summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2017-08-02 06:46:45 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2017-08-07 16:41:52 +0200
commitb16bd5350fe686a0e8e1ef39cc35c383fb1560a1 (patch)
treecd5c686d1289da42e297c8c391e9760e8e083bc5 /src
parentprocess-util: add sched_{policy,priority}_is_valid() (diff)
downloadsystemd-b16bd5350fe686a0e8e1ef39cc35c383fb1560a1.tar.xz
systemd-b16bd5350fe686a0e8e1ef39cc35c383fb1560a1.zip
seccomp-util: add parse_syscall_archs()
Diffstat (limited to 'src')
-rw-r--r--src/shared/seccomp-util.c32
-rw-r--r--src/shared/seccomp-util.h2
2 files changed, 34 insertions, 0 deletions
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
index 5d8a6986b7..147b1b2ab2 100644
--- a/src/shared/seccomp-util.c
+++ b/src/shared/seccomp-util.c
@@ -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;
+}
diff --git a/src/shared/seccomp-util.h b/src/shared/seccomp-util.h
index 4438e87fa6..596539e8f5 100644
--- a/src/shared/seccomp-util.h
+++ b/src/shared/seccomp-util.h
@@ -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);