tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: proposed /etc/rc.d/staticroute change to allow variables



On Tue, Oct 18, 2011 at 3:49 PM, Alan Barrett <apb%cequrux.com@localhost> wrote:
> On Mon, 17 Oct 2011, David Brownlee wrote:
>>
>> Since ! has a well defined meaning in ifconfig.if, maybe use a '$' or
>> similar prefix to mean eval?
>
> '!' already means 'eval this line' in ifconfig.if.  It was my suggestion to
> have it mean more or less the same thing in route.conf.
>
> I see now that /etc/rc.d/network eval's each '!' line from ifconfig.if in a
> separate subshell, whereas the proposal for /etc/rc.d/staticroute is to eval
> all linesin the same subshell (so that variables set in one line may affect
> commands in a subsequent line).  I think it would make more sense for both
> rc.d/network and rc.d/staticroute to perform all the evals in the same
> subshell.

I misunderstood what Alan was suggesting. So, staticroute_doit should be this:

staticroute_doit() {
       if [ -s /etc/route.conf ]; then
               echo "$1 static routes."
               while read args; do
                       [ -z "$args" ] && continue
                       case "$args" in
                       "#"*)
                               ;;
                       "+"*)
                               [ $2 = "add" ] && eval ${args#*+}
                               ;;
                       "-"*)
                               [ $2 = "delete" ] && eval ${args#*-}
                               ;;
                       "!"*)
                               eval "${args#*!}"
                               ;;
                       *)
                               eval route -q $2 -$args
                               ;;
                       esac
               done < /etc/route.conf
       fi
}

Which allows always setting variables whether you're adding or
deleting without having to repeat it, and separately allows an
unmarked line to do proper variable substitution.

From other conversation, adding eval to "route -q $2 -$args" seems
uncontroversial, because if it has any effect, it is very likely your
route.conf wasn't doing what you expected.

And Alan should correct me if I've misunderstood again.

Thanks,
Tracy


Home | Main Index | Thread Index | Old Index