@@ -41,9 +41,6 @@ type VersionError struct {
4141 minimum string
4242}
4343
44- // Caches the libseccomp API level
45- var apiLevel uint
46-
4744func init () {
4845 // This forces the cgo libseccomp to initialize its internal API support state,
4946 // which is necessary on older versions of libseccomp in order to work
@@ -451,12 +448,7 @@ func GetLibraryVersion() (major, minor, micro uint) {
451448// See the seccomp_api_get(3) man page for details on available API levels:
452449// https://github.com/seccomp/libseccomp/blob/main/doc/man/man3/seccomp_api_get.3
453450func GetAPI () (uint , error ) {
454- api , err := getAPI ()
455- if err != nil {
456- return api , err
457- }
458- apiLevel = api
459- return api , err
451+ return getAPI ()
460452}
461453
462454// SetAPI forcibly sets the API level. General use of this function is strongly
@@ -466,11 +458,7 @@ func GetAPI() (uint, error) {
466458// See the seccomp_api_get(3) man page for details on available API levels:
467459// https://github.com/seccomp/libseccomp/blob/main/doc/man/man3/seccomp_api_get.3
468460func SetAPI (api uint ) error {
469- if err := setAPI (api ); err != nil {
470- return err
471- }
472- apiLevel = api
473- return nil
461+ return setAPI (api )
474462}
475463
476464// Syscall functions
@@ -909,6 +897,8 @@ func (f *ScmpFilter) GetNoNewPrivsBit() (bool, error) {
909897func (f * ScmpFilter ) GetLogBit () (bool , error ) {
910898 log , err := f .getFilterAttr (filterAttrLog )
911899 if err != nil {
900+ // Ignore error, if not supported returns apiLevel == 0
901+ apiLevel , _ := GetAPI ()
912902 if apiLevel < 3 {
913903 return false , fmt .Errorf ("getting the log bit is only supported in libseccomp 2.4.0 and newer with API level 3 or higher" )
914904 }
@@ -986,6 +976,8 @@ func (f *ScmpFilter) SetLogBit(state bool) error {
986976
987977 err := f .setFilterAttr (filterAttrLog , toSet )
988978 if err != nil {
979+ // Ignore error, if not supported returns apiLevel == 0
980+ apiLevel , _ := GetAPI ()
989981 if apiLevel < 3 {
990982 return fmt .Errorf ("setting the log bit is only supported in libseccomp 2.4.0 and newer with API level 3 or higher" )
991983 }
0 commit comments