Added code from windows branch

This commit is contained in:
Mathias Hall-Andersen
2017-08-27 15:41:00 +02:00
parent eafa3df606
commit 6f5ef153c3
6 changed files with 896 additions and 337 deletions
+34
View File
@@ -0,0 +1,34 @@
package main
import (
"os"
)
/* Daemonizes the process on windows
*
* 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
}