From owner-freebsd-stable@FreeBSD.ORG Fri Jun 15 18:23:45 2012 Return-Path: Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 621CA1065672 for ; Fri, 15 Jun 2012 18:23:45 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [212.17.241.230]) by mx1.freebsd.org (Postfix) with ESMTP id B71A98FC16 for ; Fri, 15 Jun 2012 18:23:44 +0000 (UTC) Received: from lurza.secnetix.de (localhost [127.0.0.1]) by lurza.secnetix.de (8.14.3/8.14.3) with ESMTP id q5FINRWC084094; Fri, 15 Jun 2012 20:23:43 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.14.3/8.14.3/Submit) id q5FINRFT084093; Fri, 15 Jun 2012 20:23:27 +0200 (CEST) (envelope-from olli) Date: Fri, 15 Jun 2012 20:23:27 +0200 (CEST) Message-Id: <201206151823.q5FINRFT084093@lurza.secnetix.de> From: Oliver Fromme To: freebsd-stable@FreeBSD.ORG, wblock@wonkity.com In-Reply-To: X-Newsgroups: list.freebsd-stable User-Agent: tin/1.9.6-20101126 ("Burnside") (UNIX) (FreeBSD/6.4-PRERELEASE-20080904 (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (lurza.secnetix.de [127.0.0.1]); Fri, 15 Jun 2012 20:23:43 +0200 (CEST) Cc: Subject: Re: devd problem with 9-stable X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jun 2012 18:23:45 -0000 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