diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2018-02-04 16:08:26 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2018-02-04 16:08:26 +0100 |
commit | a0f54cbe5ac2cd8b8296c2c57c30029dd349cff0 (patch) | |
tree | 64574090d79ff3899c5c18e5268e450028e4656b /daemon_windows.go | |
parent | 5871ec04deb8f4715cab37146940baa35c08cbee (diff) |
Align with go library layout
Diffstat (limited to 'daemon_windows.go')
-rw-r--r-- | daemon_windows.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/daemon_windows.go b/daemon_windows.go new file mode 100644 index 0000000..d5ec1e8 --- /dev/null +++ b/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
+}
|