summaryrefslogtreecommitdiff
path: root/service.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-27 06:19:48 +0100
committerLennart Poettering <lennart@poettering.net>2010-01-27 06:19:48 +0100
commitceee3d82853a198884795e5d815b895468212b24 (patch)
tree2e40ab3dff86ae1ebf49d76db1716a8677b095ff /service.c
parent2a987ee8c94ac29545e3c94d47b5d493daea0b5e (diff)
notify socket unit when service unit dies
Diffstat (limited to 'service.c')
-rw-r--r--service.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/service.c b/service.c
index ae7fc36a5c..2c3c0b233b 100644
--- a/service.c
+++ b/service.c
@@ -198,6 +198,34 @@ static int service_load_pid_file(Service *s) {
return 0;
}
+static int service_notify_sockets(Service *s) {
+ Iterator i;
+ char *t;
+
+ assert(s);
+
+ SET_FOREACH(t, UNIT(s)->meta.names, i) {
+ char *k;
+ Unit *p;
+
+ /* Look for all socket objects that go by any of our
+ * units and collect their fds */
+
+ if (!(k = unit_name_change_suffix(t, ".socket")))
+ return -ENOMEM;
+
+ p = manager_get_unit(UNIT(s)->meta.manager, k);
+ free(k);
+
+ if (!p)
+ continue;
+
+ socket_notify_service_dead(SOCKET(p));
+ }
+
+ return 0;
+}
+
static void service_set_state(Service *s, ServiceState state) {
ServiceState old_state;
assert(s);
@@ -252,6 +280,17 @@ static void service_set_state(Service *s, ServiceState state) {
state != SERVICE_STOP_POST)
s->control_command = NULL;
+ if (state == SERVICE_DEAD ||
+ state == SERVICE_STOP ||
+ state == SERVICE_STOP_SIGTERM ||
+ state == SERVICE_STOP_SIGKILL ||
+ state == SERVICE_STOP_POST ||
+ state == SERVICE_FINAL_SIGTERM ||
+ state == SERVICE_FINAL_SIGKILL ||
+ state == SERVICE_MAINTAINANCE ||
+ state == SERVICE_AUTO_RESTART)
+ service_notify_sockets(s);
+
log_debug("%s changing %s → %s", unit_id(UNIT(s)), state_string_table[old_state], state_string_table[state]);
unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);