On Thu, Oct 09, 2014 at 09:02:14PM +0200, Patrik Lundin wrote:
> Hello,
>
> While working on rcctl(8) support for ansible I have run into a
> situation I am not sure how to deal with.
>
> Basically, if the user has supplied arguments we append
> "flags <whatever the user requested>" and this works good.
>
> If the user supplied no arguments, but there currently are flags set
> in rc.conf.local we append an empty "flags" argument to reset the
> default value.
>
> The later behaviour causes a problem when modifying special services
> like pf. When disabling pf a "pf=NO" is added to rc.conf.local as
> expected, but when trying to enable it again it will fail because the
> ansible module notices that flags are currently set ("NO"), and tries to
> call "rcctl enable pf flags" which fails:
Why is ansible appending flags in the first place when no flags are configured?
> ---
> # rcctl enable pf flags
> rcctl: "pf" is a special variable, cannot set "flags"
> ---
>
> I am not sure how to deal with this properly since I do not want to
> duplicate the _special_services variable in the module.
>
> A possible solution to this would be to relax the flags check in rcctl,
> so it only cares if there are actual flags supplied. See diff below for
> a suggestion on how to deal with this which seems to work.
>
> If I am going about this the wrong way any pointers are greatly
> appreciated of course!
>
> Regards,
> Patrik Lundin
>
> Index: rcctl.sh
> ===================================================================
> RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
> retrieving revision 1.38
> diff -u -p -u -r1.38 rcctl.sh
> --- rcctl.sh 1 Sep 2014 18:01:55 -0000 1.38
> +++ rcctl.sh 9 Oct 2014 18:17:56 -0000
> @@ -274,10 +274,14 @@ fi
> if [ -n "$flag" ]; then
> if [ "$flag" = "flags" ]; then
> if [ "$action" != "enable" ]; then
> - _rc_err "${0##*/}: \"flags\" can only be set with
> \"enable\""
> + if [ -n "$4" ]; then
> + _rc_err "${0##*/}: \"flags\" can only be set
> with \"enable\""
> + fi
> fi
> if svc_is_special $svc; then
> - _rc_err "${0##*/}: \"$svc\" is a special variable,
> cannot set \"flags\""
> + if [ -n "$4" ]; then
> + _rc_err "${0##*/}: \"$svc\" is a special
> variable, cannot set \"flags\""
> + fi
> fi
> if [ "$4" = "NO" ]; then
> _rc_err "${0##*/}: \"flags NO\" contradicts \"enable\""
>
--
Antoine