util: move parse_syscall_and_errno() to seccomp-util.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 31 Dec 2020 23:46:06 +0000 (08:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 18 Jan 2021 22:04:19 +0000 (07:04 +0900)
This makes parse-util.c independent of seccomp-util.c, which is located
in src/shared.

src/basic/parse-util.c
src/basic/parse-util.h
src/shared/seccomp-util.c
src/shared/seccomp-util.h

index 5d4dafe3a5956527fea76269de489be172e809a0..8ca8f251e142b6d9cf7b6ea5c69a4835115cf72b 100644 (file)
@@ -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;
 
index 81478ed0591177e21d1a170a0955067af38f5de5..1ff76ded446c468d0aea374f4f8e9978705f768d 100644 (file)
@@ -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)
index b5f9ad9adc2c67192e3eff8a104c5a85e655d572..03d039f778ff2c962bf1ea5ee2265c7944a368fb 100644 (file)
@@ -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;
+}
index 53b74bdc3424f585b961ef2e320faf4cf73dc74a..ee6f7b878bd49423fea9eefd89ec87f200585750 100644 (file)
@@ -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);