From 51fcf61630905f5dc9370e18522cd0a6c086856d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 9 Nov 2015 23:21:11 +0100 Subject: Use new arg "-notifypid" for more robust daemonization No more string matching on the parent command line! --- sendusr1.go | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'sendusr1.go') diff --git a/sendusr1.go b/sendusr1.go index c5dbb7c..5de8a6f 100644 --- a/sendusr1.go +++ b/sendusr1.go @@ -1,38 +1,21 @@ package main import ( - "bytes" "fmt" - "io/ioutil" "os" "syscall" ) -const ( - wrapperContains = "gocryptfs\000" -) - -// Send USR1 to the parent process. This notifies it that the -// mounting has completed sucessfully. -// -// Checks /proc/$PPID/cmdline to make sure we do not kill an unrelated process. -func sendUsr1() { - ppid := os.Getppid() - fn := fmt.Sprintf("/proc/%d/cmdline", ppid) - cmdline, err := ioutil.ReadFile(fn) +// Send signal USR1 to "pid" (usually our parent process). This notifies it +// that the mounting has completed sucessfully. +func sendUsr1(pid int) { + p, err := os.FindProcess(pid) if err != nil { - fmt.Printf("sendUsr1: ReadFile: %v\n", err) + fmt.Printf("sendUsr1: FindProcess: %v\n", err) return } - if bytes.Contains(cmdline, []byte(wrapperContains)) { - p, err := os.FindProcess(ppid) - if err != nil { - fmt.Printf("sendUsr1: FindProcess: %v\n", err) - return - } - err = p.Signal(syscall.SIGUSR1) - if err != nil { - fmt.Printf("sendUsr1: Signal: %v\n", err) - } + err = p.Signal(syscall.SIGUSR1) + if err != nil { + fmt.Printf("sendUsr1: Signal: %v\n", err) } } -- cgit v1.2.3