|
@@ -8,11 +8,16 @@ import (
|
|
|
|
|
|
// PIDFILE - path/name of pid file
|
|
// PIDFILE - path/name of pid file
|
|
const PIDFILE = "/var/run/netclient.pid"
|
|
const PIDFILE = "/var/run/netclient.pid"
|
|
|
|
+const WIN_PIDFILE = "C:\\Windows\\Temp\\netclient.pid"
|
|
|
|
|
|
// SavePID - saves the pid of running program to disk
|
|
// SavePID - saves the pid of running program to disk
|
|
func SavePID() error {
|
|
func SavePID() error {
|
|
|
|
+ pidfile := PIDFILE
|
|
|
|
+ if IsWindows() {
|
|
|
|
+ pidfile = WIN_PIDFILE
|
|
|
|
+ }
|
|
pid := os.Getpid()
|
|
pid := os.Getpid()
|
|
- if err := os.WriteFile(PIDFILE, []byte(fmt.Sprintf("%d", pid)), 0644); err != nil {
|
|
|
|
|
|
+ if err := os.WriteFile(pidfile, []byte(fmt.Sprintf("%d", pid)), 0644); err != nil {
|
|
return fmt.Errorf("could not write to pid file %w", err)
|
|
return fmt.Errorf("could not write to pid file %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
@@ -20,7 +25,11 @@ func SavePID() error {
|
|
|
|
|
|
// ReadPID - reads a previously saved pid from disk
|
|
// ReadPID - reads a previously saved pid from disk
|
|
func ReadPID() (int, error) {
|
|
func ReadPID() (int, error) {
|
|
- bytes, err := os.ReadFile(PIDFILE)
|
|
|
|
|
|
+ pidfile := PIDFILE
|
|
|
|
+ if IsWindows() {
|
|
|
|
+ pidfile = WIN_PIDFILE
|
|
|
|
+ }
|
|
|
|
+ bytes, err := os.ReadFile(pidfile)
|
|
if err != nil {
|
|
if err != nil {
|
|
return 0, fmt.Errorf("could not read pid file %w", err)
|
|
return 0, fmt.Errorf("could not read pid file %w", err)
|
|
}
|
|
}
|