summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-09-20 19:49:44 +0200
committerJakob Unterwurzacher2016-09-25 16:43:17 +0200
commit9ad49088fa7b919cee850818b61ad1d6bc5d3df3 (patch)
tree2ed9dee89c495f3c29f4c4532a782a5357ff727e
parentd9db75ebd263510dfcf93853f0e111012b82f828 (diff)
main: add explicit exit after forkChild
Trying to make it more obvious what is happening.
-rw-r--r--daemonize.go8
-rw-r--r--main.go6
2 files changed, 8 insertions, 6 deletions
diff --git a/daemonize.go b/daemonize.go
index 56423f5..5bfed7d 100644
--- a/daemonize.go
+++ b/daemonize.go
@@ -21,7 +21,7 @@ func exitOnUsr1() {
// 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() {
+func forkChild() int {
go exitOnUsr1()
name := os.Args[0]
newArgs := []string{"-f", fmt.Sprintf("-notifypid=%d", os.Getpid())}
@@ -33,7 +33,7 @@ func forkChild() {
err := c.Start()
if err != nil {
tlog.Fatal.Printf("forkChild: starting %s failed: %v\n", name, err)
- os.Exit(1)
+ return 1
}
err = c.Wait()
if err != nil {
@@ -43,8 +43,8 @@ func forkChild() {
}
}
tlog.Fatal.Printf("forkChild: wait returned an unknown error: %v\n", err)
- os.Exit(1)
+ return 1
}
// The child exited with 0 - let's do the same.
- os.Exit(0)
+ return 0
}
diff --git a/main.go b/main.go
index 9034e3f..7a29e68 100644
--- a/main.go
+++ b/main.go
@@ -159,9 +159,11 @@ func main() {
args := parseCliArgs()
- // Fork a child into the background if "-f" is not set AND we are mounting a filesystem
+ // Fork a child into the background if "-f" is not set AND we are mounting
+ // a filesystem. The child will do all the work.
if !args.foreground && flagSet.NArg() == 2 {
- forkChild() // does not return
+ ret := forkChild()
+ os.Exit(ret)
}
if args.debug {
tlog.Debug.Enabled = true