By popular request, execute rc.d scripts in the same environment

as they are at boot time.

Original concept submitted by:	ume
This commit is contained in:
Doug Barton 2009-12-21 20:32:04 +00:00
parent f2632c3b48
commit ee55fdb8fa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=200809
2 changed files with 21 additions and 4 deletions

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd December 19, 2009
.Dd December 20, 2009
.Dt service 8
.Os
.Sh NAME
@ -44,7 +44,10 @@ The
.Nm
command is an easy interface to the rc.d system.
Its primary purpose is to start and stop services provided
by the rc.d scripts, however it can also be used to list
by the rc.d scripts.
When used for this purpose it will set the same restricted
environment that is in use at boot time (see below).
It can also be used to list
the scripts using various criteria.
.Pp
The options are as follows:
@ -78,6 +81,20 @@ above, but list all of the files, not just what is enabled.
.It Fl v
Be slightly more verbose
.El
.Sh ENVIRONMENT
When used to run rc.d scripts the
.Nm
command sets
.Ev HOME
to
.Pa /
and
.Ev PATH
to
.Pa /sbin:/bin:/usr/sbin:/usr/bin
which is how they are set in
.Pa /etc/rc
at boot time.
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES

View File

@ -106,11 +106,11 @@ else
exit 1
fi
cd /
for dir in /etc/rc.d $local_startup; do
if [ -x "$dir/$script" ]; then
[ -n "$VERBOSE" ] && echo "$script is located in $dir"
$dir/$script $*
exit $?
exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin $dir/$script $*
fi
done