]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/analyze/analyze-syscall-filter.c
mkosi: update arch commit reference
[thirdparty/systemd.git] / src / analyze / analyze-syscall-filter.c
index 50cd62a71c14bed44c5f369a2711c26d18c95ad6..66a52da8976d504bf7d50daf353f1921253e24e2 100644 (file)
@@ -58,23 +58,39 @@ static int load_kernel_syscalls(Set **ret) {
         return 0;
 }
 
-static void syscall_set_remove(Set *s, const SyscallFilterSet *set) {
-        const char *syscall;
+static int syscall_set_add(Set **s, const SyscallFilterSet *set) {
+        int r;
+
+        assert(s);
 
+        if (!set)
+                return 0;
+
+        NULSTR_FOREACH(sc, set->value) {
+                if (sc[0] == '@')
+                        continue;
+
+                r = set_put_strdup(s, sc);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
+static void syscall_set_remove(Set *s, const SyscallFilterSet *set) {
         if (!set)
                 return;
 
-        NULSTR_FOREACH(syscall, set->value) {
-                if (syscall[0] == '@')
+        NULSTR_FOREACH(sc, set->value) {
+                if (sc[0] == '@')
                         continue;
 
-                free(set_remove(s, syscall));
+                free(set_remove(s, sc));
         }
 }
 
 static void dump_syscall_filter(const SyscallFilterSet *set) {
-        const char *syscall;
-
         printf("%s%s%s\n"
                "    # %s\n",
                ansi_highlight(),
@@ -88,17 +104,17 @@ static void dump_syscall_filter(const SyscallFilterSet *set) {
 
 int verb_syscall_filters(int argc, char *argv[], void *userdata) {
         bool first = true;
+        int r;
 
         pager_open(arg_pager_flags);
 
         if (strv_isempty(strv_skip(argv, 1))) {
                 _cleanup_set_free_ Set *kernel = NULL, *known = NULL;
-                const char *sys;
                 int k = 0;  /* explicit initialization to appease gcc */
 
-                NULSTR_FOREACH(sys, syscall_filter_sets[SYSCALL_FILTER_SET_KNOWN].value)
-                        if (set_put_strdup(&known, sys) < 0)
-                                return log_oom();
+                r = syscall_set_add(&known, syscall_filter_sets + SYSCALL_FILTER_SET_KNOWN);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to prepare set of known system calls: %m");
 
                 if (!arg_quiet)
                         k = load_kernel_syscalls(&kernel);
@@ -120,7 +136,6 @@ int verb_syscall_filters(int argc, char *argv[], void *userdata) {
 
                 if (!set_isempty(known)) {
                         _cleanup_free_ char **l = NULL;
-                        char **syscall;
 
                         printf("\n"
                                "# %sUngrouped System Calls%s (known but not included in any of the groups except @known):\n",
@@ -143,7 +158,6 @@ int verb_syscall_filters(int argc, char *argv[], void *userdata) {
                                 log_notice_errno(k, "# Not showing unlisted system calls, couldn't retrieve kernel system call list: %m");
                 } else if (!set_isempty(kernel)) {
                         _cleanup_free_ char **l = NULL;
-                        char **syscall;
 
                         printf("\n"
                                "# %sUnlisted System Calls%s (supported by the local kernel, but not included in any of the groups listed above):\n",
@@ -158,9 +172,7 @@ int verb_syscall_filters(int argc, char *argv[], void *userdata) {
                         STRV_FOREACH(syscall, l)
                                 printf("#   %s\n", *syscall);
                 }
-        } else {
-                char **name;
-
+        } else
                 STRV_FOREACH(name, strv_skip(argv, 1)) {
                         const SyscallFilterSet *set;
 
@@ -179,9 +191,8 @@ int verb_syscall_filters(int argc, char *argv[], void *userdata) {
                         dump_syscall_filter(set);
                         first = false;
                 }
-        }
 
-        return 0;
+        return EXIT_SUCCESS;
 }
 
 #else