summaryrefslogtreecommitdiff
path: root/src/shared/seccomp-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-01-01 08:46:06 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-01-19 07:04:19 +0900
commit22eadc289bd534b723457557b16469a2a81d6be8 (patch)
tree49ca7f8b8a8cea55c264365c9d6c2350249f6502 /src/shared/seccomp-util.c
parent09f7c7c6687a6d0c939e7e54a433e0bab63292f8 (diff)
downloadsystemd-22eadc289bd534b723457557b16469a2a81d6be8.tar.gz
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.
Diffstat (limited to 'src/shared/seccomp-util.c')
-rw-r--r--src/shared/seccomp-util.c38
1 files changed, 38 insertions, 0 deletions
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;
+}