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.
This commit is contained in:
34
src/daemon_linux.go
Normal file
34
src/daemon_linux.go
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user