From b16bd5350fe686a0e8e1ef39cc35c383fb1560a1 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 2 Aug 2017 13:46:45 +0900 Subject: [PATCH] seccomp-util: add parse_syscall_archs() --- src/shared/seccomp-util.c | 32 ++++++++++++++++++++++++++++++++ src/shared/seccomp-util.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index 5d8a698..147b1b2 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 4438e87..596539e 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); -- 2.7.4