Bug 663358

Summary: environment variables from /etc/sysconfig/* does not work
Product: [Fedora] Fedora Reporter: Michal Hlavinka <mhlavink>
Component: systemdAssignee: Lennart Poettering <lpoetter>
Status: CLOSED DUPLICATE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: lpoetter, mcepl, metherid, mschmidt, notting, plautrba
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-01-03 08:05:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Michal Hlavinka 2010-12-15 14:42:52 UTC
Description of problem:
We are trying to create service file for smartd for which some configuration is present in /etc/sysconfig/smartmontools :

smartd_opts="-q never"

however systemd does not handle it correctly:

ExecStart=/usr/sbin/smartd -n $smartd_opts

is always interpreted as:
argv[1]=-n
argv[2]=-q never

instead of expected:
argv[1]=-n
argv[2]=-q
argv[3]=never

man page contains:
 Also $FOO may appear as separate word on the command line in which case the variable is replaced by its value split at whitespaces.

but it behaves differently


Version-Release number of selected component (if applicable):
systemd-15-1.fc15.x86_64

How reproducible:
always

Steps to Reproduce:
1)
/lib/systemd/system/smartd.service:
""""""""""""""
[Unit]
Description=Self Monitoring and Reporting Technology (SMART) Daemon
After=syslog.target

[Service]
EnvironmentFile=/etc/sysconfig/smartmontools
ExecStart=/usr/sbin/smartd.sh -n $smartd_opts

[Install]
WantedBy=multi-user.target
"""""""""""""

2) /usr/sbin/smartd.sh
"""""""""""""
#!/bin/bash
sleep 3600
"""""""""""""

3) chmod +x /usr/sbin/smartd.sh
4) systemctl --system daemon-reload
5) systemctl start smartd.service
6) get pid from systemctl status smartd.service
7) check /proc/<pid>/cmdline

Actual results:
no '\0' between "-q" and "never"
cat /proc/<pid>/cmdline shows /bin/bash/usr/sbin/smartde-n-q never because there is ' ' instead of '\0'

Expected results:
'\0' between "-q" and "never"
cat /proc/<pid>/cmdline would show /bin/bash/usr/sbin/smartde-n-qnever

additional comments:
I don't know why ${smartd_opts} should behave differently than $smartd_opts, because it's misleading. These variables looks like shell variables and from shell's pov both are interpreted the same way. Anyway, ${var} does not work too, because $var is interpreted as "-q never" and ${var} as "\"-q never\""
if ${smartd_opts} is used instead of $smartd_opts

Comment 1 Matěj Cepl 2010-12-29 11:29:10 UTC
Michal, why is this not a duplicate of bug 661291?

Comment 2 Michal Hlavinka 2011-01-03 08:05:47 UTC

*** This bug has been marked as a duplicate of bug 661291 ***