From: Lennart Poettering Date: Wed, 10 Jul 2013 19:10:53 +0000 (+0200) Subject: core: send out "Reloading" signal before and after doing a full reload/reexec of... X-Git-Tag: v206~160 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=71445ae75b0e9954d141e5f0ee97803b406ea332 core: send out "Reloading" signal before and after doing a full reload/reexec of PID 1 Since we'll unload all units/job during a reload, and then readd them it is really useful for clients to be aware of this phase hence sent a signal out before and after. This signal is called "Reloading" (despite the fact that it is also sent out during reexecution, which we consider a special case in this context) and has one boolean parameter which is true for the signal sent before the reload, and false for the signal after the reload. The UnitRemoved/JobRremoved and UnitNew/JobNew due to the reloading are guranteed to be between the pair of Reloading messages. --- diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 742f6bbd8..d7604b1ab 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -276,7 +276,10 @@ " \n" \ " \n" \ " " \ - " \n" + " \n" \ + " \n" \ + " \n" \ + " " #define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL \ " \n" \ diff --git a/src/core/dbus.c b/src/core/dbus.c index c1bf25c69..aa3d93bf0 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -1451,7 +1451,7 @@ void bus_broadcast_finished( usec_t userspace_usec, usec_t total_usec) { - DBusMessage *message; + _cleanup_dbus_message_unref_ DBusMessage *message = NULL; assert(m); @@ -1471,18 +1471,42 @@ void bus_broadcast_finished( DBUS_TYPE_UINT64, &total_usec, DBUS_TYPE_INVALID)) { log_oom(); - goto finish; + return; } if (bus_broadcast(m, message) < 0) { log_oom(); - goto finish; + return; } +} -finish: - if (message) - dbus_message_unref(message); +void bus_broadcast_reloading(Manager *m, bool active) { + + _cleanup_dbus_message_unref_ DBusMessage *message = NULL; + dbus_bool_t b = active; + + assert(m); + + message = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "Reloading"); + if (!message) { + log_oom(); + return; + } + + assert_cc(sizeof(usec_t) == sizeof(uint64_t)); + if (!dbus_message_append_args(message, + DBUS_TYPE_BOOLEAN, &b, + DBUS_TYPE_INVALID)) { + log_oom(); + return; + } + + + if (bus_broadcast(m, message) < 0) { + log_oom(); + return; + } } Set *bus_acquire_subscribed(Manager *m, DBusConnection *c) { diff --git a/src/core/dbus.h b/src/core/dbus.h index b5c28c6ab..6500cd745 100644 --- a/src/core/dbus.h +++ b/src/core/dbus.h @@ -43,6 +43,7 @@ bool bus_connection_has_subscriber(Manager *m, DBusConnection *c); int bus_fdset_add_all(Manager *m, FDSet *fds); void bus_broadcast_finished(Manager *m, usec_t firmware_usec, usec_t loader_usec, usec_t kernel_usec, usec_t initrd_usec, usec_t userspace_usec, usec_t total_usec); +void bus_broadcast_reloading(Manager *m, bool active); Set *bus_acquire_subscribed(Manager *m, DBusConnection *c); diff --git a/src/core/main.c b/src/core/main.c index 1d188e0bf..efc5791bb 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1055,15 +1055,16 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching assert(_f); assert(_fds); - /* Make sure nothing is really destructed when we shut down */ - m->n_reloading ++; - r = manager_open_serialization(m, &f); if (r < 0) { log_error("Failed to create serialization file: %s", strerror(-r)); goto fail; } + /* Make sure nothing is really destructed when we shut down */ + m->n_reloading ++; + bus_broadcast_reloading(m, true); + fds = fdset_new(); if (!fds) { r = -ENOMEM; diff --git a/src/core/manager.c b/src/core/manager.c index 51f03de09..2e98181b3 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -864,6 +864,11 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { if (serialization) { assert(m->n_reloading > 0); m->n_reloading --; + + /* Let's wait for the UnitNew/JobNew messages being + * sent, before we notify that the reload is + * finished */ + m->send_reloading_done = true; } return r; @@ -1163,6 +1168,13 @@ unsigned manager_dispatch_dbus_queue(Manager *m) { } m->dispatching_dbus_queue = false; + + if (m->send_reloading_done) { + m->send_reloading_done = false; + + bus_broadcast_reloading(m, false); + } + return n; } @@ -2238,6 +2250,7 @@ int manager_reload(Manager *m) { return r; m->n_reloading ++; + bus_broadcast_reloading(m, true); fds = fdset_new(); if (!fds) { @@ -2297,6 +2310,8 @@ int manager_reload(Manager *m) { assert(m->n_reloading > 0); m->n_reloading--; + m->send_reloading_done = true; + finish: if (f) fclose(f); diff --git a/src/core/manager.h b/src/core/manager.h index 31da04e47..6d5241497 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -195,6 +195,8 @@ struct Manager { int32_t conn_data_slot; int32_t subscribed_data_slot; + bool send_reloading_done; + uint32_t current_job_id; uint32_t default_unit_job_id;