From owner-svn-src-all@freebsd.org Fri Mar 24 03:40:25 2017 Return-Path: Delivered-To: svn-src-all@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 CF531D193D0; Fri, 24 Mar 2017 03:40:25 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from smtp-out-so.shaw.ca (smtp-out-so.shaw.ca [64.59.136.138]) (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 70AB0E2A; Fri, 24 Mar 2017 03:40:25 +0000 (UTC) (envelope-from cy.schubert@komquats.com) Received: from spqr.komquats.com ([96.50.22.10]) by shaw.ca with SMTP id rG5Hca0AUsa1krG5IcFYWZ; Thu, 23 Mar 2017 21:40:18 -0600 X-Authority-Analysis: v=2.2 cv=W+NIbVek c=1 sm=1 tr=0 a=jvE2nwUzI0ECrNeyr98KWA==:117 a=jvE2nwUzI0ECrNeyr98KWA==:17 a=8nJEP1OIZ-IA:10 a=6Iz7jQTuP9IA:10 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=3_mYSEdGjyZgiJlhfz4A:9 a=wPNLvfGTeEIA:10 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 6C57F10F; Thu, 23 Mar 2017 20:40:15 -0700 (PDT) Received: from slippy (localhost [127.0.0.1]) by slippy.cwsent.com (8.15.2/8.15.2) with ESMTP id v2O3eEKh002609; Thu, 23 Mar 2017 20:40:14 -0700 (PDT) (envelope-from Cy.Schubert@cschubert.com) Message-Id: <201703240340.v2O3eEKh002609@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 cc: 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 Ian Lepore of "Thu, 23 Mar 2017 13:34:31 -0600." <1490297671.58015.102.camel@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Date: Thu, 23 Mar 2017 20:40:14 -0700 X-CMAE-Envelope: MS4wfE959jd2f9lc0/Kn5dU3Zzmqzi/NSODN4I9z9PksHoxhZvYtM1uhKXAiprxWbOVuQu8jMxCnJ+5MvXaik2vr5fqAcBLUNcvpTb/H+bPyU7eP/sarur1w AAQg+WbN2vccYyrjI98nzYPeKazY/wSIf+EfrguWfIxBuhLZTVJGxbthYL6scbLgUWvaH4q62XrF4KlyjOSo0Jfe3eIRMnL5tEQxmpH79/FnL2FNbd7VBAPX sFm7XDfuAjMjQ9t2M4I705eJEK9lBOZltSD5e6F/PDjpc0yqWzs26wQd7E54Uec7hs6l96Pqkj2n6VviwHsQOgLupZaTfsuj5+G2GlNZ6kQ= X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Mar 2017 03:40:25 -0000 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 -- Cheers, Cy Schubert FreeBSD UNIX: Web: http://www.FreeBSD.org The need of the many outweighs the greed of the few.