summaryrefslogtreecommitdiff
path: root/sendusr1.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-10-11 18:01:47 +0200
committerJakob Unterwurzacher2015-10-11 18:01:47 +0200
commit39183bea00f0d064f0cb96427dff150799d1dbe5 (patch)
tree364143fefb51130b0d21a94445bd9042f392e9d5 /sendusr1.go
parent5dc7e44aa2cb6527b0e2f4e7108c8cbd7c2a72c1 (diff)
Rename sendSig to sendUsr1
This matches waitForUsr1 in daemonize()
Diffstat (limited to 'sendusr1.go')
-rw-r--r--sendusr1.go40
1 files changed, 40 insertions, 0 deletions
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")
+ }
+}