apparmor-util: shortcut mac_apparmor_use() if compile-time disabled

This commit is contained in:
Lennart Poettering
2025-11-20 14:20:37 +01:00
parent c3b3eea2e5
commit b5dbe7179b
2 changed files with 8 additions and 7 deletions

View File

@@ -39,7 +39,6 @@ int dlopen_libapparmor(void) {
DLSYM_ARG(aa_policy_cache_replace_all),
DLSYM_ARG(aa_policy_cache_unref));
}
#endif
bool mac_apparmor_use(void) {
static int cached_use = -1;
@@ -57,14 +56,14 @@ bool mac_apparmor_use(void) {
}
r = parse_boolean(p);
if (r <= 0) {
if (r < 0)
log_debug_errno(r, "Failed to parse /sys/module/apparmor/parameters/enabled, assuming AppArmor is not available: %m");
if (r < 0)
log_debug_errno(r, "Failed to parse /sys/module/apparmor/parameters/enabled, assuming AppArmor is not available: %m");
if (r <= 0)
return (cached_use = false);
}
if (dlopen_libapparmor() < 0)
return (cached_use = false);
return (cached_use = true);
}
#endif

View File

@@ -21,10 +21,12 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(aa_features*, sym_aa_features_unref, aa_
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_RENAME(aa_policy_cache*, sym_aa_policy_cache_unref, aa_policy_cache_unrefp, NULL);
int dlopen_libapparmor(void);
bool mac_apparmor_use(void);
#else
static inline int dlopen_libapparmor(void) {
return -EOPNOTSUPP;
}
static inline bool mac_apparmor_use(void) {
return false;
}
#endif
bool mac_apparmor_use(void);