aboutsummaryrefslogtreecommitdiff
path: root/daemonize.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-06-07 23:06:03 +0200
committerJakob Unterwurzacher2018-06-07 23:09:27 +0200
commitfb772da6975eec186161fb00ededc2aef43f9eb9 (patch)
treedbc30f31d27c5bc933a0a2ea2ed22d67878a075a /daemonize.go
parent10212d791a3196c2c8705a7a3cccdeb14a8efdbe (diff)
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".
Diffstat (limited to 'daemonize.go')
-rw-r--r--daemonize.go9
1 files changed, 8 insertions, 1 deletions
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