libgocryptfs/sendusr1.go

39 lines
775 B
Go
Raw Normal View History

package main
import (
"bytes"
"fmt"
"io/ioutil"
2015-10-07 22:58:22 +02:00
"os"
"syscall"
)
const (
2015-11-02 22:50:53 +01:00
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)
if err != nil {
fmt.Printf("sendUsr1: ReadFile: %v\n", err)
return
}
2015-11-02 22:50:53 +01:00
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)
}
}
}