Here are the steps to reproduce: 1. Save the following script as /usr/local/etc/rc.d/teststartcmd and make it executable: ``` #!/bin/sh # PROVIDE: teststartcmd . /etc/rc.subr name=teststartcmd load_rc_config $name start_cmd="teststartcmd_start" teststartcmd_start() { env } run_rc_command "$1" ``` 2. Run `sysrc teststartcmd_env="TESTVARIABLE=foo"` to modify rc.conf. 3. Run `service teststartcmd onestart` and observe that TESTVARIABLE is not in the output. 4. Save the following script as /usr/local/etc/rc.d/testcommand and make it executable: ``` #!/bin/sh # PROVIDE: testcommand . /etc/rc.subr name=testcommand load_rc_config $name command="/usr/bin/env" run_rc_command "$1" ``` 5. Run `sysrc testcommand_env="TESTVARIABLE=foo"` to modify rc.conf. 6. Run `service testcommand onestart` and observe that TESTVARIABLE is in the output this time.
I've posted an attempt at addressing this issue: https://reviews.freebsd.org/D21228
A commit references this bug: Author: 0mp Date: Thu Sep 5 14:52:23 UTC 2019 New revision: 351863 URL: https://svnweb.freebsd.org/changeset/base/351863 Log: rc: Honor ${name}_env when a custom *_cmd is defined (e.g., start_cmd) A user may set ${name}_env variable in rc.conf(5) in order to set additional environment variables for a service command. Unfortunately, at the moment this variable is only honored when the command is specified via the command variable. Those additional environment variables coming from ${name}_env are never set if the service is started via the ${rc_arg}_cmd variable (for example start_cmd). PR: 239692 Reviewed by: bcr, jilles Approved by: src (jilles) Differential Revision: https://reviews.freebsd.org/D21228 Changes: head/libexec/rc/rc.subr head/share/man/man8/rc.subr.8
Re-open for MFC (requested earlier), given the desirability of having this behaviour consistent across supported FreeBSD versions and the limited scope of the change. Would be great to add this to RELNOTES too
A commit references this bug: Author: 0mp Date: Tue Nov 10 10:19:55 UTC 2020 New revision: 367550 URL: https://svnweb.freebsd.org/changeset/base/367550 Log: MFC r351863: rc: Honor ${name}_env when a custom *_cmd is defined (e.g., start_cmd) A user may set ${name}_env variable in rc.conf(5) in order to set additional environment variables for a service command. Unfortunately, at the moment this variable is only honored when the command is specified via the command variable. Those additional environment variables coming from ${name}_env are never set if the service is started via the ${rc_arg}_cmd variable (for example start_cmd). PR: 239692 Reviewed by: bcr, jilles Approved by: src (jilles) Requested by: koobs Changes: _U stable/12/ stable/12/libexec/rc/rc.subr stable/12/share/man/man8/rc.subr.8
A commit references this bug: Author: 0mp Date: Tue Nov 10 10:40:45 UTC 2020 New revision: 367551 URL: https://svnweb.freebsd.org/changeset/base/367551 Log: Add an entry for r351863 (honoring ${name}_env in rc(8) scripts) PR: 239692 Requested by: koobs Changes: head/RELNOTES
Done. I'm not MFCing the change to 11-STABLE as there seem to be some conflicts which make my Subversion client hang.
Thanks Mateusz! ^Triage: Track (current) explicit non-merge to stable/11 @Kyle Do you have cycles to check the MFC for stable/11 ? Consistency would be nice for this one.
(In reply to Kubilay Kocak from comment #7) Unfortunately not, but almost certainly the conflict is that the file doesn't exist as written in stable/11 so the diff would not apply cleanly. To be honest, if it's not something we'd issue an EN for, there's not much point in trying to keep stable/11 consistent anymore -- there will not be another release from that branch, so most folks will not see the difference anyways.
(In reply to Kyle Evans from comment #8) Roger, just asking :) Thanks!