From fb772da6975eec186161fb00ededc2aef43f9eb9 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 7 Jun 2018 23:06:03 +0200 Subject: main: forkChild: try to read /proc/self/exe On Linux, where /proc exists, this makes sure that we are executing ourselves again, and not some other copy of the gocryptfs executable. This usually does not matter, but mount(1) unsets $PATH and sets argv[0] to just "gocryptfs". --- daemonize.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/daemonize.go b/daemonize.go index abb6d08..5215b2c 100644 --- a/daemonize.go +++ b/daemonize.go @@ -28,6 +28,13 @@ func exitOnUsr1() { // This is a workaround for the missing true fork function in Go. func forkChild() int { name := os.Args[0] + // Use the full path to our executable if we can get if from /proc. + buf := make([]byte, syscall.PathMax) + n, err := syscall.Readlink("/proc/self/exe", buf) + if err == nil { + name = string(buf[:n]) + tlog.Debug.Printf("forkChild: readlink worked: %q", name) + } newArgs := []string{"-fg", fmt.Sprintf("-notifypid=%d", os.Getpid())} newArgs = append(newArgs, os.Args[1:]...) c := exec.Command(name, newArgs...) @@ -35,7 +42,7 @@ func forkChild() int { c.Stderr = os.Stderr c.Stdin = os.Stdin exitOnUsr1() - err := c.Start() + err = c.Start() if err != nil { tlog.Fatal.Printf("forkChild: starting %s failed: %v", name, err) return exitcodes.ForkChild -- cgit v1.2.3