initial import

This commit is contained in:
Kyle Isom 2023-10-02 23:08:55 -07:00
commit b6ed20ff87
3 changed files with 41 additions and 0 deletions

7
cmd/sysreboot/main.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "git.wntrmute.dev/kyle/gokpkg"
func main() {
gokpkg.Reboot()
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.wntrmute.dev/kyle/gokpkg
go 1.20

31
sys.go Normal file
View File

@ -0,0 +1,31 @@
package gokpkg
import (
"log"
"os"
"os/exec"
"syscall"
)
func MustDropPrivileges() {
if os.Getenv("NTP_PRIVILEGES_DROPPED") == "1" {
return
}
cmd := exec.Command(os.Args[0])
cmd.Env = append(os.Environ(), "NTP_PRIVILEGES_DROPPED=1")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: 65534,
Gid: 65534,
},
}
log.Fatal(cmd.Run())
}
func Reboot() {
cmd := exec.Command("reboot")
log.Fatal(cmd.Run())
}