File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 77 "os/exec"
88 "runtime"
99 "runtime/debug"
10+ "syscall"
1011)
1112
1213var (
@@ -45,20 +46,23 @@ func Init() {
4546 os .Exit (0 )
4647 }
4748
49+ if os .Getppid () == 1 || syscall .Getppid () == 1 {
50+ daemon = false
51+ } else {
52+ parent , err := os .FindProcess (os .Getppid ())
53+ if err != nil || parent .Pid < 1 {
54+ daemon = false
55+ }
56+ }
57+
4858 if daemon {
4959 if runtime .GOOS == "windows" {
5060 fmt .Println ("Daemon not supported on Windows" )
5161 os .Exit (1 )
5262 }
5363
54- args := os .Args [1 :]
55- for i , arg := range args {
56- if arg == "-daemon" || arg == "-d" {
57- args [i ] = ""
58- }
59- }
6064 // Re-run the program in background and exit
61- cmd := exec .Command (os .Args [0 ], args ... )
65+ cmd := exec .Command (os .Args [0 ], os . Args [ 1 :] ... )
6266 if err := cmd .Start (); err != nil {
6367 fmt .Println (err )
6468 os .Exit (1 )
You can’t perform that action at this time.
0 commit comments