github.imxd.top/hashicorp/consul@v1.4.5/agent/proxyprocess/root.go (about)

     1  package proxyprocess
     2  
     3  import (
     4  	"os"
     5  )
     6  
     7  // isRoot returns true if the process is executing as root.
     8  func isRoot() bool {
     9  	if testRootValue != nil {
    10  		return *testRootValue
    11  	}
    12  
    13  	return os.Geteuid() == 0
    14  }
    15  
    16  // testSetRootValue is a test helper for setting the root value.
    17  func testSetRootValue(v bool) func() {
    18  	testRootValue = &v
    19  	return func() { testRootValue = nil }
    20  }
    21  
    22  // testRootValue should be set to a non-nil value to return it as a stub
    23  // from isRoot. This should only be used in tests.
    24  var testRootValue *bool