mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-26 14:21:17 +00:00
- Explicitly included golang.org/x/sys v0.38.0 in go.mod and removed indirect references - Optimized process liveness detection logic on Windows platforms using the golang.org/x/sys/windows package - Used OpenProcess and GetExitCodeProcess instead of Signal detection methods to improve accuracy - Updated command-line output and added an ASCII banner to improve user experience - Added blank lines to the github.com/spf13/cobra package to standardize import format
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
//go:build windows
|
|
|
|
package cli
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// getSysProcAttr returns platform-specific process attributes for daemonization
|
|
func getSysProcAttr() *syscall.SysProcAttr {
|
|
return &syscall.SysProcAttr{
|
|
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
|
|
}
|
|
}
|
|
|
|
// isProcessRunningOS checks if a process is running using OS-specific method
|
|
func isProcessRunningOS(process *os.Process) bool {
|
|
handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(process.Pid))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
defer windows.CloseHandle(handle)
|
|
|
|
var exitCode uint32
|
|
if err := windows.GetExitCodeProcess(handle, &exitCode); err != nil {
|
|
return false
|
|
}
|
|
|
|
return exitCode == 259
|
|
}
|
|
|
|
// killProcessOS kills a process using OS-specific method
|
|
func killProcessOS(process *os.Process) error {
|
|
// On Windows, use Kill() directly
|
|
return process.Kill()
|
|
}
|
|
|
|
// setupDaemonCmd configures the command for daemon mode
|
|
func setupDaemonCmd(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = getSysProcAttr()
|
|
}
|