]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: read $SYSTEMD_PROC_CMDLINE if set when looking for the kernel cmdline
authorLennart Poettering <lennart@poettering.net>
Mon, 12 Dec 2016 12:42:06 +0000 (13:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 21 Dec 2016 18:07:55 +0000 (19:07 +0100)
if we want to parse the kernel command line, let's check the
$SYSTEMD_PROC_CMDLINE environment variable first. This is useful for debugging
purposes.

ENVIRONMENT.md
src/basic/proc-cmdline.c

index 4ace45751f710d97ae357da426de7af038d717bb..1ad2addfeefd2bbcdb1608d51f19390c7d86177b 100644 (file)
@@ -21,6 +21,11 @@ All tools:
 * `$SD_EVENT_PROFILE_DELAYS=1` — if set, the sd-event event loop implementation
   will print latency information at runtime.
 
+* `$SYSTEMD_PROC_CMDLINE` — if set, may contain a string that is used as kernel
+  command line instead of the actual one readable from /proc/cmdline. This is
+  useful for debugging, in order to test generators and other code against
+  specific kernel command lines.
+
 systemctl:
 
 * `$SYSTEMCTL_FORCE_BUS=1` — if set, do not connect to PID1's private D-Bus
index 8297a222b76f93e154b7bdf33896271feaf12d99..98c94ed5e26eeb7c626ffcca5c46cd35485d8dc4 100644 (file)
 #include "virt.h"
 
 int proc_cmdline(char **ret) {
+        const char *e;
         assert(ret);
 
+        /* For testing purposes it is sometimes useful to be able to override what we consider /proc/cmdline to be */
+        e = secure_getenv("SYSTEMD_PROC_CMDLINE");
+        if (e) {
+                char *m;
+
+                m = strdup(e);
+                if (!m)
+                        return -ENOMEM;
+
+                *ret = m;
+                return 0;
+        }
+
         if (detect_container() > 0)
                 return get_process_cmdline(1, 0, false, ret);
         else