From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Andrew L. Moore" Newsgroups: gmane.emacs.devel Subject: Re: executable-set-magic update Date: Sat, 10 Jun 2017 15:31:04 -0400 Message-ID: References: <83ink471mf.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_AF45B3B2-91AE-4AEA-A753-728C6D4AEA48" X-Trace: blaine.gmane.org 1497123109 21795 195.159.176.226 (10 Jun 2017 19:31:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Jun 2017 19:31:49 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 10 21:31:42 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJm6n-0005Cn-Ut for ged-emacs-devel@m.gmane.org; Sat, 10 Jun 2017 21:31:42 +0200 Original-Received: from localhost ([::1]:59989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJm6t-0000Df-6E for ged-emacs-devel@m.gmane.org; Sat, 10 Jun 2017 15:31:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJm6J-0000DY-4a for emacs-devel@gnu.org; Sat, 10 Jun 2017 15:31:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJm6I-0006D5-3K for emacs-devel@gnu.org; Sat, 10 Jun 2017 15:31:11 -0400 Original-Received: from mail-yb0-x22c.google.com ([2607:f8b0:4002:c09::22c]:35229) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dJm6G-0006Cc-EF; Sat, 10 Jun 2017 15:31:08 -0400 Original-Received: by mail-yb0-x22c.google.com with SMTP id f192so21010632yba.2; Sat, 10 Jun 2017 12:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=xjtkf+d50hOS/FM21yJDWoJLH+cO2JVbqn7Az8YDiIY=; b=hP33T2UryneKo8g4k+JbJmIHDUrjtJ+y4EyusSNyWhbBHKB6yxpbJNTJiG+18iONfy yLFHC4BAwPeQ+cza+cb8YdOE7zugRVHGNhbZtAwIY/tFRfif/GyfA3JpWu4mGL38anyE VjwYKmtlkBm+5NlRzXnyb7uhVGwxuHU+bEYMlk5Rq0OC9LhAW1IUTRnO5KfAlYiUsYqD sKLWjfoBHusQWDXiBgWspCO9ttCIvURMPsFgAR/Bd7zkQsVv9GZYkesDq0ZWzT8q5rbC 7MXGYvlv2msTcdd1lXOA3eB+EhHA4qImhYiEBURBMhR2rql8VPaMeGpqVZvxg2yLelIf CPyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=xjtkf+d50hOS/FM21yJDWoJLH+cO2JVbqn7Az8YDiIY=; b=s5yw60qnyMdwWjT1jSVHdvtkg9tSaLgIs8qmrX3GgpvnxNy0/uZR46gdKGRKvKyy9Y 3YjJo37SVqcE4tD2lenoRxA9XYnXkHv43hiGcqTvQVZiqGRIppr66DEfqyZW8ibpOt9L +1BR2Saww+wWJMDL1YFhtqOGdZtguZdwBkldgSS6IafGBpVnD1QUIda+s6haFBfQz16M DapPTeHJgi9oIn2/9siMuLd/ZDoQYsqTzJRt//Z9eF0hel2Qk269+kBJzkRvFo5wzjN8 uaI3lSzlvxMzISOJTnpzeQWoY1yuTiPzVRlsVFrvbR0yHJajJAN7Qtr6qHRdm/5ypVH4 LtjA== X-Gm-Message-State: AODbwcAiXEAb4HtBAdLVpcI03pJin+OWJ0yxqVOmP8EbWdOJYDTU3TP6 1jZ17SqvWb/GG4U9jKE= X-Received: by 10.37.215.75 with SMTP id o72mr17555605ybg.213.1497123066663; Sat, 10 Jun 2017 12:31:06 -0700 (PDT) Original-Received: from ?IPv6:2605:a601:5010:3600:bd93:2a2:2cc5:500f? ([2605:a601:5010:3600:bd93:2a2:2cc5:500f]) by smtp.gmail.com with ESMTPSA id p126sm1827108ywf.30.2017.06.10.12.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Jun 2017 12:31:05 -0700 (PDT) In-Reply-To: <83ink471mf.fsf@gnu.org> X-Mailer: Apple Mail (2.3273) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c09::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215566 Archived-At: --Apple-Mail=_AF45B3B2-91AE-4AEA-A753-728C6D4AEA48 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jun 10, 2017, at 3:17 AM, Eli Zaretskii wrote: >=20 >> From: "Andrew L. Moore" >> Date: Fri, 9 Jun 2017 17:31:30 -0400 >>=20 >> lisp/progmodes/executable.el does not appear to support magic numbers = of the form `#/usr/bin/env interpreter=E2=80=99. One way to extend = support is via the attached diff which merely adds a new variable = `executable-interpreter-path-absolute=E2=80=99. Set the new variable to = nil and variable `executable-prefix=E2=80=99 to =E2=80=9C#!/usr/bin/env = =E2=80=9C. >=20 > Thanks. >=20 > Wouldn't it be more elegant (and perhaps also safer, security-wise) if > we supported the special prefix "/usr/bin/env" directly, i.e. without > feeding it via some kind of "back door", and allowing arbitrary > strings there? Attached below is a patch following your suggestions. =46rom NEWS: ** The new variable 'executable-prefix-env' affects the format of the magic number inserted by 'executable-set-magic'. If non-nil, the magic number takes the form "#!/usr/bin/env interpreter", otherwise "#!/path/to/interpreter", which is the default. +++ As you advised, if =E2=80=98executable-prefix=E2=80=99 has been = customized to=20 something other than =E2=80=9C#!=E2=80=9D or =E2=80=9C#!/usr/bin/env=E2=80= =9D, it masks the effect of =E2=80=98executable-prefix-env=E2=80=99. This behavior is not = documented. Instead, the doc string for =E2=80=98executable-prefix=E2=80=99 now adds: =E2=80=9C=E2=80=A6 Use of `executable-prefix' is deprecated in favor of = `executable-prefix-env=E2=80=99." > If your proposal is accepted, I think at least its documentation parts > should be improved: >=20 >> +(defcustom executable-interpreter-path-absolute t >> + "If non-nil, `executable-set-magic' uses the interpreter's >> +absolute path. Otherwise, it's basename is used." >=20 > This doc string leaves out the important stuff: the reason why the > variable is introduced and how it should be used. I think the doc > string should be more helpful by explicitly describing its intended > usage. New name and new definition: (defcustom executable-prefix-env nil "If non-nil, the magic number inserted by function = `executable-set-magic' takes the form \"#!/usr/bin/env interpreter\", otherwise \"#!/path/to/interpreter\"." :version "26.1" :type 'boolean :group 'executable) >=20 >> + :version "26.0" >=20 > Emacs never releases N.0 versions, so this should be "26.1=E2=80=9D. Okay. >=20 >> @@ -220,6 +226,9 @@ executable-set-magic >> (and argument (string< "" argument) " ") >> argument)) >=20 > The doc string of executable-set-magic should mention the variable you > introduce. Done - although just by changing a reference from = =E2=80=98executable-prefix=E2=80=99 to =E2=80=98executable-prefix-env=E2=80=99 - i.e., =E2=80=98executable-prefix= =E2=80=99 is now not referenced in its deprecated role. > Finally, there should be a NEWS entry about this new facility. Thank you! -AM --Apple-Mail=_AF45B3B2-91AE-4AEA-A753-728C6D4AEA48 Content-Disposition: attachment; filename=lisp_progmodes_executable.el.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="lisp_progmodes_executable.el.diff" Content-Transfer-Encoding: quoted-printable diff=20--git=20a/etc/NEWS=20b/etc/NEWS=0Aindex=207972511f7a..a81949efa6=20= 100644=0A---=20a/etc/NEWS=0A+++=20b/etc/NEWS=0A@@=20-94,6=20+94,12=20@@=20= required=20capabilities=20are=20found=20in=20terminfo.=20=20See=20the=20= FAQ=20node=0A=20=0C=0A=20*=20Changes=20in=20Emacs=2026.1=0A=0A+**=20The=20= new=20variable=20'executable-prefix-env'=20affects=20the=20format=20of=0A= +the=20magic=20number=20inserted=20by=20'executable-set-magic'.=20If=20= non-nil,=0A+the=20magic=20number=20takes=20the=20form=20"#!/usr/bin/env=20= interpreter",=0A+otherwise=20"#!/path/to/interpreter",=20which=20is=20= the=20default.=0A+=0A++++=0A=20**=20The=20variable=20'emacs-version'=20= no=20longer=20includes=20the=20build=20number.=0A=20This=20is=20now=20= stored=20separately=20in=20a=20new=20variable,=20'emacs-build-number'.=0A= =0Adiff=20--git=20a/lisp/progmodes/executable.el=20= b/lisp/progmodes/executable.el=0Aindex=20da148bd39a..5decc92e27=20100644=0A= ---=20a/lisp/progmodes/executable.el=0A+++=20= b/lisp/progmodes/executable.el=0A@@=20-83,13=20+83,20=20@@=20= executable-magicless-file-regexp=0A=20=20=20:type=20'regexp=0A=20=20=20= :group=20'executable)=0A=0A-=0A=20(defcustom=20executable-prefix=20"#!"=0A= -=20=20"Interpreter=20magic=20number=20prefix=20inserted=20when=20there=20= was=20no=20magic=20number."=0A-=20=20:version=20"24.3"=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20;=20"#!=20"=20->=20"#!"=0A= +=20=20"Interpreter=20magic=20number=20prefix=20inserted=20when=20there=20= was=20no=20magic=20number.=0A+Use=20of=20`executable-prefix'=20is=20= deprecated=20in=20favor=20of=20`executable-prefix-env'."=0A+=20=20= :version=20"26.1"=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20;=20deprecated=0A=20=20=20:type=20'string=0A=20=20=20:group=20= 'executable)=0A=0A+(defcustom=20executable-prefix-env=20nil=0A+=20=20"If=20= non-nil,=20the=20magic=20number=20inserted=20by=20function=20= `executable-set-magic'=0A+takes=20the=20form=20\"#!/usr/bin/env=20= interpreter\",=20otherwise=0A+\"#!/path/to/interpreter\"."=0A+=20=20= :version=20"26.1"=0A+=20=20:type=20'boolean=0A+=20=20:group=20= 'executable)=0A=0A=20(defcustom=20executable-chmod=2073=0A=20=20=20= "After=20saving,=20if=20the=20file=20is=20not=20executable,=20set=20this=20= mode.=0A@@=20-199,7=20+206,7=20@@=20executable-interpret=0A=20(defun=20= executable-set-magic=20(interpreter=20&optional=20argument=0A=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20no-query-flag=20insert-flag)=0A=20= =20=20"Set=20this=20buffer's=20interpreter=20to=20INTERPRETER=20with=20= optional=20ARGUMENT.=0A-The=20variables=20= `executable-magicless-file-regexp',=20`executable-prefix',=0A+The=20= variables=20`executable-magicless-file-regexp',=20= `executable-prefix-env',=0A=20`executable-insert',=20`executable-query'=20= and=20`executable-chmod'=20control=0A=20when=20and=20how=20magic=20= numbers=20are=20inserted=20or=20replaced=20and=20scripts=20made=0A=20= executable."=0A@@=20-220,6=20+227,14=20@@=20executable-set-magic=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (and=20argument=20(string<=20""=20argument)=20"=20")=0A=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20argument))=0A= =0A+=20=20;;=20For=20backward=20compatibilty,=20allow=20= `executable-prefix-env'=20to=20be=0A+=20=20;;=20overriden=20by=20custom=20= `executable-prefix'.=0A+=20=20(if=20(string-match=20"#!\\([=20= \t]*/usr/bin/env[=20\t]*\\)?$"=20executable-prefix)=0A+=20=20=20=20=20=20= (if=20executable-prefix-env=0A+=20=20=20=20=20=20=20=20=20=20(setq=20= argument=20(concat=20"/usr/bin/env=20"=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (file-name-nondirectory=20argument))))=0A+=20=20=20=20(setq=20argument=20= (concat=20(substring=20executable-prefix=202)=20argument)))=0A+=0A=20=20=20= (or=20buffer-read-only=0A=20=20=20=20=20=20=20(if=20buffer-file-name=0A=20= =20=20=20=20=20=20=20=20=20=20(string-match=20= executable-magicless-file-regexp=0A@@=20-241,15=20+256,13=20@@=20= executable-set-magic=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20;;=20Make=20buffer=20visible=20before=20= question.=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(switch-to-buffer=20(current-buffer))=0A=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (y-or-n-p=20(format-message=0A-=20=20=20=20=20=20=20=20=20=20"Replace=20= magic=20number=20by=20`%s%s'?=20"=0A-=20=20=20=20=20=20=20=20=20=20= executable-prefix=20argument))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= "Replace=20magic=20number=20by=20`#!%s'?=20"=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20argument))))=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20(progn=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(replace-match=20argument=20t=20t=20nil=201)=0A-=20= =20=20=20=20=20=20=20=20(message=20"Magic=20number=20changed=20to=20= `%s'"=0A-=09=09=09=09(concat=20executable-prefix=20argument)))))=0A-=20=20= =20(insert=20executable-prefix=20argument=20?\n)=0A-=20=20=20(message=20= "Magic=20number=20changed=20to=20`%s'"=0A-=20=20=20=20=20(concat=20= executable-prefix=20argument)))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(message=20"Magic=20number=20changed=20= to=20`#!%s'"=20argument))))=0A+=20=20=20=20=20=20=20=20=20=20(insert=20= "#!"=20argument=20?\n)=0A+=20=20=20=20=20=20=20=20=20=20(message=20= "Magic=20number=20changed=20to=20`#!%s'"=20argument))))=0A=20=20=20= interpreter)=0A= --Apple-Mail=_AF45B3B2-91AE-4AEA-A753-728C6D4AEA48--