Skip to content

Commit 72d7e8a

Browse files
committed
refactor(app): remove syscall import and improve error messages
1 parent b389d0e commit 72d7e8a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

internal/app/app.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os/exec"
88
"runtime"
99
"runtime/debug"
10-
"syscall"
1110
)
1211

1312
var (
@@ -46,25 +45,26 @@ func Init() {
4645
os.Exit(0)
4746
}
4847

49-
if os.Getppid() == 1 || syscall.Getppid() == 1 {
48+
ppid := os.Getppid()
49+
if ppid == 1 {
5050
daemon = false
5151
} else {
52-
parent, err := os.FindProcess(os.Getppid())
52+
parent, err := os.FindProcess(ppid)
5353
if err != nil || parent.Pid < 1 {
5454
daemon = false
5555
}
5656
}
5757

5858
if daemon {
5959
if runtime.GOOS == "windows" {
60-
fmt.Println("Daemon not supported on Windows")
60+
fmt.Println("Daemon mode is not supported on Windows")
6161
os.Exit(1)
6262
}
6363

6464
// Re-run the program in background and exit
6565
cmd := exec.Command(os.Args[0], os.Args[1:]...)
6666
if err := cmd.Start(); err != nil {
67-
fmt.Println(err)
67+
fmt.Println("Failed to start daemon:", err)
6868
os.Exit(1)
6969
}
7070
fmt.Println("Running in daemon mode with PID:", cmd.Process.Pid)

0 commit comments

Comments
 (0)