]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: make the default timeout configurable by environment variable 29390/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 1 Oct 2023 03:04:59 +0000 (12:04 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 1 Oct 2023 03:41:10 +0000 (12:41 +0900)
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.

docs/ENVIRONMENT.md
src/libsystemd/sd-netlink/sd-netlink.c

index 7517d15fdabe208dfe763d7fc01fd027366b1380..6396789e4a2da0af5ab77e358d50dd8c0c8a7039 100644 (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`:
 
index 6028d24c380db6eff4406fe7283c19ef9a795b6e..d3c906de1507875b3770d9fa8d86850c2426d62a 100644 (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);
 }