Page MenuHomeFreeBSD

rc: Honor ${name}_env when a custom *_cmd is define (e.g., start_cmd)
AcceptedPublic

Authored by 0mp on Mon, Aug 12, 3:26 PM.

Details

Reviewers
bcr
Group Reviewers
manpages
Summary
rc: Honor ${name}_env when a custom *_cmd is define (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 are never set if the service
is started via the ${rc_arg}_cmd variable (for example start_cmd).

PR:		239692
Test Plan
  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"
  1. Run sysrc teststartcmd_env="TESTVARIABLE=foo" to modify rc.conf.
  1. Run service teststartcmd onestart and observe that TESTVARIABLE is not in the output.
  1. 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"
  1. Run sysrc testcommand_env="TESTVARIABLE=foo" to modify rc.conf.
  1. Run service testcommand onestart and observe that TESTVARIABLE is in the output this time.

With the patch, both outputs should contain TESTVARIABLE=foo.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 25805
Build 24377: arc lint + arc unit

Event Timeline

0mp created this revision.Mon, Aug 12, 3:26 PM
0mp edited the summary of this revision. (Show Details)Mon, Aug 12, 3:29 PM
0mp added subscribers: kevans, dteske, jilles, cem.
bcr added a subscriber: bcr.Mon, Aug 12, 3:51 PM

Minor man page fix.

share/man/man8/rc.subr.8
573

s/the/then/
(You can also leave out the "the" completely)

0mp updated this revision to Diff 60677.Mon, Aug 12, 3:53 PM

Fix a typo (thanks @bcr)

0mp marked an inline comment as done.Mon, Aug 12, 3:53 PM
bcr accepted this revision.Mon, Aug 12, 4:33 PM

OK from manpages.
Nice feature, BTW.

This revision is now accepted and ready to land.Mon, Aug 12, 4:33 PM
0mp added a comment.Tue, Aug 13, 12:50 PM

Otherwise, we may just document that ${name}_env only works if the ${rc_arg}_cmd is not defined.