From: Yu Watanabe Date: Wed, 2 Aug 2017 04:46:45 +0000 (+0900) Subject: seccomp-util: add parse_syscall_archs() X-Git-Tag: v235~248^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b16bd5350fe686a0e8e1ef39cc35c383fb1560a1;p=thirdparty%2Fsystemd.git seccomp-util: add parse_syscall_archs() --- diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index 5d8a6986b72..147b1b2ab2e 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 4438e87fa6c..596539e8f55 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);