mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2025-08-19 05:05:54 +02:00
Align with go library layout
This commit is contained in:
32
daemon_linux.go
Normal file
32
daemon_linux.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
/* Daemonizes the process on linux
|
||||
*
|
||||
* This is done by spawning and releasing a copy with the --foreground flag
|
||||
*/
|
||||
func Daemonize(attr *os.ProcAttr) error {
|
||||
// I would like to use os.Executable,
|
||||
// however this means dropping support for Go <1.8
|
||||
path, err := exec.LookPath(os.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
argv := []string{os.Args[0], "--foreground"}
|
||||
argv = append(argv, os.Args[1:]...)
|
||||
process, err := os.StartProcess(
|
||||
path,
|
||||
argv,
|
||||
attr,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
process.Release()
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user