From owner-svn-src-head@freebsd.org Tue Oct 13 05:19:01 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 255AB434D9D; Tue, 13 Oct 2020 05:19:01 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4C9P3T09ZPz49c2; Tue, 13 Oct 2020 05:19:01 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DD71E181E6; Tue, 13 Oct 2020 05:19:00 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09D5J0Wv058915; Tue, 13 Oct 2020 05:19:00 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09D5J0lU058914; Tue, 13 Oct 2020 05:19:00 GMT (envelope-from imp@FreeBSD.org) Message-Id: <202010130519.09D5J0lU058914@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Tue, 13 Oct 2020 05:19:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366661 - head/sbin/devd X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sbin/devd X-SVN-Commit-Revision: 366661 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 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: Tue, 13 Oct 2020 05:19:01 -0000 Author: imp Date: Tue Oct 13 05:19:00 2020 New Revision: 366661 URL: https://svnweb.freebsd.org/changeset/base/366661 Log: Document the rather suprising behavior with ' inside action rules. To prevent issues with odd shell characters appearing in, a surprising shell feature is used. Document it and a workaround for it. Differential Revision: https://reviews.freebsd.org/D26723 Modified: head/sbin/devd/devd.conf.5 Modified: head/sbin/devd/devd.conf.5 ============================================================================== --- head/sbin/devd/devd.conf.5 Tue Oct 13 04:37:57 2020 (r366660) +++ head/sbin/devd/devd.conf.5 Tue Oct 13 05:19:00 2020 (r366661) @@ -40,7 +40,7 @@ .\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS .\" SOFTWARE. .\" -.Dd August 18, 2020 +.Dd October 12, 2020 .Dt DEVD.CONF 5 .Os .Sh NAME @@ -662,6 +662,59 @@ For example: // is a new comment, even though it is logically // part of the previous comment. .Ed +.Ss Notes on Variable Expansion +To prevent issues with special shell characters, the following happens for each +variable +.Ic $foo . +.Bl -enum +.It +The characters +.Dq $' +are inserted. +.It +The string +.Dq $foo +is removed. +.It +The value of the +.Ic foo +variable is inserted into the buffer with all single quote characters +prefixed by a backslash. +.El +.Pp +See +.Xr sh 1 +for what this construct means. +It is safe in all context, except one: inside single quotes. +If foo=meta and bar=var, then a rule like the following: +.Bd -literal -offset indent -compact +action "echo '$foo $bar'"; +.Ed +will be presented to the shell via +.Xr system 3 +as +.Bd -literal -offset indent -compact +echo '$'meta' $'var'' +.Ed +which produces the following output: +.Bd -literal -offset indent -compact +$meta $var +.Ed +as its output. +This is an unanticipated result. +A future version of this software will change this behavior. +Users are discouraged from using single quotes inside +.Ic action +value without due care. +.Pp +The above should be written as +.Bd -literal -offset indent -compact +action "echo $foo' '$bar" +.Ed +to produce a single argument to echo. +Given the above expansion, juxtaposing bare variables with +single quote expressions will produce the right output, +regardless of the value of the variable. .Sh FILES .Bl -tag -width ".Pa /etc/devd.conf" -compact .It Pa /etc/devd.conf @@ -733,6 +786,9 @@ detach 0 { The installed .Pa /etc/devd.conf has many additional examples. +.Sh BUGS +The variable expansion's interaction with single quotes is +suboptimal and surprising. .Sh SEE ALSO .Xr cam 4 , .Xr coretemp 4 ,