summaryrefslogtreecommitdiff
path: root/sendusr1.go
blob: c5dbb7ca5b64554722f8c8d2bbdbfbde0bce92d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"syscall"
)

const (
	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
	}
	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)
		}
	}
}