wireguard-go/src/daemon_linux.go
Mathias Hall-Andersen b21c82e32d 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.
2017-07-15 13:41:02 +02:00

35 lines
503 B
Go

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
}