udevd: implement the full Type=notify-reload protocol

We are basically already there, just need to add MONOTONIC_USEC= to the
RELOADING=1 message, and make sure the message is generated in really
all cases.
This commit is contained in:
Lennart Poettering 2023-01-02 17:21:16 +01:00
parent 0e07cdb0e7
commit f84331539d
2 changed files with 28 additions and 22 deletions

View file

@ -32,6 +32,7 @@
#include "cgroup-setup.h" #include "cgroup-setup.h"
#include "cgroup-util.h" #include "cgroup-util.h"
#include "cpu-set-util.h" #include "cpu-set-util.h"
#include "daemon-util.h"
#include "dev-setup.h" #include "dev-setup.h"
#include "device-monitor-private.h" #include "device-monitor-private.h"
#include "device-private.h" #include "device-private.h"
@ -330,9 +331,7 @@ static void manager_exit(Manager *manager) {
manager->exit = true; manager->exit = true;
sd_notify(false, (void) sd_notify(/* unset= */ false, NOTIFY_STOPPING);
"STOPPING=1\n"
"STATUS=Starting shutdown...");
/* close sources of new events and discard buffered events */ /* close sources of new events and discard buffered events */
manager->ctrl = udev_ctrl_unref(manager->ctrl); manager->ctrl = udev_ctrl_unref(manager->ctrl);
@ -350,7 +349,7 @@ static void manager_exit(Manager *manager) {
static void notify_ready(void) { static void notify_ready(void) {
int r; int r;
r = sd_notifyf(false, r = sd_notifyf(/* unset= */ false,
"READY=1\n" "READY=1\n"
"STATUS=Processing with %u children at max", arg_children_max); "STATUS=Processing with %u children at max", arg_children_max);
if (r < 0) if (r < 0)
@ -375,23 +374,33 @@ static void manager_reload(Manager *manager, bool force) {
mac_selinux_maybe_reload(); mac_selinux_maybe_reload();
/* Nothing changed. It is not necessary to reload. */ /* Nothing changed. It is not necessary to reload. */
if (!udev_rules_should_reload(manager->rules) && !udev_builtin_should_reload()) if (!udev_rules_should_reload(manager->rules) && !udev_builtin_should_reload()) {
return;
sd_notify(false, if (!force)
"RELOADING=1\n" return;
"STATUS=Flushing configuration...");
manager_kill_workers(manager, false); /* If we eat this up, then tell our service manager to just continue */
(void) sd_notifyf(/* unset= */ false,
"RELOADING=1\n"
"STATUS=Skipping configuration reloading, nothing changed.\n"
"MONOTONIC_USEC=" USEC_FMT, now(CLOCK_MONOTONIC));
} else {
(void) sd_notifyf(/* unset= */ false,
"RELOADING=1\n"
"STATUS=Flushing configuration...\n"
"MONOTONIC_USEC=" USEC_FMT, now(CLOCK_MONOTONIC));
udev_builtin_exit(); manager_kill_workers(manager, false);
udev_builtin_init();
r = udev_rules_load(&rules, arg_resolve_name_timing); udev_builtin_exit();
if (r < 0) udev_builtin_init();
log_warning_errno(r, "Failed to read udev rules, using the previously loaded rules, ignoring: %m");
else r = udev_rules_load(&rules, arg_resolve_name_timing);
udev_rules_free_and_replace(manager->rules, rules); if (r < 0)
log_warning_errno(r, "Failed to read udev rules, using the previously loaded rules, ignoring: %m");
else
udev_rules_free_and_replace(manager->rules, rules);
}
notify_ready(); notify_ready();
} }
@ -1985,9 +1994,7 @@ static int main_loop(Manager *manager) {
if (r < 0) if (r < 0)
log_error_errno(r, "Event loop failed: %m"); log_error_errno(r, "Event loop failed: %m");
sd_notify(false, (void) sd_notify(/* unset= */ false, NOTIFY_STOPPING);
"STOPPING=1\n"
"STATUS=Shutting down...");
return r; return r;
} }

View file

@ -18,14 +18,13 @@ ConditionPathIsReadWrite=/sys
[Service] [Service]
CapabilityBoundingSet=~CAP_SYS_TIME CAP_WAKE_ALARM CapabilityBoundingSet=~CAP_SYS_TIME CAP_WAKE_ALARM
Delegate=pids Delegate=pids
Type=notify Type=notify-reload
# Note that udev will reset the value internally for its workers # Note that udev will reset the value internally for its workers
OOMScoreAdjust=-1000 OOMScoreAdjust=-1000
Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
Restart=always Restart=always
RestartSec=0 RestartSec=0
ExecStart={{ROOTLIBEXECDIR}}/systemd-udevd ExecStart={{ROOTLIBEXECDIR}}/systemd-udevd
ExecReload=udevadm control --reload --timeout 0
KillMode=mixed KillMode=mixed
TasksMax=infinity TasksMax=infinity
PrivateMounts=yes PrivateMounts=yes