[PATCH] systemd: Add systemd.setenv for /proc/cmdline parsing.

William Douglas william.douglas at intel.com
Mon Feb 6 16:18:56 PST 2012

Check for systemd.setenv when parsing /proc/cmdline.
ex: systemd.setenv=PATH=/opt/bin

Signed-off-by: William Douglas <william.douglas at intel.com>
 src/main.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/main.c b/src/main.c
index 5c28a6c..16fff05 100644
--- a/src/main.c
+++ b/src/main.c
@@ -319,6 +319,19 @@ static int parse_proc_cmdline_word(const char *word) {
                         log_warning("Failed to parse default standard
error switch %s, Ignoring.", word + 31);
                         arg_default_std_error = r;
+        } else if (startswith(word, "systemd.setenv=")) {
+                char *eq;
+                int r;
+                if (!(eq = strchr(word + 15, '=')))
+                        log_warning("Failed to parse setenv switch %s.
Ignoring.", word + 15);
+                else {
+                        *eq = 0;
+                        r = setenv(word + 15, eq + 1, 1);
+                        if (r)
+                                log_warning("Failed setenv call with %s.
Ignoring", strerror(-r));
+                        *eq = '=';
+                }
         } else if (startswith(word, "systemd.sysv_console=")) {
                 int r;

Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>From 0f981111c5efa3dc0d96f323e9c799ca5d9a6e7e Mon Sep 17 00:00:00 2001=
</div><div>From: William Douglas &lt;<a href=3D"mailto:william.douglas at inte=
l.com">william.douglas at intel.com</a>&gt;</div><div>Date: Mon, 6 Feb 2012 16=
:18:56 -0800</div>
<div>Subject: [PATCH] systemd: Add systemd.setenv for /proc/cmdline parsing=
.</div><div><br></div><div>Check for systemd.setenv when parsing /proc/cmdl=
ine.</div><div>ex: systemd.setenv=3DPATH=3D/opt/bin</div><div><br></div><di=
Signed-off-by: William Douglas &lt;<a href=3D"mailto:william.douglas at intel.=
com">william.douglas at intel.com</a>&gt;</div><div>---</div><div>=A0src/main.=
c | =A0 13 +++++++++++++</div><div>=A01 files changed, 13 insertions(+), 0 =
<div><br></div><div>diff --git a/src/main.c b/src/main.c</div><div>index 5c=
28a6c..16fff05 100644</div><div>--- a/src/main.c</div><div>+++ b/src/main.c=
</div><div>@@ -319,6 +319,19 @@ static int parse_proc_cmdline_word(const ch=
ar *word) {</div>
<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log_warning(&quot;F=
ailed to parse default standard error switch %s, Ignoring.&quot;, word + 31=
);</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else</div><div>=A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0arg_default_std_error =3D r;</div>
<div>+ =A0 =A0 =A0 =A0} else if (startswith(word, &quot;systemd.setenv=3D&q=
uot;)) {</div><div>+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0char *eq;</div><div>+ =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int r;</div><div>+</div><div>+ =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0if (!(eq =3D strchr(word + 15, &#39;=3D&#39;)))</div>
<div>+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log_warning(&quot;Fai=
led to parse setenv switch %s. Ignoring.&quot;, word + 15);</div><div>+ =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0else {</div><div>+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0*eq =3D 0;</div><div>+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0r =3D setenv(word + 15, eq + 1, 1);</div>
<div>+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (r)</div><div>+ =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log_warning(=
&quot;Failed setenv call with %s. Ignoring&quot;, strerror(-r));</div><div>=
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*eq =3D &#39;=3D&#39;;</di=
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}</div><div>=A0#ifdef HAVE_SYSV_COMPAT</di=
v><div>=A0 =A0 =A0 =A0 =A0} else if (startswith(word, &quot;systemd.sysv_co=
nsole=3D&quot;)) {</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int r;</div=


More information about the systemd-devel mailing list