From owner-svn-src-head@freebsd.org Fri Mar 24 07:38:34 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69735D1B3B6; Fri, 24 Mar 2017 07:38:34 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from smtp-out-no.shaw.ca (smtp-out-no.shaw.ca [64.59.134.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 07767693; Fri, 24 Mar 2017 07:38:33 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from spqr.komquats.com ([96.50.22.10]) by shaw.ca with SMTP id rJnlcgsVwUiwTrJnmcEbjk; Fri, 24 Mar 2017 01:38:26 -0600 X-Authority-Analysis: v=2.2 cv=Qo0u5R6d c=1 sm=1 tr=0 a=jvE2nwUzI0ECrNeyr98KWA==:117 a=jvE2nwUzI0ECrNeyr98KWA==:17 a=8nJEP1OIZ-IA:10 a=6Iz7jQTuP9IA:10 a=VxmjJ2MpAAAA:8 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=A280ri9A0HIyo5GazOIA:9 a=wPNLvfGTeEIA:10 a=7gXAzLPJhVmCkEl4_tsf:22 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTPS id AF50FA9; Fri, 24 Mar 2017 00:38:24 -0700 (PDT) Received: from slippy (localhost [127.0.0.1]) by slippy.cwsent.com (8.15.2/8.15.2) with ESMTP id v2O7cOhb003757; Fri, 24 Mar 2017 00:38:24 -0700 (PDT) (envelope-from Cy.Schubert@cschubert.com) Message-Id: <201703240738.v2O7cOhb003757@slippy.cwsent.com> X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.6 Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Ian Lepore , Roman Divacky , Warner Losh , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r315773 - head/sbin/devd In-Reply-To: Message from Cy Schubert of "Thu, 23 Mar 2017 20:40:14 -0700." <201703240340.v2O3eEKh002609@slippy.cwsent.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Date: Fri, 24 Mar 2017 00:38:24 -0700 X-CMAE-Envelope: MS4wfHUcyUCUeo7ZOknILkGat6fHIMwDvDCL+hoipfo4XSn3lG19d1M0/PvQdIVe9H1V2IQBwls+KYVtXBL4nxZWO1l/GVLkSSReD/0Yv992tOK8oMFJzSEk b4DzafHi4vZrMzK4C6ooUa/1aCFUP8eMLI+9DSpmuj4oNlunSZOstRydNxRRQ0lymhGIyIxXG6ScWG5FbxNNqA2fYm782S7DwhwEQ1yd1qlukOe2/xNsfIxx LaCTLOlfKg5kG16EpJESTaHfGuqFqAFNHKT+9aR1v1hKx5bU2MWXFM8m7Pa6SDg1JGVufr9KAeGyzsYpA1SBJn6CnoJp4z1WE17/rt+dgSE= X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Mar 2017 07:38:34 -0000 In message <201703240340.v2O3eEKh002609@slippy.cwsent.com>, Cy Schubert writes: > In message <1490297671.58015.102.camel@freebsd.org>, Ian Lepore writes: > > On Thu, 2017-03-23 at 19:58 +0100, Roman Divacky wrote: > > > On Thu, Mar 23, 2017 at 02:36:51AM +0000, Warner Losh wrote: > > > > > > > > Author: imp > > > > Date: Thu Mar 23 02:36:51 2017 > > > > New Revision: 315773 > > > > URL: https://svnweb.freebsd.org/changeset/base/315773 > > > > > > > > Log: > > > >   Implement quote escaping. String values may now contain " if you > > > >   it is preceded by \. > > > >    > > > >   foo="I \"like\" C++" > > > >    > > > >   gives the value 'I "like" C++' to the variable 'foo'. If a > > > > character > > > >   other than " follows the \, both the \ and that character are > > > > passed > > > >   through. > > > >    > > > >   Differential Revision: https://reviews.freebsd.org/D6286 > > > >   Sponsored by: Netflix > > > > > > > > Modified: > > > >   head/sbin/devd/devd.cc > > > >   head/sbin/devd/devd.hh > > > > > > > > Modified: head/sbin/devd/devd.cc > > > > =================================================================== > > > > =========== > > > > --- head/sbin/devd/devd.cc Thu Mar 23 02:33:27 2017 ( > > > > r315772) > > > > +++ head/sbin/devd/devd.cc Thu Mar 23 02:36:51 2017 ( > > > > r315773) > > > > @@ -411,6 +411,32 @@ var_list::is_set(const string &var) cons > > > >   return (_vars.find(var) != _vars.end()); > > > >  } > > > >   > > > > +/** fix_value > > > > + * > > > > + * Removes quoted characters that have made it this far. \" are > > > > + * converted to ". For all other characters, both \ and following > > > > + * character. So the string 'fre\:\"' is translated to 'fred\:"'. > > > > + */ > > > > +const std::string & > > > > +var_list::fix_value(const std::string &val) const > > > > +{ > > > > + char *tmp, *dst; > > > > + const char *src; > > > > + std::string *rv; > > > > + > > > > + dst = tmp = new char[val.length()]; > > > > + src = val.c_str(); > > > > + while (*src) { > > > > + if (*src == '\\' && src[1] == '"') > > > > + src++; > > > > + else > > > > + *dst++ = *src++; > > > > + } > > > > + rv = new string(tmp); > > > > + delete tmp; > > > > + return *rv; > > > > +} > > > Can the temporary char[] be stack allocated? Also, when returning a > > > reference to > > > a heap allocated string who is responsible for freeing it? Perhaps > > > you can just > > > return std::string and let the compiler optimize it? > > > > > > Roman > > > > > > > Returning a reference to a new'd string is not good. > > > > IMO, the implementation of the function should take into account the > > idea that embedded escaped quotes are rare.  The function should be > > optimized for readability and the common case of simply copying the > > string unmodified, something like: > > > > > > std::string > > var_list::fix_value(const std::string &val) const > > { > > std::string rv(val); > > std::string::size_type pos(0); > > > > while ((pos = rv.find("\\\"", pos)) != rv.npos) { > > rv.erase(pos, 1); > > } > > return (rv); > > } > > This revision caused devd a little gas. It failed to start moused for usb > attached mice (ums0 & ums1) to my latpop and nut failed to recognize my USB > connected UPS on a server. downstairs due to a permission issue which nut > provides a devd.conf file with: > > chgrp uucp /dev/$cdev; chmod g+rw /dev/$cdev Hi Ian, Your example above fixes the problem. -- Cheers, Cy Schubert FreeBSD UNIX: Web: http://www.FreeBSD.org The need of the many outweighs the greed of the few.