summaryrefslogtreecommitdiffhomepage
path: root/src/daemon_windows.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-27 15:41:00 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-27 15:41:00 +0200
commit6f5ef153c3b578da99501cfcbe4f2e4a84d44708 (patch)
tree5fcdda37f8cde8be8b2f2afb3ebd6b337b0652ed /src/daemon_windows.go
parenteafa3df60689d3ad2b4316c42a8360ed47072a00 (diff)
Added code from windows branch
Diffstat (limited to 'src/daemon_windows.go')
-rw-r--r--src/daemon_windows.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/daemon_windows.go b/src/daemon_windows.go
new file mode 100644
index 0000000..d5ec1e8
--- /dev/null
+++ b/src/daemon_windows.go
@@ -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
+}