Skip to content

Commit 043204c

Browse files
committed
golang: return ErrSyscallDoesNotExist when unable to resolve a syscall
This patch is based on a previous patch by Michael Vogt that was forward ported by the current main branch. Suggested-by: Michael Vogt <[email protected]> Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 4b7f544 commit 043204c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

seccomp.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ const (
185185
CompareMaskedEqual ScmpCompareOp = iota
186186
)
187187

188+
var (
189+
ErrSyscallDoesNotExist = fmt.Errorf("could not resolve syscall name")
190+
)
191+
188192
// Helpers for types
189193

190194
// GetArchFromString returns an ScmpArch constant from a string representing an
@@ -398,7 +402,7 @@ func (s ScmpSyscall) GetNameByArch(arch ScmpArch) (string, error) {
398402

399403
cString := C.seccomp_syscall_resolve_num_arch(arch.toNative(), C.int(s))
400404
if cString == nil {
401-
return "", fmt.Errorf("could not resolve syscall name for %#x", int32(s))
405+
return "", ErrSyscallDoesNotExist
402406
}
403407
defer C.free(unsafe.Pointer(cString))
404408

@@ -421,7 +425,7 @@ func GetSyscallFromName(name string) (ScmpSyscall, error) {
421425

422426
result := C.seccomp_syscall_resolve_name(cString)
423427
if result == scmpError {
424-
return 0, fmt.Errorf("could not resolve name to syscall: %q", name)
428+
return 0, ErrSyscallDoesNotExist
425429
}
426430

427431
return ScmpSyscall(result), nil
@@ -445,7 +449,7 @@ func GetSyscallFromNameByArch(name string, arch ScmpArch) (ScmpSyscall, error) {
445449

446450
result := C.seccomp_syscall_resolve_name_arch(arch.toNative(), cString)
447451
if result == scmpError {
448-
return 0, fmt.Errorf("could not resolve name to syscall: %q on %v", name, arch)
452+
return 0, ErrSyscallDoesNotExist
449453
}
450454

451455
return ScmpSyscall(result), nil

0 commit comments

Comments
 (0)