mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
f3a03c4164
* fixes windows compilation, adds signal impl for windows, adds free space usage for windows, https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70 https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1036 NOTE victoria metrics database still CANNOT work under windows system, only vmagent is supported. To completly port victoria metrics, you have to fix issues with separators, parsing and posix file removall * rollback separator * Adds windows setInformation api, it must behave like unix, need to test it. changes procutil * check for invlaid param * Fixes posix delete semantic * refactored a bit * fixes openbsd build * removed windows api call * Fixes code after windows add * Update lib/procutil/signal_windows.go Co-authored-by: Aliaksandr Valialkin <valyala@gmail.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
// +build windows
|
|
|
|
package procutil
|
|
|
|
import (
|
|
"os"
|
|
"os/signal"
|
|
"sync"
|
|
"syscall"
|
|
)
|
|
|
|
// WaitForSigterm waits for either SIGTERM or SIGINT
|
|
//
|
|
// Returns the caught signal.
|
|
//
|
|
// Windows dont 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:
|
|
}
|
|
}
|
|
}
|