Skip to content

Instantly share code, notes, and snippets.

@ymgyt
Created August 1, 2017 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ymgyt/d90b3dec11045043a9069619f79b7ae4 to your computer and use it in GitHub Desktop.
Save ymgyt/d90b3dec11045043a9069619f79b7ae4 to your computer and use it in GitHub Desktop.
// 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