diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-15 13:41:02 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-15 13:41:02 +0200 |
commit | b21c82e32d955e15d846aed87535b6d728ab1d0b (patch) | |
tree | 1528bd49789a6cd48a94407477011e51732b2f5c /src/daemon_linux.go | |
parent | 8993b3927cf66517e2884b181d6b71d4c6599b7a (diff) |
Conforming to the cross-platform UX
The implementation now terminates when the unix socket is deleted.
Currently we are unable to use fsnotify (on linux),
since it does not notify on the deletion of open files.
The implementation can now daemonize (on linux)
or be kept in the foreground by providing the necessary flag.
Diffstat (limited to 'src/daemon_linux.go')
-rw-r--r-- | src/daemon_linux.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/daemon_linux.go b/src/daemon_linux.go new file mode 100644 index 0000000..809c176 --- /dev/null +++ b/src/daemon_linux.go @@ -0,0 +1,34 @@ +package main + +import ( + "os" +) + +/* Daemonizes the process on linux + * + * This is done by spawning and releasing a copy with the --foreground flag + */ + +func Daemonize() error { + argv := []string{os.Args[0], "--foreground"} + argv = append(argv, os.Args[1:]...) + attr := &os.ProcAttr{ + Dir: ".", + Env: os.Environ(), + Files: []*os.File{ + os.Stdin, + nil, + nil, + }, + } + process, err := os.StartProcess( + argv[0], + argv, + attr, + ) + if err != nil { + return err + } + process.Release() + return nil +} |