]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bus-util: add env var for disabling exit-on-idle
authorLennart Poettering <lennart@poettering.net>
Wed, 8 May 2024 08:38:52 +0000 (10:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Jun 2024 10:53:53 +0000 (12:53 +0200)
docs/ENVIRONMENT.md
src/shared/bus-util.c

index fd8aa0caf691657c27d98dbb4ed53f5bbe373b3a..d44e91b9739e761c2cecb8aa66e599d97c0b5cc0 100644 (file)
@@ -713,3 +713,9 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
   and `run0` invocations is turned off. Note that this environment variable has
   no effect if the background color is explicitly selected via the relevant
   `--background=` switch of the tool.
+
+`systemd-hostnamed`, `systemd-importd`, `systemd-localed`, `systemd-machined`,
+`systemd-portabled`, `systemd-timedated`:
+
+* `SYSTEMD_EXIT_ON_IDLE` – Takes a boolean. When false, the exit-on-idle logic
+  of these services is disabled, making it easier to debug them.
index 216c16f039714a7e698dbf150e8ac60da6a931d5..544494b3f80e1f4f06a8d13ebbf0095ede996303 100644 (file)
@@ -22,6 +22,7 @@
 #include "chase.h"
 #include "daemon-util.h"
 #include "data-fd-util.h"
+#include "env-util.h"
 #include "fd-util.h"
 #include "format-util.h"
 #include "memstream-util.h"
@@ -98,6 +99,19 @@ int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) {
         return 0;
 }
 
+static bool idle_allowed(void) {
+        static int allowed = -1;
+
+        if (allowed >= 0)
+                return allowed;
+
+        allowed = secure_getenv_bool("SYSTEMD_EXIT_ON_IDLE");
+        if (allowed < 0 && allowed != -ENXIO)
+                log_debug_errno(allowed, "Failed to parse $SYSTEMD_EXIT_ON_IDLE, ignoring: %m");
+
+        return allowed != 0;
+}
+
 int bus_event_loop_with_idle(
                 sd_event *e,
                 sd_bus *bus,
@@ -122,7 +136,7 @@ int bus_event_loop_with_idle(
                 if (r == SD_EVENT_FINISHED)
                         break;
 
-                if (sd_bus_pending_method_calls(bus) > 0)
+                if (!idle_allowed() || sd_bus_pending_method_calls(bus) > 0)
                         idle = false;
                 else if (check_idle)
                         idle = check_idle(userdata);