devd problem with 9-stable

Warren Block wblock at wonkity.com
Fri Jun 15 20:09:49 UTC 2012


On Fri, 15 Jun 2012, Oliver Fromme wrote:

> > When the event is seen:
> > Executing 'devnum=`echo ugen0.6 | sed -e 's/^ugen//'` && echo devnum:  > /tmp/example && echo cdev: ugen0.6 >> /tmp/example'
> >
> > $devnum never gets a value, the contents of /tmp/example are:
> >    devnum:
> >    cdev: ugen0.6
> >
> > Trying $() instead of backticks makes it worse:
> > Executing 'devnum=$(echo $cdev | sed -e 's/^ugen//') && echo devnum: $devnum > /tmp/example && echo cdev: $cdev >> /tmp/example'
>
> Unfortunately, the manual page does not explain how the action
> strings are parsed exactly.  I guess the problem is not the
> backticks but the fact that the parser tries to expand $devnum
> as a devd variable, so the shell never sees it.  This also
> explains why using $() makes things worse.

It should be pointed out that this is a regression from 8.x.

> You can try to prepend a backslash, i.e. echo \$devnum.  This
> isn't documented, but then again, using backslashes to continue
> strings that span multiple lines isn't documented either.

devd has already expanded variables by then:
Executing 'devnum=ugen0.6 && echo devnum: \ > /tmp/example && echo cdev: ugen0.6 >> /tmp/example'

It does seem to work to use the bracketed form:

action "devnum=`echo $cdev | sed -e 's/^ugen//'` && echo ${devnum} > /tmp/example";

> In case the sed command still doesn't work, alternatively you
> can use shell substring processing instead (this is also more
> efficient because the shell doesn't have to create a pipe and
> fork a sed process):
>
>   action "devnum=$cdev; devnum=\${devnum##ugen}; echo \$devnum > /tmp/foo"
>
> Or even:
>
>   action "devnum=$cdev; echo \${devnum##ugen} > /tmp/foo"

I like that, and it does work without the backslash.
   action "devnum=$cdev ; echo ${devnum##ugen} > /tmp/example";
   cat /tmp/example
   0.6

I started to enter a PR, but got confused partway through.  The problem 
here is that devd is expanding variables unknown to it in action strings 
(unless the bracket notation is used), and replacing them with empty 
strings.  Agreed?


More information about the freebsd-stable mailing list