From: Lennart Poettering Date: Wed, 8 May 2024 08:38:52 +0000 (+0200) Subject: bus-util: add env var for disabling exit-on-idle X-Git-Tag: v257-rc1~1176^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afc55a5eff7806044b7fee841ff7d07e23078187;p=thirdparty%2Fsystemd.git bus-util: add env var for disabling exit-on-idle --- diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index fd8aa0caf69..d44e91b9739 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -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. diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 216c16f0397..544494b3f80 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -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);