check for system signals
This commit is contained in:
parent
e3cc322594
commit
c13f6d5ca8
21
main.go
21
main.go
@ -6,14 +6,21 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
envFile = flag.String("env", "$HOME/.config/i3-wrapper/environment", "environment file with variable definitions")
|
envFile = flag.String("env", "$HOME/.config/i3-wrapper/environment", "environment file with variable definitions")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
i3 *os.Process
|
||||||
|
running bool
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logFile, err := os.Create(filepath.Join(os.Getenv("HOME"), ".i3.log"))
|
logFile, err := os.Create(filepath.Join(os.Getenv("HOME"), ".i3.log"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -24,7 +31,18 @@ func main() {
|
|||||||
os.Stdout = logFile
|
os.Stdout = logFile
|
||||||
os.Stderr = logFile
|
os.Stderr = logFile
|
||||||
|
|
||||||
for {
|
fmt.Println("environment file:", os.ExpandEnv(*envFile))
|
||||||
|
|
||||||
|
sigs := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
sig := <-sigs
|
||||||
|
running = false
|
||||||
|
i3.Signal(sig)
|
||||||
|
}()
|
||||||
|
|
||||||
|
running = true
|
||||||
|
for running {
|
||||||
cmd := exec.Command("i3")
|
cmd := exec.Command("i3")
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@ -41,6 +59,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
}
|
}
|
||||||
|
i3 = cmd.Process
|
||||||
|
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user