Skip to content

Commit

Permalink
osutil: fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Nov 11, 2024
1 parent ec84c9f commit a84bb8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions osutil/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
22 changes: 12 additions & 10 deletions osutil/signal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ 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
}
}

// 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)
}

0 comments on commit a84bb8f

Please sign in to comment.