From 1b962e66d08c721aca5aee8cec8d0cca6167e4cb Mon Sep 17 00:00:00 2001 From: Chetan Sarva Date: Tue, 26 Oct 2021 16:53:35 -0400 Subject: [PATCH] feat: extra headless check --- daemon.go | 4 ++++ go.mod | 1 + go.sum | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/daemon.go b/daemon.go index 1593b1c..d06db69 100644 --- a/daemon.go +++ b/daemon.go @@ -10,6 +10,7 @@ import ( "sync" "syscall" + "github.com/mattn/go-isatty" "github.com/mitchellh/go-homedir" ) @@ -79,6 +80,9 @@ func testListener(addr string) { if svc == "homebrew.mxcl.vproxy" || strings.Contains(svc, "vproxy") { fmt.Println("[*] warning: looks like we are running via launchd; won't try rerunning with sudo") fmt.Println("[*] instead, run the service as root. see docs for help.") + } else if !isatty.IsTerminal(os.Stdin.Fd()) { + 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() } diff --git a/go.mod b/go.mod index ecc5048..63e7d5e 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/cbednarski/hostess v0.5.2 github.com/cenkalti/backoff/v4 v4.1.0 github.com/jittering/truststore v0.0.0-20211026192954-23f65d32fa19 + github.com/mattn/go-isatty v0.0.14 // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/pelletier/go-toml v1.8.1 github.com/urfave/cli/v2 v2.3.0 diff --git a/go.sum b/go.sum index 1f03c11..9929b21 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= @@ -50,6 +52,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=