Files
metrics/lib/procutil/signal_windows.go
e439cab7e1 spelling and grammar fixes via codespell (#8497)
### Describe Your Changes

Fix many spelling errors and some grammar, including misspellings in
filenames. 

The change also fixes a typo in metric `vm_mmaped_files` to `vm_mmapped_files`.
While this is a breaking change, this metric isn't used in alerts or dashboards. 
So it seems to have low impact on users.

The change also deprecates `cspell` as it is much heavier and less usable. 
---------

Co-authored-by: Andrii Chubatiuk <[email protected]>
Co-authored-by: Andrii Chubatiuk <[email protected]>
2025-03-17 16:32:10 +01:00

61 lines
1.2 KiB
Go

//go:build windows
package procutil
import (
"os"
"os/signal"
"sync"
"syscall"
)
// WaitForSigterm waits for either SIGTERM or SIGINT
//
// Returns the caught signal.
//
// Windows does not have SIGHUP syscall.
func WaitForSigterm() os.Signal {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
sig := <-ch
return sig
}
type sigHUPNotifier struct {
lock sync.Mutex
subscribers []chan<- os.Signal
}
var notifier sigHUPNotifier
// https://golang.org/pkg/os/signal/#hdr-Windows
// https://github.com/golang/go/issues/6948
// SelfSIGHUP sends SIGHUP signal to the subscribed listeners.
func SelfSIGHUP() {
notifier.notify(syscall.SIGHUP)
}
// NewSighupChan returns a channel, which is triggered on every SelfSIGHUP.
func NewSighupChan() <-chan os.Signal {
ch := make(chan os.Signal, 1)
notifier.subscribe(ch)
return ch
}
func (sn *sigHUPNotifier) subscribe(sub chan<- os.Signal) {
sn.lock.Lock()
defer sn.lock.Unlock()
sn.subscribers = append(sn.subscribers, sub)
}
func (sn *sigHUPNotifier) notify(sig os.Signal) {
sn.lock.Lock()
defer sn.lock.Unlock()
for _, sub := range sn.subscribers {
select {
case sub <- sig:
default:
}
}
}