Skip to content

Commit 4da67f8

Browse files
committed
fix: ensure we have sudo avail before running
1 parent a3ec97f commit 4da67f8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

daemon.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ func NewDaemon(lh *LoggedHandler, listen string, httpPort int, httpsPort int) *D
4747
return &Daemon{loggedHandler: lh, listenHost: listen, httpPort: httpPort, httpsPort: httpsPort}
4848
}
4949

50-
func rerunWithSudo() {
50+
func rerunWithSudo(addr string) {
51+
// ensure sudo exists on this OS
52+
_, err := os.Stat("/usr/bin/sudo")
53+
if err != nil {
54+
fmt.Println("[*] error: unable to bind on ", addr)
55+
log.Fatal("[*] fatal: sudo not found")
56+
return
57+
}
58+
5159
exe, e := os.Executable()
5260
if e != nil {
5361
log.Fatal(e)
@@ -89,7 +97,7 @@ func testListener(addr string) {
8997
fmt.Println("[*] warning: looks like we are running as a headless daemon; won't try rerunning with sudo")
9098
fmt.Println("[*] instead, run the service as root. see docs for help.")
9199
} else {
92-
rerunWithSudo()
100+
rerunWithSudo(addr)
93101
}
94102
}
95103
log.Fatal(err)

0 commit comments

Comments
 (0)