Skip to content

Commit

Permalink
Apply: fix ambient caps error handling
Browse files Browse the repository at this point in the history
Commit e7cb7fa added support for ambient capabilities. Unfortunately,
the code added to Apply is incorrect because it uses a local variable
err which is never used or returned.

Found by a linter:

> capability_linux.go:480:5: ineffectual assignment to err (ineffassign)
> 				err = nil
> 				^

Fixes: e7cb7fa
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 22, 2024
1 parent 96ee438 commit 4d79446
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions capability_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,14 @@ func (c *capsV3) Apply(kind CapType) (err error) {
if c.Get(AMBIENT, i) {
action = pr_CAP_AMBIENT_RAISE
}
err := prctl(pr_CAP_AMBIENT, action, uintptr(i), 0, 0)
// Ignore EINVAL as not supported on kernels before 4.3
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINVAL {
err = nil
continue
err = prctl(pr_CAP_AMBIENT, action, uintptr(i), 0, 0)
if err != nil {
// Ignore EINVAL as not supported on kernels before 4.3
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINVAL {
err = nil
continue
}
return
}
}
}
Expand Down

0 comments on commit 4d79446

Please sign in to comment.