Skip to content

Commit

Permalink
fix: ensure we have sudo avail before running
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Jul 21, 2022
1 parent a3ec97f commit 4da67f8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ func NewDaemon(lh *LoggedHandler, listen string, httpPort int, httpsPort int) *D
return &Daemon{loggedHandler: lh, listenHost: listen, httpPort: httpPort, httpsPort: httpsPort}
}

func rerunWithSudo() {
func rerunWithSudo(addr string) {
// ensure sudo exists on this OS
_, err := os.Stat("/usr/bin/sudo")
if err != nil {
fmt.Println("[*] error: unable to bind on ", addr)
log.Fatal("[*] fatal: sudo not found")
return
}

exe, e := os.Executable()
if e != nil {
log.Fatal(e)
Expand Down Expand Up @@ -89,7 +97,7 @@ func testListener(addr string) {
fmt.Println("[*] warning: looks like we are running as a headless daemon; won't try rerunning with sudo")
fmt.Println("[*] instead, run the service as root. see docs for help.")
} else {
rerunWithSudo()
rerunWithSudo(addr)
}
}
log.Fatal(err)
Expand Down

0 comments on commit 4da67f8

Please sign in to comment.