]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
seccomp: get_v2_action()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 11:47:59 +0000 (13:47 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 11:47:59 +0000 (13:47 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/seccomp.c

index f03dc4ab5060efb7706e7d5982e9d4f60cf7f5e3..d2f80cb7092ea00db68908451541d08836b90b65 100644 (file)
@@ -65,6 +65,23 @@ static int parse_config_v1(FILE *f, struct lxc_conf *conf)
 }
 
 #if HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH
+static const char *get_action_name(uint32_t action)
+{
+       /* The upper 16 bits indicate the type of the seccomp action. */
+       switch (action & 0xffff0000) {
+       case SCMP_ACT_KILL:
+               return "kill";
+       case SCMP_ACT_ALLOW:
+               return "allow";
+       case SCMP_ACT_TRAP:
+               return "trap";
+       case SCMP_ACT_ERRNO(0):
+               return "errno";
+       }
+
+       return "invalid action";
+}
+
 static uint32_t get_v2_default_action(char *line)
 {
        uint32_t ret_action = -1;
@@ -94,41 +111,31 @@ static uint32_t get_v2_default_action(char *line)
        return ret_action;
 }
 
-static const char *get_action_name(uint32_t action)
-{
-       /* The upper 16 bits indicate the type of the seccomp action. */
-       switch (action & 0xffff0000) {
-       case SCMP_ACT_KILL:
-               return "kill";
-       case SCMP_ACT_ALLOW:
-               return "allow";
-       case SCMP_ACT_TRAP:
-               return "trap";
-       case SCMP_ACT_ERRNO(0):
-               return "errno";
-       }
-
-       return "invalid action";
-}
-
 static uint32_t get_v2_action(char *line, uint32_t def_action)
 {
-       char *p = strchr(line, ' ');
+       char *p;
        uint32_t ret;
 
+       p = strchr(line, ' ');
        if (!p)
                return def_action;
        p++;
+
        while (*p == ' ')
                p++;
+
        if (!*p || *p == '#')
                return def_action;
+
        ret = get_v2_default_action(p);
-       switch(ret) {
-       case -2: return -1;
-       case -1: return def_action;
-       default: return ret;
+       switch (ret) {
+       case -2:
+               return -1;
+       case -1:
+               return def_action;
        }
+
+       return ret;
 }
 
 struct v2_rule_args {