Skip to content

Commit

Permalink
refactor(main): use init to check correct permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Oct 1, 2023
1 parent 0927596 commit c231ede
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ import (
"github.com/joshuar/go-hass-agent/cmd"
)

func main() {
ensureNotEUID()
cmd.Execute()
}

// Following is copied from https://git.kernel.org/pub/scm/libs/libcap/libcap.git/tree/goapps/web/web.go
//
// ensureNotEUID aborts the program if it is running setuid something,
// or being invoked by root.
func ensureNotEUID() {
func init() {
// Following is copied from https://git.kernel.org/pub/scm/libs/libcap/libcap.git/tree/goapps/web/web.go
// ensureNotEUID aborts the program if it is running setuid something,
// or being invoked by root.
euid := syscall.Geteuid()
uid := syscall.Getuid()
egid := syscall.Getegid()
Expand All @@ -30,3 +24,7 @@ func ensureNotEUID() {
log.Fatalf("go-hass-agent should not be run with additional privileges or as root.")
}
}

func main() {
cmd.Execute()
}

0 comments on commit c231ede

Please sign in to comment.