Bug 1032694

Summary: Wrong parsing Environment= arguments
Product: Red Hat Enterprise Linux 7 Reporter: Honza Horak <hhorak>
Component: systemdAssignee: systemd-maint
Status: CLOSED NOTABUG QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: lnykryn, systemd-maint-list
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-21 12:42:55 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Honza Horak 2013-11-20 15:25:03 UTC
Description of problem:
Basically, when passing an argument in Environment=, which includes a white-space, I need to use quotes (like Environment=MYVAR1="aaa bbb"), but even then the argument is not read by systemd (seems like only '"aaa' is read, which is broken imho).

Version-Release number of selected component (if applicable):
# rpm -q systemd
systemd-207-4.el7.x86_64

How reproducible:
every-time

Steps to Reproduce:
1. # cat >/etc/systemd/system/foo.service<<EOF
[Unit]
Description=Testing environment variable setting
[Service]
Type=oneshot
Environment=MYVAR1="e f"
Environment=MYVAR2=g h
Environment=MYVAR3=i "j k"
ExecStart=/usr/local/bin/foo a "b c" d \${MYVAR1} "\${MYVAR2}" "\${MYVAR3} l"
EOF
2. # cat >/usr/local/bin/foo<<EOF
#!/bin/bash
while [ ! -z "\$1" ] ; do
    echo \$1
    shift
done
EOF
3. # chmod a+x /usr/local/bin/foo
4. # systemctl daemon-reload
5. # systemctl status foo -l
6. # systemctl start foo
7. # tail -n 20 /var/log/messages

Actual results:
Nov 20 13:29:17 unused-4-187 foo: a
Nov 20 13:29:17 unused-4-187 foo: b c
Nov 20 13:29:17 unused-4-187 foo: d
Nov 20 13:29:17 unused-4-187 foo: "e
Nov 20 13:29:17 unused-4-187 foo: g
Nov 20 13:29:17 unused-4-187 foo: i l
Nov 20 13:29:17 unused-4-187 systemd: Started Testing environment variable setting.
Nov 20 13:29:17 unused-4-187 systemd: [/etc/systemd/system/foo.service:5] Invalid environment assignment, ignoring: MYVAR1="e f"
Nov 20 13:29:17 unused-4-187 systemd: [/etc/systemd/system/foo.service:6] Invalid environment assignment, ignoring: MYVAR2=g h
Nov 20 13:29:17 unused-4-187 systemd: [/etc/systemd/system/foo.service:7] Invalid environment assignment, ignoring: MYVAR3=i "j k"
Nov 20 13:29:23 unused-4-187 systemd: [/etc/systemd/system/foo.service:5] Invalid environment assignment, ignoring: MYVAR1="e f"
Nov 20 13:29:23 unused-4-187 systemd: [/etc/systemd/system/foo.service:6] Invalid environment assignment, ignoring: MYVAR2=g h
Nov 20 13:29:23 unused-4-187 systemd: [/etc/systemd/system/foo.service:7] Invalid environment assignment, ignoring: MYVAR3=i "j k"

Expected results:
Nov 20 13:29:17 unused-4-187 foo: a
Nov 20 13:29:17 unused-4-187 foo: b c
Nov 20 13:29:17 unused-4-187 foo: d
Nov 20 13:29:17 unused-4-187 foo: e f
Nov 20 13:29:17 unused-4-187 foo: g h
Nov 20 13:29:17 unused-4-187 foo: i j k l

Additional info:
First, I thought version 204 from Fedora 19 works fine, but it seems more like it works similar, only doesn't print errors.

We can work-around this by some wrapper script, but that is ugly. systemd should have the power to pass proper arguments to daemons.

Comment 1 Lukáš Nykrýn 2013-11-21 12:42:55 UTC
If you are using spaces you should quote whole expression.

From the manpage:
If you need to assign a value containing spaces to a variable, use double quotes (") for the assignment.

Example:

Environment="VAR1=word1 word2" VAR2=word3 "VAR3=word 5 6"

So if I am not missing anything this should be closed as NOTABUG.