bus-util: add env var for disabling exit-on-idle

This commit is contained in:
Lennart Poettering
2024-05-08 10:38:52 +02:00
parent 21f51d877f
commit afc55a5eff
2 changed files with 21 additions and 1 deletions

View 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.

View 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);