Page MenuHomeFreeBSD
Authored By
dor
Jan 17 2018, 4:49 PM
Size
2 KB
Referenced Files
None
Subscribers
None

service-3.diff

diff --git a/usr.sbin/service/service.sh b/usr.sbin/service/service.sh
index a7e75d30933..c005c383532 100755
--- a/usr.sbin/service/service.sh
+++ b/usr.sbin/service/service.sh
@@ -53,19 +53,19 @@ accepted_argstr='j:ehlrRv'
# If running outside of a jail, check if -j was used.
if [ `/sbin/sysctl -n security.jail.jailed` -eq 0 ]; then
- # Only deal with the -j option here. If found, JAIL is set to OPTARG
- # and OPTIND is left untouched. This is fine as we only parse getopts
- # once in this scenario.
- # The whole $* will be passed along to jexec(8) unmodified.
+ # Only deal with the -j option here. If found, JAIL is set to
+ # OPTARG and OPTIND is left untouched. This is fine as we only
+ # parse getopts once in this scenario.
while getopts ${accepted_argstr} COMMAND_LINE_ARGUMENT ; do
case "${COMMAND_LINE_ARGUMENT}" in
j) JAIL="${OPTARG}" ;;
+ *) ;;
esac
done
- # If -j was provided, then we pass everthing along to jexec(8) and
- # execute service(8) within the named JAIL. Provided that the jail
- # actually exists, as checked by jls(8).
+ # If -j was provided, then we're going to execute service(8) within the
+ # named JAIL using jexec(8). Provided that the jail actually exists, as
+ # checked by jls(8).
# We do this so that if the jail does exist, we can then return the
# exit code of jexec(8) and it should be the exit code of whatever ran
# inside the jail.
@@ -79,7 +79,18 @@ if [ `/sbin/sysctl -n security.jail.jailed` -eq 0 ]; then
exit 1
fi
- /usr/sbin/jexec -l "$JAIL" /usr/sbin/service $*
+ # We don't want to pass the -j argument into the jail.
+ # Get the prefix and the suffix of the command line, ready for
+ # restructuring. This removes the `-j JAIL` from the args.
+ jail_str="-j ${JAIL}"
+ args="${@}"
+ args_prefix="${args%${jail_str}*}"
+ args_suffix="${args#*${jail_str}}"
+
+ # Reset $@ before passing it to jexec(8).
+ set -- ${args_prefix} ${args_suffix}
+
+ echo /usr/sbin/jexec -l "$JAIL" /usr/sbin/service $@
exit $?
fi
@@ -88,11 +99,8 @@ if [ `/sbin/sysctl -n security.jail.jailed` -eq 0 ]; then
OPTIND=1
fi
-# If we get to this point with a -j argument, execution is happening inside a
-# jail. The -j argument is not used beyond this point.
while getopts ${accepted_argstr} COMMAND_LINE_ARGUMENT ; do
case "${COMMAND_LINE_ARGUMENT}" in
- j) JAIL=jopt ;;
e) ENABLED=eopt ;;
h) usage ; exit 0 ;;
l) LIST=lopt ;;

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1259792
Default Alt Text
service-3.diff (2 KB)

Event Timeline