mirror of
https://github.com/kubereboot/kured.git
synced 2026-05-17 13:56:43 +00:00
Without this, impossible to bubble up errors to main Signed-off-by: Jean-Philippe Evrard <open-source@a.spamming.party>
38 lines
919 B
Go
38 lines
919 B
Go
package reboot
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// SignalRebooter holds context-information for a signal reboot.
|
|
type SignalRebooter struct {
|
|
Signal int
|
|
}
|
|
|
|
// Reboot triggers the reboot signal
|
|
func (c SignalRebooter) Reboot() error {
|
|
process, err := os.FindProcess(1)
|
|
if err != nil {
|
|
return fmt.Errorf("not running on Unix: %v", err)
|
|
}
|
|
|
|
err = process.Signal(syscall.Signal(c.Signal))
|
|
// Either PID does not exist, or the signal does not work. Hoping for
|
|
// a decent enough error.
|
|
if err != nil {
|
|
return fmt.Errorf("signal of SIGRTMIN+5 failed: %v", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NewSignalRebooter is the constructor which sets the signal number.
|
|
// The constructor does not yet validate any input. It should be done in a later commit.
|
|
func NewSignalRebooter(sig int) (*SignalRebooter, error) {
|
|
if sig < 1 {
|
|
return nil, fmt.Errorf("invalid signal: %v", sig)
|
|
}
|
|
return &SignalRebooter{Signal: sig}, nil
|
|
}
|