mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
Merge pull request #33045 from poettering/exit-on-idle-tweaks
bus-util: honour new env var $SYSTEMD_ALLOW_IDLE to permit turning off exit-on-idle logic in hostnamed, timedated, …
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
@@ -134,6 +148,8 @@ int bus_event_loop_with_idle(
|
||||
return r;
|
||||
|
||||
if (r == 0 && !exiting && idle) {
|
||||
log_debug("Idle for %s, exiting.", FORMAT_TIMESPAN(timeout, 1));
|
||||
|
||||
/* Inform the service manager that we are going down, so that it will queue all
|
||||
* further start requests, instead of assuming we are still running. */
|
||||
(void) sd_notify(false, NOTIFY_STOPPING);
|
||||
|
||||
Reference in New Issue
Block a user