diff options
author | Daniel Mack <zonque@gmail.com> | 2014-03-17 11:41:21 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-19 02:25:36 +0100 |
commit | 5892a914d173e4b968d2a14fbf717373dee3999a (patch) | |
tree | ca7305c322b9f7544d888e4cfac6de93cca8ac5f /src | |
parent | ec8408740a32888f0bbbdcb79ccfbf550b12f19f (diff) |
busname: introduce Activating directive
Add a new config 'Activating' directive which denotes whether a busname
is actually registered on the bus. It defaults to 'yes'.
If set to 'no', the .busname unit only uploads policy, which will remain
active as long as the unit is running.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/busname.c | 57 | ||||
-rw-r--r-- | src/core/busname.h | 2 | ||||
-rw-r--r-- | src/core/load-fragment-gperf.gperf.m4 | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-kernel.c | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-kernel.h | 2 |
5 files changed, 44 insertions, 24 deletions
diff --git a/src/core/busname.c b/src/core/busname.c index ccef32e9e7..0cae20d2d1 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -29,6 +29,7 @@ static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = { [BUSNAME_DEAD] = UNIT_INACTIVE, + [BUSNAME_REGISTERED] = UNIT_ACTIVE, [BUSNAME_LISTENING] = UNIT_ACTIVE, [BUSNAME_RUNNING] = UNIT_ACTIVE, [BUSNAME_FAILED] = UNIT_FAILED @@ -96,20 +97,22 @@ static int busname_add_extras(BusName *n) { return r; } - if (!UNIT_DEREF(n->service)) { - Unit *x; + if (n->activating) { + if (!UNIT_DEREF(n->service)) { + Unit *x; - r = unit_load_related_unit(u, ".service", &x); + r = unit_load_related_unit(u, ".service", &x); + if (r < 0) + return r; + + unit_ref_set(&n->service, x); + } + + r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true); if (r < 0) return r; - - unit_ref_set(&n->service, x); } - r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true); - if (r < 0) - return r; - if (u->default_dependencies) { r = busname_add_default_default_dependencies(n); if (r < 0) @@ -172,10 +175,12 @@ static void busname_dump(Unit *u, FILE *f, const char *prefix) { "%sBus Name State: %s\n" "%sResult: %s\n" "%sName: %s\n" + "%sActivating: %s\n" "%sAccept FD: %s\n", prefix, busname_state_to_string(n->state), prefix, busname_result_to_string(n->result), prefix, n->name, + prefix, yes_no(n->activating), prefix, yes_no(n->accept_fd)); } @@ -231,7 +236,7 @@ static int busname_open_fd(BusName *n) { n->starter_fd = bus_kernel_create_starter( UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user", - n->name, n->accept_fd, n->policy); + n->name, n->activating, n->accept_fd, n->policy); if (n->starter_fd < 0) { log_warning_unit(UNIT(n)->id, "Failed to create starter fd: %s", strerror(-n->starter_fd)); @@ -251,7 +256,7 @@ static void busname_set_state(BusName *n, BusNameState state) { if (state != BUSNAME_LISTENING) busname_unwatch_fd(n); - if (!IN_SET(state, BUSNAME_LISTENING, BUSNAME_RUNNING)) + if (!IN_SET(state, BUSNAME_LISTENING, BUSNAME_REGISTERED, BUSNAME_RUNNING)) busname_close_fd(n); if (state != old_state) @@ -271,7 +276,7 @@ static int busname_coldplug(Unit *u) { if (n->deserialized_state == n->state) return 0; - if (IN_SET(n->deserialized_state, BUSNAME_LISTENING, BUSNAME_RUNNING)) { + if (IN_SET(n->deserialized_state, BUSNAME_LISTENING, BUSNAME_REGISTERED, BUSNAME_RUNNING)) { r = busname_open_fd(n); if (r < 0) return r; @@ -303,17 +308,23 @@ static void busname_enter_listening(BusName *n) { r = busname_open_fd(n); if (r < 0) { - log_warning_unit(UNIT(n)->id, "%s failed to listen on bus names: %s", UNIT(n)->id, strerror(-r)); + log_warning_unit(UNIT(n)->id, "%s failed to %s: %s", UNIT(n)->id, + n->activating ? "listen on bus name" : "register policy for name", + strerror(-r)); goto fail; } - r = busname_watch_fd(n); - if (r < 0) { - log_warning_unit(UNIT(n)->id, "%s failed to watch names: %s", UNIT(n)->id, strerror(-r)); - goto fail; - } + if (n->activating) { + r = busname_watch_fd(n); + if (r < 0) { + log_warning_unit(UNIT(n)->id, "%s failed to watch names: %s", UNIT(n)->id, strerror(-r)); + goto fail; + } + + busname_set_state(n, BUSNAME_LISTENING); + } else + busname_set_state(n, BUSNAME_REGISTERED); - busname_set_state(n, BUSNAME_LISTENING); return; fail: @@ -329,6 +340,9 @@ static void busname_enter_running(BusName *n) { assert(n); + if (!n->activating) + return; + /* We don't take conenctions anymore if we are supposed to * shut down anyway */ @@ -369,7 +383,7 @@ static int busname_start(Unit *u) { assert(n); - if (UNIT_ISSET(n->service)) { + if (n->activating && UNIT_ISSET(n->service)) { Service *service; service = SERVICE(UNIT_DEREF(n->service)); @@ -392,7 +406,7 @@ static int busname_stop(Unit *u) { BusName *n = BUSNAME(u); assert(n); - assert(n->state == BUSNAME_LISTENING || n->state == BUSNAME_RUNNING); + assert(IN_SET(n->state, BUSNAME_REGISTERED, BUSNAME_LISTENING, BUSNAME_RUNNING)); busname_enter_dead(n, BUSNAME_SUCCESS); return 0; @@ -536,6 +550,7 @@ static void busname_trigger_notify(Unit *u, Unit *other) { static const char* const busname_state_table[_BUSNAME_STATE_MAX] = { [BUSNAME_DEAD] = "dead", + [BUSNAME_REGISTERED] = "registered", [BUSNAME_LISTENING] = "listening", [BUSNAME_RUNNING] = "running", [BUSNAME_FAILED] = "failed" diff --git a/src/core/busname.h b/src/core/busname.h index 7f591974de..0009c6a65e 100644 --- a/src/core/busname.h +++ b/src/core/busname.h @@ -28,6 +28,7 @@ typedef struct BusNamePolicy BusNamePolicy; typedef enum BusNameState { BUSNAME_DEAD, + BUSNAME_REGISTERED, BUSNAME_LISTENING, BUSNAME_RUNNING, BUSNAME_FAILED, @@ -48,6 +49,7 @@ struct BusName { char *name; int starter_fd; + bool activating; UnitRef service; diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4 index c793a1e25f..1dd9f2b909 100644 --- a/src/core/load-fragment-gperf.gperf.m4 +++ b/src/core/load-fragment-gperf.gperf.m4 @@ -251,6 +251,7 @@ CGROUP_CONTEXT_CONFIG_ITEMS(Socket)m4_dnl KILL_CONTEXT_CONFIG_ITEMS(Socket)m4_dnl m4_dnl BusName.Name, config_parse_string, 0, offsetof(BusName, name) +BusName.Activating, config_parse_bool, 0, offsetof(BusName, activating) BusName.Service, config_parse_busname_service, 0, 0 BusName.AllowUser, config_parse_bus_policy, 0, 0 BusName.AllowGroup, config_parse_bus_policy, 0, 0 diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 977a7cda40..00f58114ac 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -1378,7 +1378,7 @@ static void bus_kernel_translate_policy(const BusNamePolicy *policy, struct kdbu } } -int bus_kernel_create_starter(const char *bus, const char *name, bool accept_fd, BusNamePolicy *policy) { +int bus_kernel_create_starter(const char *bus, const char *name, bool activating, bool accept_fd, BusNamePolicy *policy) { struct kdbus_cmd_hello *hello; struct kdbus_item *n; size_t policy_cnt = 0; @@ -1420,7 +1420,9 @@ int bus_kernel_create_starter(const char *bus, const char *name, bool accept_fd, } hello->size = size; - hello->conn_flags = KDBUS_HELLO_ACTIVATOR | (accept_fd ? KDBUS_HELLO_ACCEPT_FD : 0); + hello->conn_flags = + (activating ? KDBUS_HELLO_ACTIVATOR : KDBUS_HELLO_POLICY_HOLDER) | + (accept_fd ? KDBUS_HELLO_ACCEPT_FD : 0); hello->pool_size = KDBUS_POOL_SIZE; hello->attach_flags = _KDBUS_ATTACH_ALL; diff --git a/src/libsystemd/sd-bus/bus-kernel.h b/src/libsystemd/sd-bus/bus-kernel.h index 3a9794fbe3..4ef26fce64 100644 --- a/src/libsystemd/sd-bus/bus-kernel.h +++ b/src/libsystemd/sd-bus/bus-kernel.h @@ -67,7 +67,7 @@ int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority); int bus_kernel_create_bus(const char *name, bool world, char **s); int bus_kernel_create_domain(const char *name, char **s); -int bus_kernel_create_starter(const char *bus, const char *name, bool accept_fd, BusNamePolicy *policy); +int bus_kernel_create_starter(const char *bus, const char *name, bool activating, bool accept_fd, BusNamePolicy *policy); int bus_kernel_create_monitor(const char *bus); int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *allocated); |