diff options
author | Jakob Unterwurzacher | 2015-11-14 21:25:10 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2015-11-14 21:25:10 +0100 |
commit | 58592330dc33e194e55fa942d3f375124839f058 (patch) | |
tree | 7b523afe12b7382556ca591768e05ed397b0512f /daemonize.go | |
parent | 6736212b29bd54a0ed9778f1bbea49db03f43c06 (diff) |
Refactor cli argument handling
Also, add the "-config" option for storing gocryptfs.conf
outside of CIPHERDIR.
Diffstat (limited to 'daemonize.go')
-rw-r--r-- | daemonize.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/daemonize.go b/daemonize.go index 4f09164..a65bd11 100644 --- a/daemonize.go +++ b/daemonize.go @@ -9,17 +9,18 @@ import ( ) // The child sends us USR1 if the mount was successful -func waitForUsr1() { +func exitOnUsr1() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGUSR1) <-c os.Exit(0) } -// daemonize - execute ourselves once again, this time with the "-f" flag, and -// wait for SIGUSR1. -func daemonize() { - go waitForUsr1() +// forkChild - execute ourselves once again, this time with the "-f" flag, and +// wait for SIGUSR1 or child exit. +// This is a workaround for the missing true fork function in Go. +func forkChild() { + go exitOnUsr1() name := os.Args[0] notifyArg := fmt.Sprintf("-notifypid=%d", os.Getpid()) newArgs := []string{"-f", notifyArg} @@ -30,7 +31,7 @@ func daemonize() { c.Stdin = os.Stdin err := c.Start() if err != nil { - fmt.Printf("daemonize: starting %s failed: %v\n", name, err) + fmt.Printf("forkChild: starting %s failed: %v\n", name, err) os.Exit(1) } err = c.Wait() @@ -40,7 +41,7 @@ func daemonize() { os.Exit(waitstat.ExitStatus()) } } - fmt.Printf("daemonize: wait returned an unknown error: %v\n", err) + fmt.Printf("forkChild: wait returned an unknown error: %v\n", err) os.Exit(1) } // The child exited with 0 - let's do the same. |