Created
August 1, 2017 12:37
-
-
Save ymgyt/d90b3dec11045043a9069619f79b7ae4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check root rights to use system service | |
func checkPrivileges() (bool, error) { | |
if output, err := exec.Command("id", "-g").Output(); err == nil { | |
if gid, parseErr := strconv.ParseUint(strings.TrimSpace(string(output)), 10, 32); parseErr == nil { | |
if gid == 0 { | |
return true, nil | |
} | |
return false, ErrRootPriveleges | |
} | |
} | |
return false, ErrUnsupportedSystem | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment