Bug 199850 - [patch] /usr/sbin/service -e fails if /sbin isn't in PATH
Summary: [patch] /usr/sbin/service -e fails if /sbin isn't in PATH
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Keywords: patch
Depends on:
Reported: 2015-05-01 20:32 UTC by Glyn Grinstead
Modified: 2015-07-07 16:57 UTC (History)
2 users (show)

See Also:

Patch service.sh replacing rcorder with /sbin/rcorder (656 bytes, patch)
2015-05-01 20:32 UTC, Glyn Grinstead
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Glyn Grinstead 2015-05-01 20:32:25 UTC
Created attachment 156221 [details]
Patch service.sh replacing rcorder with /sbin/rcorder

The /usr/sbin/service script uses rcorder without specifying the path. If called from an environment without /sbin in the path the -e option (and presumably -r and -R) will fail. Adding /sbin/ to the two references to rcorder will avoid this. Use of /sbin/sysctl within service already uses this form.

Attached patch against Revision 268098 (stable) which should also apply to 268773 (head).
Comment 1 Mateusz Guzik freebsd_committer 2015-05-01 20:54:57 UTC
Well that is a bug, but you are dealing with only part of the real problem.

The tool should work with empty PATH.
Comment 2 Glyn Grinstead 2015-05-01 22:16:11 UTC
(In reply to Mateusz Guzik from comment #1)

That seems to require either adding a PATH statement to the top or patching both service and rc.subr (find_local_scripts_new) to include the fully qualified path to grep. 

rc.subr has other functions which appear to assume a path will have been set, e.g. mount_critical_filesystems uses 'mount' not '/sbin/mount'. Would it be sensible to attempt to make all of rc.subr safe to use without a path or should it be left as the risk of breaking something is too great? My first pass at this found about 30 instances to consider.
Comment 3 Mateusz Guzik freebsd_committer 2015-05-01 23:26:28 UTC
Setting PATH in service should be fine.

I don't recommend playing with rc.subr. That's a can of worms and I'm definitely not up to reviewing patches to that file (but someone else might).
Comment 4 Jilles Tjoelker freebsd_committer 2015-05-03 20:34:32 UTC
Although this patch is not directly wrong, I'm not sure about the use of the bin vs sbin distinction. In most cases, both bin and sbin are in PATH, and there seems little benefit in removing sbin.

Where does the PATH without /sbin come from, in your case? Perhaps we should add /sbin and /usr/sbin there instead of trying to make the world work without /sbin and /usr/sbin in PATH. One such definition is _PATH_DEFPATH in include/paths.h.
Comment 5 Glen Barber freebsd_committer 2015-07-07 16:57:01 UTC
Is there anything to do with this PR?