sd-netlink: make the default timeout configurable by environment variable

On normal systems, triggering a timeout should be a bug in code or
configuration error, so I do not think we should extend the default
timeout. Also, we should not introduce a 'first class' configuration
option about that. But, making it configurable may be useful for cases
such that "an extremely highly utilized system (lots of OOM kills,
very high CPU utilization, etc)".

Closes #25441.
This commit is contained in:
Yu Watanabe 2023-10-01 12:04:59 +09:00
parent f5c615889a
commit 52afaee74b
2 changed files with 25 additions and 3 deletions

View file

@ -121,7 +121,10 @@ All tools:
kernel supports this.
* `$SYSTEMD_ENABLE_LOG_CONTEXT` — if set, extra fields will always be logged to
the journal instead of only when logging in debug mode.
the journal instead of only when logging in debug mode.
* `$SYSTEMD_NETLINK_DEFAULT_TIMEOUT` — specifies the default timeout of waiting
replies for netlink messages from the kernel. Defaults to 25 seconds.
`systemctl`:

View file

@ -378,8 +378,27 @@ int sd_netlink_process(sd_netlink *nl, sd_netlink_message **ret) {
}
static usec_t timespan_to_timestamp(usec_t usec) {
if (usec == 0)
usec = NETLINK_DEFAULT_TIMEOUT_USEC;
static bool default_timeout_set = false;
static usec_t default_timeout;
int r;
if (usec == 0) {
if (!default_timeout_set) {
const char *e;
default_timeout_set = true;
default_timeout = NETLINK_DEFAULT_TIMEOUT_USEC;
e = getenv("SYSTEMD_NETLINK_DEFAULT_TIMEOUT");
if (e) {
r = parse_sec(e, &default_timeout);
if (r < 0)
log_debug_errno(r, "sd-netlink: Failed to parse $SYSTEMD_NETLINK_DEFAULT_TIMEOUT environment variable, ignoring: %m");
}
}
usec = default_timeout;
}
return usec_add(now(CLOCK_MONOTONIC), usec);
}