main: add explicit exit after forkChild

Trying to make it more obvious what is happening.
This commit is contained in:
Jakob Unterwurzacher 2016-09-20 19:49:44 +02:00
parent d9db75ebd2
commit 9ad49088fa
2 changed files with 8 additions and 6 deletions

View File

@ -21,7 +21,7 @@ func exitOnUsr1() {
// forkChild - execute ourselves once again, this time with the "-f" flag, and // forkChild - execute ourselves once again, this time with the "-f" flag, and
// wait for SIGUSR1 or child exit. // wait for SIGUSR1 or child exit.
// This is a workaround for the missing true fork function in Go. // This is a workaround for the missing true fork function in Go.
func forkChild() { func forkChild() int {
go exitOnUsr1() go exitOnUsr1()
name := os.Args[0] name := os.Args[0]
newArgs := []string{"-f", fmt.Sprintf("-notifypid=%d", os.Getpid())} newArgs := []string{"-f", fmt.Sprintf("-notifypid=%d", os.Getpid())}
@ -33,7 +33,7 @@ func forkChild() {
err := c.Start() err := c.Start()
if err != nil { if err != nil {
tlog.Fatal.Printf("forkChild: starting %s failed: %v\n", name, err) tlog.Fatal.Printf("forkChild: starting %s failed: %v\n", name, err)
os.Exit(1) return 1
} }
err = c.Wait() err = c.Wait()
if err != nil { if err != nil {
@ -43,8 +43,8 @@ func forkChild() {
} }
} }
tlog.Fatal.Printf("forkChild: wait returned an unknown error: %v\n", err) 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. // The child exited with 0 - let's do the same.
os.Exit(0) return 0
} }

View File

@ -159,9 +159,11 @@ func main() {
args := parseCliArgs() 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 { if !args.foreground && flagSet.NArg() == 2 {
forkChild() // does not return ret := forkChild()
os.Exit(ret)
} }
if args.debug { if args.debug {
tlog.Debug.Enabled = true tlog.Debug.Enabled = true