Page MenuHomeFreeBSD

D13952.id38143.diff
No OneTemporary

D13952.id38143.diff

Index: usr.sbin/service/service.sh
===================================================================
--- usr.sbin/service/service.sh
+++ usr.sbin/service/service.sh
@@ -49,50 +49,44 @@
echo ''
}
-accepted_argstr='jehlrRv'
-
-# Only deal with the -j option here. If found, JAIL is set and the opt and
-# arg are shifted out. OPTIND is left untouched. We strip the -j option out
-# here because we'll be proxying this invocation through to the jail via
-# jls(8) instead of handling it ourselves.
-while getopts ${accepted_argstr} COMMAND_LINE_ARGUMENT ; do
+while getopts 'j:ehlrRv' COMMAND_LINE_ARGUMENT ; do
case "${COMMAND_LINE_ARGUMENT}" in
- j) JAIL="$2" ; shift ; shift ;;
+ j) JAIL="${OPTARG}" ;;
+ e) ENABLED=eopt ;;
+ h) usage ; exit 0 ;;
+ l) LIST=lopt ;;
+ r) RCORDER=ropt ;;
+ R) RESTART=Ropt ;;
+ v) VERBOSE=vopt ;;
+ *) usage ; exit 1 ;;
esac
done
+shift $(( $OPTIND - 1 ))
-# If -j was provided, then we pass everthing along to the jexec command
-# and execute `service` within the named JAIL. Provided that the jail
-# actually exists, as checked by `jls`.
-# We do this so that if the jail does exist, we can then return the exit
-# code of `jexec` and it should be the exit code of whatever ran in the jail.
-# There is a race condition here in that the jail might exist at `jls` time
-# and be gone by `jexec` time, but it shouldn't be a big deal.
-if [ -n "$JAIL" ]; then
+# If we're not jailed and we were passed -j
+if [ `/sbin/sysctl -n security.jail.jailed` -eq 0 ] && [ -n "${JAIL}" ]; then
+ # Check that the requested jail actually exists.
/usr/sbin/jls -j "$JAIL" 2>/dev/null >/dev/null
if [ $? -ne 0 ]; then
echo "Jail '$JAIL' does not exist."
exit 1
fi
- /usr/sbin/jexec -l "$JAIL" /usr/sbin/service $*
+ # We need to rebuild the command line before passing it on.
+ # We do not send the -j argument into the jail.
+ args=""
+ [ -n "${ENABLED}" ] && args="${args} -e"
+ [ -n "${LIST}" ] && args="${args} -l"
+ [ -n "${RCORDER}" ] && args="${args} -r"
+ [ -n "${RESTART}" ] && args="${args} -R"
+ [ -n "${VERBOSE}" ] && args="${args} -v"
+
+ # Call jexec(8) with the rebuild args and any positional args that
+ # were left in $@
+ /usr/sbin/jexec -l "$JAIL" /usr/sbin/service $args $@
exit $?
fi
-OPTIND=1
-while getopts ${accepted_argstr} COMMAND_LINE_ARGUMENT ; do
- case "${COMMAND_LINE_ARGUMENT}" in
- e) ENABLED=eopt ;;
- h) usage ; exit 0 ;;
- l) LIST=lopt ;;
- r) RCORDER=ropt ;;
- R) RESTART=Ropt ;;
- v) VERBOSE=vopt ;;
- *) usage ; exit 1 ;;
- esac
-done
-shift $(( $OPTIND - 1 ))
-
if [ -n "$RESTART" ]; then
skip="-s nostart"
if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 7, 5:59 AM (10 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31014357
Default Alt Text
D13952.id38143.diff (2 KB)

Event Timeline