Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jun 2012 20:23:27 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-stable@FreeBSD.ORG, wblock@wonkity.com
Subject:   Re: devd problem with 9-stable
Message-ID:  <201206151823.q5FINRFT084093@lurza.secnetix.de>
In-Reply-To: <alpine.BSF.2.00.1206151053360.26334@wonkity.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Warren Block wrote:
 > Well, it did work with an attach event.  Progress: the event is seen 
 > with a notify event.  However, something is not right with the execution 
 > of backticks in the action string:
 > 
 > notify 20 {
 >          match "subsystem" "DEVICE";
 >          match "type" "ATTACH";
 >          match "cdev" "ugen[0-9]+.[0-9]+";
 >          match "vendor" "0x04b8";
 >          match "product" "0x010a";
 >          action "devnum=`echo $cdev | sed -e 's/^ugen//'` && \
 >                  echo $devnum > /tmp/example && \
 >                  echo $cdev >> /tmp/example";
 > };
 > 
 > 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.

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.

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"

Best regards
   Oliver


-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"I made up the term 'object-oriented', and I can tell you
I didn't have C++ in mind."
        -- Alan Kay, OOPSLA '97



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