2015-10-06 00:29:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2015-10-07 22:58:22 +02:00
|
|
|
"os"
|
|
|
|
"syscall"
|
2015-10-06 00:29:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
WRAPPER_CONTAINS = "gocryptfs\000"
|
|
|
|
)
|
|
|
|
|
2015-10-11 18:01:47 +02:00
|
|
|
// Send USR1 to the parent process. This notifies it that the
|
2015-10-06 00:29:08 +02:00
|
|
|
// mounting has completed sucessfully.
|
|
|
|
//
|
|
|
|
// Checks /proc/$PPID/cmdline to make sure we do not kill an unrelated process.
|
2015-10-11 18:01:47 +02:00
|
|
|
func sendUsr1() {
|
2015-10-06 00:29:08 +02:00
|
|
|
ppid := os.Getppid()
|
|
|
|
fn := fmt.Sprintf("/proc/%d/cmdline", ppid)
|
|
|
|
cmdline, err := ioutil.ReadFile(fn)
|
|
|
|
if err != nil {
|
2015-10-11 18:01:47 +02:00
|
|
|
fmt.Printf("sendUsr1: ReadFile: %v\n", err)
|
2015-10-06 00:29:08 +02:00
|
|
|
return
|
|
|
|
}
|
2015-10-11 18:01:47 +02:00
|
|
|
if bytes.Contains(cmdline, []byte(WRAPPER_CONTAINS)) {
|
2015-10-06 00:29:08 +02:00
|
|
|
p, err := os.FindProcess(ppid)
|
|
|
|
if err != nil {
|
2015-10-11 18:01:47 +02:00
|
|
|
fmt.Printf("sendUsr1: FindProcess: %v\n", err)
|
2015-10-06 00:29:08 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
err = p.Signal(syscall.SIGUSR1)
|
|
|
|
if err != nil {
|
2015-10-11 18:01:47 +02:00
|
|
|
fmt.Printf("sendUsr1: Signal: %v\n", err)
|
2015-10-06 00:29:08 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Not running under the gocryptfs wrapper - will not daemonize\n")
|
|
|
|
}
|
|
|
|
}
|