Bug 239692 - rc: Environment variables set via ${name}_env are not passed to ${rc_arg}_cmd (e.g., start_cmd)
Summary: rc: Environment variables set via ${name}_env are not passed to ${rc_arg}_cmd...
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 11.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Mateusz Piotrowski
URL: https://reviews.freebsd.org/D21228
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-07 12:12 UTC by Mateusz Piotrowski
Modified: 2019-09-06 03:33 UTC (History)
5 users (show)

See Also:
koobs: mfc-stable11?
koobs: mfc-stable12?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mateusz Piotrowski freebsd_committer 2019-08-07 12:12:40 UTC
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.
Comment 1 Mateusz Piotrowski freebsd_committer 2019-08-12 15:29:43 UTC
I've posted an attempt at addressing this issue: https://reviews.freebsd.org/D21228
Comment 2 commit-hook freebsd_committer 2019-09-05 14:53:07 UTC
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
Comment 3 Kubilay Kocak freebsd_committer freebsd_triage 2019-09-06 03:33:01 UTC
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