chiark / gitweb /
bus: factor out bus policy items
authorDaniel Mack <zonque@gmail.com>
Mon, 18 Aug 2014 20:07:47 +0000 (22:07 +0200)
committerDaniel Mack <daniel@zonque.org>
Mon, 8 Sep 2014 09:06:45 +0000 (11:06 +0200)
In order to re-use the policy definitions, factor them out into their own
files.

Makefile.am
src/core/bus-common.c [new file with mode: 0644]
src/core/bus-common.h [new file with mode: 0644]
src/core/busname.c
src/core/busname.h
src/core/load-fragment.c
src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/bus-kernel.h
src/test/test-tables.c

index 9c946d7a92f2cc0753e440076e87a768c431f22a..68a78963c19ea7cfc6ae315076d57b988d85544a 100644 (file)
@@ -1026,6 +1026,8 @@ libsystemd_core_la_SOURCES = \
        src/core/socket.h \
        src/core/busname.c \
        src/core/busname.h \
+       src/core/bus-common.c \
+       src/core/bus-common.h \
        src/core/target.c \
        src/core/target.h \
        src/core/snapshot.c \
diff --git a/src/core/bus-common.c b/src/core/bus-common.c
new file mode 100644 (file)
index 0000000..4a61cb9
--- /dev/null
@@ -0,0 +1,35 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2014 Daniel Mack
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "special.h"
+#include "bus-kernel.h"
+#include "bus-internal.h"
+#include "bus-util.h"
+#include "service.h"
+#include "bus-common.h"
+
+static const char* const bus_policy_access_table[_BUS_POLICY_ACCESS_MAX] = {
+        [BUS_POLICY_ACCESS_SEE] = "see",
+        [BUS_POLICY_ACCESS_TALK] = "talk",
+        [BUS_POLICY_ACCESS_OWN] = "own",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(bus_policy_access, BusPolicyAccess);
diff --git a/src/core/bus-common.h b/src/core/bus-common.h
new file mode 100644 (file)
index 0000000..209f870
--- /dev/null
@@ -0,0 +1,35 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+#include "macro.h"
+
+/***
+  This file is part of systemd.
+
+  Copyright 2014 Daniel Mack
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+typedef enum BusPolicyAccess {
+        BUS_POLICY_ACCESS_SEE,
+        BUS_POLICY_ACCESS_TALK,
+        BUS_POLICY_ACCESS_OWN,
+        _BUS_POLICY_ACCESS_MAX,
+        _BUS_POLICY_ACCESS_INVALID = -1
+} BusPolicyAccess;
+
+const char* bus_policy_access_to_string(BusPolicyAccess i) _const_;
+BusPolicyAccess bus_policy_access_from_string(const char *s) _pure_;
index 39ea6a0d939cbc5aa2e89e7fc7ca5079472fbd30..22d2a6d24b49aaed7e338749b4677cfa89c362be 100644 (file)
@@ -911,14 +911,6 @@ static const char* const busname_result_table[_BUSNAME_RESULT_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP(busname_result, BusNameResult);
 
-static const char* const busname_policy_access_table[_BUSNAME_POLICY_ACCESS_MAX] = {
-        [BUSNAME_POLICY_ACCESS_SEE] = "see",
-        [BUSNAME_POLICY_ACCESS_TALK] = "talk",
-        [BUSNAME_POLICY_ACCESS_OWN] = "own",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(busname_policy_access, BusNamePolicyAccess);
-
 const UnitVTable busname_vtable = {
         .object_size = sizeof(BusName),
 
index 65d57f710a7745dbd3583623f3828e947abd6ce0..c9b653d82e6081389e801fa5b0afc3090cde7404 100644 (file)
@@ -25,6 +25,7 @@ typedef struct BusName BusName;
 typedef struct BusNamePolicy BusNamePolicy;
 
 #include "unit.h"
+#include "bus-common.h"
 
 typedef enum BusNameState {
         BUSNAME_DEAD,
@@ -58,17 +59,9 @@ typedef enum BusNamePolicyType {
         _BUSNAME_POLICY_TYPE_INVALID = -1
 } BusNamePolicyType;
 
-typedef enum BusNamePolicyAccess {
-        BUSNAME_POLICY_ACCESS_SEE,
-        BUSNAME_POLICY_ACCESS_TALK,
-        BUSNAME_POLICY_ACCESS_OWN,
-        _BUSNAME_POLICY_ACCESS_MAX,
-        _BUSNAME_POLICY_ACCESS_INVALID = -1
-} BusNamePolicyAccess;
-
 struct BusNamePolicy {
         BusNamePolicyType type;
-        BusNamePolicyAccess access;
+        BusPolicyAccess access;
 
         char *name;
 
@@ -97,7 +90,7 @@ struct BusName {
         pid_t control_pid;
 
         LIST_HEAD(BusNamePolicy, policy);
-        BusNamePolicyAccess policy_world;
+        BusPolicyAccess policy_world;
 };
 
 extern const UnitVTable busname_vtable;
@@ -107,6 +100,3 @@ BusNameState busname_state_from_string(const char *s) _pure_;
 
 const char* busname_result_to_string(BusNameResult i) _const_;
 BusNameResult busname_result_from_string(const char *s) _pure_;
-
-const char* busname_policy_access_to_string(BusNamePolicyAccess i) _const_;
-BusNamePolicyAccess busname_policy_access_from_string(const char *s) _pure_;
index fda27becb50c29c874ea859e31e6d42f8411782a..b4da6a550eba27912a93996a5b2869511889c328 100644 (file)
@@ -1686,7 +1686,7 @@ int config_parse_busname_service(
         return 0;
 }
 
-DEFINE_CONFIG_PARSE_ENUM(config_parse_bus_policy_world, busname_policy_access, BusNamePolicyAccess, "Failed to parse bus name policy access");
+DEFINE_CONFIG_PARSE_ENUM(config_parse_bus_policy_world, bus_policy_access, BusPolicyAccess, "Failed to parse bus name policy access");
 
 int config_parse_bus_policy(
                 const char *unit,
@@ -1736,7 +1736,7 @@ int config_parse_bus_policy(
         access_str++;
         access_str += strspn(access_str, WHITESPACE);
 
-        p->access = busname_policy_access_from_string(access_str);
+        p->access = bus_policy_access_from_string(access_str);
         if (p->access < 0) {
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
                            "Invalid busname policy access type '%s'", access_str);
index 03c4165095ce0a7c2d130d3318d2fe6c05f98dc2..ca0eddb38d561ab4dcc5ad97ad6683b73be65227 100644 (file)
@@ -1322,19 +1322,19 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
         return fd;
 }
 
-static int bus_kernel_translate_access(BusNamePolicyAccess access) {
+static int bus_kernel_translate_access(BusPolicyAccess access) {
         assert(access >= 0);
-        assert(access < _BUSNAME_POLICY_ACCESS_MAX);
+        assert(access < _BUS_POLICY_ACCESS_MAX);
 
         switch (access) {
 
-        case BUSNAME_POLICY_ACCESS_SEE:
+        case BUS_POLICY_ACCESS_SEE:
                 return KDBUS_POLICY_SEE;
 
-        case BUSNAME_POLICY_ACCESS_TALK:
+        case BUS_POLICY_ACCESS_TALK:
                 return KDBUS_POLICY_TALK;
 
-        case BUSNAME_POLICY_ACCESS_OWN:
+        case BUS_POLICY_ACCESS_OWN:
                 return KDBUS_POLICY_OWN;
 
         default:
@@ -1414,7 +1414,7 @@ int bus_kernel_make_starter(
                 bool activating,
                 bool accept_fd,
                 BusNamePolicy *policy,
-                BusNamePolicyAccess world_policy) {
+                BusPolicyAccess world_policy) {
 
         struct kdbus_cmd_hello *hello;
         struct kdbus_item *n;
index 448dd3a79754b8963afab507e79d4894ee6302eb..182f953d47d1e4256456901f0000be7a22047619 100644 (file)
@@ -66,7 +66,7 @@ int bus_kernel_write_message(sd_bus *bus, sd_bus_message *m, bool hint_sync_call
 int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority);
 
 int bus_kernel_open_bus_fd(const char *bus, char **path);
-int bus_kernel_make_starter(int fd, const char *name, bool activating, bool accept_fd, BusNamePolicy *policy, BusNamePolicyAccess world_policy);
+int bus_kernel_make_starter(int fd, const char *name, bool activating, bool accept_fd, BusNamePolicy *policy, BusPolicyAccess world_policy);
 
 int bus_kernel_create_bus(const char *name, bool world, char **s);
 int bus_kernel_create_domain(const char *name, char **s);
index 58fe4433b7ebbfce401ec89a9b36b03a2690b65c..907958e46166842a14209ad0da206d084cbd47dc 100644 (file)
@@ -55,7 +55,7 @@ int main(int argc, char **argv) {
         test_table(architecture, ARCHITECTURE);
         test_table(automount_result, AUTOMOUNT_RESULT);
         test_table(automount_state, AUTOMOUNT_STATE);
-        test_table(busname_policy_access, BUSNAME_POLICY_ACCESS);
+        test_table(bus_policy_access, BUS_POLICY_ACCESS);
         test_table(busname_result, BUSNAME_RESULT);
         test_table(busname_state, BUSNAME_STATE);
         test_table(cgroup_device_policy, CGROUP_DEVICE_POLICY);