Skip to content

Commit 444e638

Browse files
committed
SetAPI: embed rc into error
In case seccomp_api_set() failed, embed its return code into the error (rather than merely adding -N text into it), so that a user can check for a particular error using e.g. errors.Is(err, syscall.EINVAL). Do not embed EOPNOTSUPP since this is not what libseccomp returns (this is returned by own code in case it is compiled with old (< 2.4.0) libseccomp headers). Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 413543e commit 444e638

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

seccomp_internal.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,12 @@ func getAPI() (uint, error) {
349349
// Set the API level
350350
func setAPI(api uint) error {
351351
if retCode := C.seccomp_api_set(C.uint(api)); retCode != 0 {
352-
if errRc(retCode) == syscall.EOPNOTSUPP {
352+
e := errRc(retCode)
353+
if e == syscall.EOPNOTSUPP {
353354
return fmt.Errorf("API level operations are not supported")
354355
}
355356

356-
return fmt.Errorf("could not set API level: %v", retCode)
357+
return fmt.Errorf("could not set API level: %w", e)
357358
}
358359

359360
return nil

0 commit comments

Comments
 (0)