From: Yu Watanabe Date: Thu, 31 Dec 2020 23:46:06 +0000 (+0900) Subject: util: move parse_syscall_and_errno() to seccomp-util.c X-Git-Tag: v248-rc1~304^2~30 X-Git-Url: http://git-history.diyao.me/?a=commitdiff_plain;h=22eadc289bd534b723457557b16469a2a81d6be8;p=systemd%2F.git util: move parse_syscall_and_errno() to seccomp-util.c This makes parse-util.c independent of seccomp-util.c, which is located in src/shared. --- diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 5d4dafe3a5..8ca8f251e1 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -16,9 +16,6 @@ #include "missing_network.h" #include "parse-util.h" #include "process-util.h" -#if HAVE_SECCOMP -#include "seccomp-util.h" -#endif #include "stat-util.h" #include "string-util.h" #include "strv.h" @@ -317,46 +314,6 @@ int parse_errno(const char *t) { return e; } -#if HAVE_SECCOMP -int parse_syscall_and_errno(const char *in, char **name, int *error) { - _cleanup_free_ char *n = NULL; - char *p; - int e = -1; - - assert(in); - assert(name); - assert(error); - - /* - * This parse "syscall:errno" like "uname:EILSEQ", "@sync:255". - * If errno is omitted, then error is set to -1. - * Empty syscall name is not allowed. - * Here, we do not check that the syscall name is valid or not. - */ - - p = strchr(in, ':'); - if (p) { - e = seccomp_parse_errno_or_action(p + 1); - if (e < 0) - return e; - - n = strndup(in, p - in); - } else - n = strdup(in); - - if (!n) - return -ENOMEM; - - if (isempty(n)) - return -EINVAL; - - *error = e; - *name = TAKE_PTR(n); - - return 0; -} -#endif - static const char *mangle_base(const char *s, unsigned *base) { const char *k; diff --git a/src/basic/parse-util.h b/src/basic/parse-util.h index 81478ed059..1ff76ded44 100644 --- a/src/basic/parse-util.h +++ b/src/basic/parse-util.h @@ -22,9 +22,6 @@ int parse_mtu(int family, const char *s, uint32_t *ret); int parse_size(const char *t, uint64_t base, uint64_t *size); int parse_range(const char *t, unsigned *lower, unsigned *upper); int parse_errno(const char *t); -#if HAVE_SECCOMP -int parse_syscall_and_errno(const char *in, char **name, int *error); -#endif #define SAFE_ATO_REFUSE_PLUS_MINUS (1U << 30) #define SAFE_ATO_REFUSE_LEADING_ZERO (1U << 29) diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index b5f9ad9adc..03d039f778 100644 --- a/src/shared/seccomp-util.c +++ b/src/shared/seccomp-util.c @@ -2151,3 +2151,41 @@ uint32_t scmp_act_kill_process(void) { return SCMP_ACT_KILL; /* same as SCMP_ACT_KILL_THREAD */ } + +int parse_syscall_and_errno(const char *in, char **name, int *error) { + _cleanup_free_ char *n = NULL; + char *p; + int e = -1; + + assert(in); + assert(name); + assert(error); + + /* + * This parse "syscall:errno" like "uname:EILSEQ", "@sync:255". + * If errno is omitted, then error is set to -1. + * Empty syscall name is not allowed. + * Here, we do not check that the syscall name is valid or not. + */ + + p = strchr(in, ':'); + if (p) { + e = seccomp_parse_errno_or_action(p + 1); + if (e < 0) + return e; + + n = strndup(in, p - in); + } else + n = strdup(in); + + if (!n) + return -ENOMEM; + + if (isempty(n)) + return -EINVAL; + + *error = e; + *name = TAKE_PTR(n); + + return 0; +} diff --git a/src/shared/seccomp-util.h b/src/shared/seccomp-util.h index 53b74bdc34..ee6f7b878b 100644 --- a/src/shared/seccomp-util.h +++ b/src/shared/seccomp-util.h @@ -148,3 +148,5 @@ static inline const char *seccomp_errno_or_action_to_string(int num) { return "kill"; return errno_to_name(num); } + +int parse_syscall_and_errno(const char *in, char **name, int *error);