Skip to content

Commit

Permalink
sysutil: fix binding capability defining
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Dec 4, 2020
1 parent 4134220 commit 5aa0202
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/sysutil/os_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (

func canBindPrivilegedPorts() (can bool, err error) {
cnbs, err := unix.PrctlRetInt(unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0)
return cnbs == 1, err
// Don't check the error because it's always nil on Linux.
adm, _ := haveAdminRights()

return cnbs == 1 || adm, err
}

func setRlimit(val uint) {
Expand All @@ -26,6 +29,8 @@ func setRlimit(val uint) {
}

func haveAdminRights() (bool, error) {
// The error is nil because the platform-independent function signature
// requires returning an error.
return os.Getuid() == 0, nil
}

Expand Down

0 comments on commit 5aa0202

Please sign in to comment.