From 5369c77d2ee864ac0464d4adc0774ee70ba9c4bc Mon Sep 17 00:00:00 2001
From: Daniel Mack <zonque@gmail.com>
Date: Mon, 18 Aug 2014 22:07:47 +0200
Subject: [PATCH] bus: factor out bus policy items
In order to re-use the policy definitions, factor them out into their own
files.
---
Makefile.am | 2 ++
src/core/bus-common.c | 35 +++++++++++++++++++++++++++++++++++
src/core/bus-common.h | 35 +++++++++++++++++++++++++++++++++++
src/core/busname.c | 8 --------
src/core/busname.h | 16 +++-------------
src/core/load-fragment.c | 4 ++--
src/libsystemd/sd-bus/bus-kernel.c | 12 ++++++------
src/libsystemd/sd-bus/bus-kernel.h | 2 +-
src/test/test-tables.c | 2 +-
9 files changed, 85 insertions(+), 31 deletions(-)
create mode 100644 src/core/bus-common.c
create mode 100644 src/core/bus-common.h
diff --git a/Makefile.am b/Makefile.am
index 9c946d7a92..68a78963c1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
index 0000000000..4a61cb9a3a
--- /dev/null
+++ b/src/core/bus-common.c
@@ -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
index 0000000000..209f870c72
--- /dev/null
+++ b/src/core/bus-common.h
@@ -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_;
diff --git a/src/core/busname.c b/src/core/busname.c
index 39ea6a0d93..22d2a6d24b 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -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),
diff --git a/src/core/busname.h b/src/core/busname.h
index 65d57f710a..c9b653d82e 100644
--- a/src/core/busname.h
+++ b/src/core/busname.h
@@ -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_;
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index fda27becb5..b4da6a550e 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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);
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 03c4165095..ca0eddb38d 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -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;
diff --git a/src/libsystemd/sd-bus/bus-kernel.h b/src/libsystemd/sd-bus/bus-kernel.h
index 448dd3a797..182f953d47 100644
--- a/src/libsystemd/sd-bus/bus-kernel.h
+++ b/src/libsystemd/sd-bus/bus-kernel.h
@@ -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);
diff --git a/src/test/test-tables.c b/src/test/test-tables.c
index 58fe4433b7..907958e461 100644
--- a/src/test/test-tables.c
+++ b/src/test/test-tables.c
@@ -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);