Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2018 22:14:53 +0100
From:      Jilles Tjoelker <jilles@stack.nl>
To:        Kyle Evans <kevans@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r328060 - head/usr.sbin/service
Message-ID:  <20180116211453.GA32669@stack.nl>
In-Reply-To: <201801162014.w0GKEVXL048655@repo.freebsd.org>
References:  <201801162014.w0GKEVXL048655@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180116211453.GA32669>