From 39183bea00f0d064f0cb96427dff150799d1dbe5 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 11 Oct 2015 18:01:47 +0200 Subject: Rename sendSig to sendUsr1 This matches waitForUsr1 in daemonize() --- main.go | 2 +- sendsig.go | 42 ------------------------------------------ sendusr1.go | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 43 deletions(-) delete mode 100644 sendsig.go create mode 100644 sendusr1.go diff --git a/main.go b/main.go index 912ff72..89f3723 100644 --- a/main.go +++ b/main.go @@ -184,7 +184,7 @@ func main() { fmt.Println("Filesystem ready.") // Send notification to our parent - sendSig() + sendUsr1() // Jump into server loop srv.Serve() } diff --git a/sendsig.go b/sendsig.go deleted file mode 100644 index d0e1cbb..0000000 --- a/sendsig.go +++ /dev/null @@ -1,42 +0,0 @@ -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") - } -} diff --git a/sendusr1.go b/sendusr1.go new file mode 100644 index 0000000..b95e8db --- /dev/null +++ b/sendusr1.go @@ -0,0 +1,40 @@ +package main + +import ( + "bytes" + "fmt" + "io/ioutil" + "os" + "syscall" +) + +const ( + WRAPPER_CONTAINS = "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) + if err != nil { + fmt.Printf("sendUsr1: ReadFile: %v\n", err) + return + } + if bytes.Contains(cmdline, []byte(WRAPPER_CONTAINS)) { + 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) + } + } else { + fmt.Printf("Not running under the gocryptfs wrapper - will not daemonize\n") + } +} -- cgit v1.2.3