From: Yu Watanabe Date: Sun, 1 Oct 2023 03:04:59 +0000 (+0900) Subject: sd-netlink: make the default timeout configurable by environment variable X-Git-Tag: v255-rc1~353^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52afaee74b40a765b8118393bff92717f78d0a51;p=thirdparty%2Fsystemd.git 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. --- diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 7517d15fdab..6396789e4a2 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -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`: diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index 6028d24c380..d3c906de150 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -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); }