From 5dc7e44aa2cb6527b0e2f4e7108c8cbd7c2a72c1 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 11 Oct 2015 17:14:18 +0200 Subject: Move main files to top level dir This is in preparation of getting rid of the shell wrapper --- sendsig.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sendsig.go (limited to 'sendsig.go') diff --git a/sendsig.go b/sendsig.go new file mode 100644 index 0000000..d0e1cbb --- /dev/null +++ b/sendsig.go @@ -0,0 +1,42 @@ +package main + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" + "syscall" +) + +// cmdline looks like this: /bin/bash \0 /path/to/gocryptfs \0 --zerokey \0 ... +const ( + WRAPPER_PREFIX = "/bin/bash\000" + WRAPPER_CONTAINS = "gocryptfs\000" +) + +// Send USR1 to the "gocryptfs" wrapper shell script. This notifies it that the +// mounting has completed sucessfully. +// +// Checks /proc/$PPID/cmdline to make sure we do not kill an unrelated process. +func sendSig() { + ppid := os.Getppid() + fn := fmt.Sprintf("/proc/%d/cmdline", ppid) + cmdline, err := ioutil.ReadFile(fn) + if err != nil { + fmt.Printf("sendSig: ReadFile: %v\n", err) + return + } + if bytes.HasPrefix(cmdline, []byte(WRAPPER_PREFIX)) && bytes.Contains(cmdline, []byte(WRAPPER_CONTAINS)) { + p, err := os.FindProcess(ppid) + if err != nil { + fmt.Printf("sendSig: FindProcess: %v\n", err) + return + } + err = p.Signal(syscall.SIGUSR1) + if err != nil { + fmt.Printf("sendSig: Signal: %v\n", err) + } + } else { + fmt.Printf("Not running under the gocryptfs wrapper - will not daemonize\n") + } +} -- cgit v1.2.3