Rename sendSig to sendUsr1
This matches waitForUsr1 in daemonize()
This commit is contained in:
parent
5dc7e44aa2
commit
39183bea00
2
main.go
2
main.go
|
@ -184,7 +184,7 @@ func main() {
|
||||||
|
|
||||||
fmt.Println("Filesystem ready.")
|
fmt.Println("Filesystem ready.")
|
||||||
// Send notification to our parent
|
// Send notification to our parent
|
||||||
sendSig()
|
sendUsr1()
|
||||||
// Jump into server loop
|
// Jump into server loop
|
||||||
srv.Serve()
|
srv.Serve()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,33 +8,31 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// cmdline looks like this: /bin/bash \0 /path/to/gocryptfs \0 --zerokey \0 ...
|
|
||||||
const (
|
const (
|
||||||
WRAPPER_PREFIX = "/bin/bash\000"
|
|
||||||
WRAPPER_CONTAINS = "gocryptfs\000"
|
WRAPPER_CONTAINS = "gocryptfs\000"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Send USR1 to the "gocryptfs" wrapper shell script. This notifies it that the
|
// Send USR1 to the parent process. This notifies it that the
|
||||||
// mounting has completed sucessfully.
|
// mounting has completed sucessfully.
|
||||||
//
|
//
|
||||||
// Checks /proc/$PPID/cmdline to make sure we do not kill an unrelated process.
|
// Checks /proc/$PPID/cmdline to make sure we do not kill an unrelated process.
|
||||||
func sendSig() {
|
func sendUsr1() {
|
||||||
ppid := os.Getppid()
|
ppid := os.Getppid()
|
||||||
fn := fmt.Sprintf("/proc/%d/cmdline", ppid)
|
fn := fmt.Sprintf("/proc/%d/cmdline", ppid)
|
||||||
cmdline, err := ioutil.ReadFile(fn)
|
cmdline, err := ioutil.ReadFile(fn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("sendSig: ReadFile: %v\n", err)
|
fmt.Printf("sendUsr1: ReadFile: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix(cmdline, []byte(WRAPPER_PREFIX)) && bytes.Contains(cmdline, []byte(WRAPPER_CONTAINS)) {
|
if bytes.Contains(cmdline, []byte(WRAPPER_CONTAINS)) {
|
||||||
p, err := os.FindProcess(ppid)
|
p, err := os.FindProcess(ppid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("sendSig: FindProcess: %v\n", err)
|
fmt.Printf("sendUsr1: FindProcess: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = p.Signal(syscall.SIGUSR1)
|
err = p.Signal(syscall.SIGUSR1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("sendSig: Signal: %v\n", err)
|
fmt.Printf("sendUsr1: Signal: %v\n", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Not running under the gocryptfs wrapper - will not daemonize\n")
|
fmt.Printf("Not running under the gocryptfs wrapper - will not daemonize\n")
|
Loading…
Reference in New Issue