svn commit: r328060 - head/usr.sbin/service

Jilles Tjoelker jilles at stack.nl
Tue Jan 16 21:14:57 UTC 2018


On Tue, Jan 16, 2018 at 08:14:31PM +0000, Kyle Evans wrote:
> Author: kevans
> Date: Tue Jan 16 20:14:31 2018
> New Revision: 328060
> URL: https://svnweb.freebsd.org/changeset/base/328060

> Log:
>   service(8): Reset OPTIND properly now that we're parsing args twice

>   r328032 introduced a second round of argument parsing to proxy the request
>   through to a jail as needed, but failed to reset OPTIND before getting to
>   the second round of parsing to allow other flags to be set.

>   Reported by:	Oleg Ginzburg <olevole olevole ru>

> Modified:
>   head/usr.sbin/service/service.sh

> Modified: head/usr.sbin/service/service.sh
> ==============================================================================
> --- head/usr.sbin/service/service.sh	Tue Jan 16 20:02:07 2018	(r328059)
> +++ head/usr.sbin/service/service.sh	Tue Jan 16 20:14:31 2018	(r328060)
> @@ -79,6 +79,7 @@ if [ -n "$JAIL" ]; then
>  	exit $?
>  fi
>  
> +OPTIND=1
>  while getopts ${accepted_argstr} COMMAND_LINE_ARGUMENT ; do
>  	case "${COMMAND_LINE_ARGUMENT}" in
>  	e)	ENABLED=eopt ;;

Hi,

Although this solves the immediate problem of all existing options
becoming no-ops, the new -j option still behaves strangely if it is not
used with "-j" and the jail name as the first two arguments, since the
shift commands will shift away other arguments.

One way to fix this avoids depending on the exact options known by the
jailed service(8) and accepts that the -j option must be first (either
-j JAIL as two arguments or -jJAIL as one argument). This parsing would
be open-coded and there would be only one getopts loop.

Another way to fix this allows using the -j option as any other option.
This would also use one getopts loop and reconstruct a command line for
the jailed service(8) based on the variables like ENABLED (the values
for set options can be changed to simplify this since the rest of the
script only cares about non-empty or not).

-- 
Jilles Tjoelker


More information about the svn-src-all mailing list