From a84bb8fd9a6d1cb8a232b7371efceba1369798d4 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Mon, 11 Nov 2024 20:31:57 +0300 Subject: [PATCH] osutil: fix windows --- osutil/signal.go | 4 ++++ osutil/signal_windows.go | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/osutil/signal.go b/osutil/signal.go index d6ccd0f..3ce3781 100644 --- a/osutil/signal.go +++ b/osutil/signal.go @@ -54,6 +54,8 @@ func (n DefaultSignalNotifier) Stop(c chan<- os.Signal) { } // IsReconfigureSignal returns true if sig is a reconfigure signal. +// +// NOTE: It always returns false on Windows. func IsReconfigureSignal(sig os.Signal) (ok bool) { return isReconfigureSignal(sig) } @@ -64,6 +66,8 @@ func IsShutdownSignal(sig os.Signal) (ok bool) { } // NotifyReconfigureSignal notifies c on receiving reconfigure signals using n. +// +// NOTE: It does nothing on Windows. func NotifyReconfigureSignal(n SignalNotifier, c chan<- os.Signal) { notifyReconfigureSignal(n, c) } diff --git a/osutil/signal_windows.go b/osutil/signal_windows.go index 0ef576d..e9885f2 100644 --- a/osutil/signal_windows.go +++ b/osutil/signal_windows.go @@ -4,19 +4,22 @@ package osutil import ( "os" - - "golang.org/x/sys/windows" + "syscall" ) // isReconfigureSignal returns true if sig is a Windows reconfigure signal. -func isReconfigureSignal(sig os.Signal) (ok bool) { - return sig == windows.SIGHUP +// Since Windows doesn't seem to have a Unix-compatible mechanism of signaling a +// change in the configuration, it always returns false. +func isReconfigureSignal(_ os.Signal) (ok bool) { + return false } // isShutdownSignal returns true if sig is a Windows shutdown signal. func isShutdownSignal(sig os.Signal) (ok bool) { + // NOTE: Use syscall.SIGTERM as opposed to windows.SIGTERM, because that's + // the type that the Go runtime is sending. switch sig { - case os.Interrupt, windows.SIGTERM: + case os.Interrupt, syscall.SIGTERM: return true default: return false @@ -24,15 +27,14 @@ func isShutdownSignal(sig os.Signal) (ok bool) { } // notifyReconfigureSignal notifies c on receiving Windows reconfigure signals -// using n. -func notifyReconfigureSignal(n SignalNotifier, c chan<- os.Signal) { - n.Notify(c, windows.SIGHUP) -} +// using n. Since Windows doesn't seem to have a Unix-compatible mechanism of +// signaling a change in the configuration, it does nothing. +func notifyReconfigureSignal(_ SignalNotifier, _ chan<- os.Signal) {} // notifyShutdownSignal notifies c on receiving Windows shutdown signals using // n. func notifyShutdownSignal(n SignalNotifier, c chan<- os.Signal) { - // [windows.SIGTERM] is processed automatically. See go doc os/signal, + // [syscall.SIGTERM] is processed automatically. See go doc os/signal, // section Windows. n.Notify(c, os.Interrupt) }