@@ -9,12 +9,10 @@ import (
99 "log"
1010 "net"
1111 "os"
12- "os/exec"
1312 "strconv"
1413 "strings"
1514 "syscall"
1615
17- "github.com/tech-thinker/telepath/config"
1816 "github.com/tech-thinker/telepath/constants"
1917 "github.com/tech-thinker/telepath/handler"
2018 "github.com/tech-thinker/telepath/models"
@@ -49,6 +47,11 @@ func (ps *daemonMgr) IsDaemonRunning(ctx context.Context) bool {
4947 return false
5048 }
5149
50+ // For windows, no need to check process signal
51+ if utils .IsWindows () {
52+ return true
53+ }
54+
5255 // Check if the process is alive
5356 err = process .Signal (syscall .Signal (0 ))
5457 return err == nil
@@ -61,12 +64,13 @@ func (ps *daemonMgr) RunAsDaemon(ctx context.Context) error {
6164 return fmt .Errorf ("daemon is already running" )
6265 }
6366
64- // Fork the process
65- cmd := exec .Command (os .Args [0 ], "daemon" , "start" , "--daemon-child" )
66- cmd .Stdout = os .Stdout
67- cmd .Stderr = os .Stderr
68- cmd .Start ()
69- fmt .Printf ("Daemon started with PID: %d\n " , cmd .Process .Pid )
67+ pid , err := utils .FrokProcess (os .Args [0 ], "daemon" , "start" , "--daemon-child" )
68+ if err != nil {
69+ // fmt.Println("Failed to start daemon process: ", err)
70+ return fmt .Errorf ("failed to start daemon process: %v" , err .Error ())
71+ }
72+
73+ fmt .Printf ("Daemon started with PID: %d\n " , pid )
7074 return nil
7175}
7276
@@ -83,7 +87,7 @@ func (ps *daemonMgr) RunDaemonChild(ctx context.Context) (err error) {
8387 // Set up the UNIX socket
8488 var listener net.Listener
8589
86- if ! config .IsWindows () {
90+ if ! utils .IsWindows () {
8791 if _ , err := os .Stat (ps .socketPath ); err == nil {
8892 os .Remove (ps .socketPath )
8993 }
@@ -189,7 +193,7 @@ func (ps *daemonMgr) SendCommandToDaemon(ctx context.Context, packet models.Pack
189193 var conn net.Conn
190194 var err error
191195
192- if ! config .IsWindows () {
196+ if ! utils .IsWindows () {
193197 conn , err = net .Dial ("unix" , ps .socketPath )
194198 if err != nil {
195199 return fmt .Errorf ("failed to connect to daemon: %v" , err )
0 commit comments