]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevd: implement the full Type=notify-reload protocol
authorLennart Poettering <lennart@poettering.net>
Mon, 2 Jan 2023 16:21:16 +0000 (17:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Jan 2023 17:28:38 +0000 (18:28 +0100)
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.

src/udev/udevd.c
units/systemd-udevd.service.in

index 28b76bfbab2c19b4805fa0435ad39d736fb27b19..6fb0305e0934e90005850c4c6a99824b495f2d4c 100644 (file)
@@ -32,6 +32,7 @@
 #include "cgroup-setup.h"
 #include "cgroup-util.h"
 #include "cpu-set-util.h"
+#include "daemon-util.h"
 #include "dev-setup.h"
 #include "device-monitor-private.h"
 #include "device-private.h"
@@ -330,9 +331,7 @@ static void manager_exit(Manager *manager) {
 
         manager->exit = true;
 
-        sd_notify(false,
-                  "STOPPING=1\n"
-                  "STATUS=Starting shutdown...");
+        (void) sd_notify(/* unset= */ false, NOTIFY_STOPPING);
 
         /* close sources of new events and discard buffered events */
         manager->ctrl = udev_ctrl_unref(manager->ctrl);
@@ -350,7 +349,7 @@ static void manager_exit(Manager *manager) {
 static void notify_ready(void) {
         int r;
 
-        r = sd_notifyf(false,
+        r = sd_notifyf(/* unset= */ false,
                        "READY=1\n"
                        "STATUS=Processing with %u children at max", arg_children_max);
         if (r < 0)
@@ -375,23 +374,33 @@ static void manager_reload(Manager *manager, bool force) {
         mac_selinux_maybe_reload();
 
         /* Nothing changed. It is not necessary to reload. */
-        if (!udev_rules_should_reload(manager->rules) && !udev_builtin_should_reload())
-                return;
+        if (!udev_rules_should_reload(manager->rules) && !udev_builtin_should_reload()) {
 
-        sd_notify(false,
-                  "RELOADING=1\n"
-                  "STATUS=Flushing configuration...");
+                if (!force)
+                        return;
 
-        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();
-        udev_builtin_init();
+                manager_kill_workers(manager, false);
 
-        r = udev_rules_load(&rules, arg_resolve_name_timing);
-        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);
+                udev_builtin_exit();
+                udev_builtin_init();
+
+                r = udev_rules_load(&rules, arg_resolve_name_timing);
+                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();
 }
@@ -1985,9 +1994,7 @@ static int main_loop(Manager *manager) {
         if (r < 0)
                 log_error_errno(r, "Event loop failed: %m");
 
-        sd_notify(false,
-                  "STOPPING=1\n"
-                  "STATUS=Shutting down...");
+        (void) sd_notify(/* unset= */ false, NOTIFY_STOPPING);
         return r;
 }
 
index e9dbe85ef4ad06f3f1317183651b5490f7d0d080..dfc2a0e341b0d7b4cd43ef5494725e1b8044efe0 100644 (file)
@@ -18,14 +18,13 @@ ConditionPathIsReadWrite=/sys
 [Service]
 CapabilityBoundingSet=~CAP_SYS_TIME CAP_WAKE_ALARM
 Delegate=pids
-Type=notify
+Type=notify-reload
 # Note that udev will reset the value internally for its workers
 OOMScoreAdjust=-1000
 Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
 Restart=always
 RestartSec=0
 ExecStart={{ROOTLIBEXECDIR}}/systemd-udevd
-ExecReload=udevadm control --reload --timeout 0
 KillMode=mixed
 TasksMax=infinity
 PrivateMounts=yes