seccomp-util: add parse_syscall_archs()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Aug 2017 04:46:45 +0000 (13:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Aug 2017 14:41:52 +0000 (23:41 +0900)
src/shared/seccomp-util.c
src/shared/seccomp-util.h

index 5d8a698..147b1b2 100644 (file)
@@ -30,7 +30,9 @@
 #include "macro.h"
 #include "nsflags.h"
 #include "seccomp-util.h"
+#include "set.h"
 #include "string-util.h"
+#include "strv.h"
 #include "util.h"
 #include "errno-list.h"
 
@@ -1313,3 +1315,33 @@ int seccomp_restrict_archs(Set *archs) {
 
         return seccomp_load(seccomp);
 }
+
+int parse_syscall_archs(char **l, Set **archs) {
+        _cleanup_set_free_ Set *_archs;
+        char **s;
+        int r;
+
+        assert(l);
+        assert(archs);
+
+        r = set_ensure_allocated(&_archs, NULL);
+        if (r < 0)
+                return r;
+
+        STRV_FOREACH(s, l) {
+                uint32_t a;
+
+                r = seccomp_arch_from_string(*s, &a);
+                if (r < 0)
+                        return -EINVAL;
+
+                r = set_put(_archs, UINT32_TO_PTR(a + 1));
+                if (r < 0)
+                        return -ENOMEM;
+        }
+
+        *archs = _archs;
+        _archs = NULL;
+
+        return 0;
+}
index 4438e87..596539e 100644 (file)
@@ -84,3 +84,5 @@ extern const uint32_t seccomp_local_archs[];
              (arch) = seccomp_local_archs[++_i])
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release);
+
+int parse_syscall_archs(char **l, Set **archs);