From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4899 invoked from network); 9 May 2020 15:36:33 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 9 May 2020 15:36:33 -0000 Received: (qmail 25398 invoked by alias); 9 May 2020 15:36:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45799 Received: (qmail 2105 invoked by uid 1010); 9 May 2020 15:36:27 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25801. spamassassin: 3.4.4. Clear:RC:0(66.111.4.29):SA:0(-1.1/5.0):. Processed in 5.171896 secs); 09 May 2020 15:36:27 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrkeehgdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkjghfofggtgfgsehtqhdttdertdejnecuhfhrohhmpeffrghnihgv lhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqeenuc ggtffrrghtthgvrhhnpefhveetgfegtdekvddvjeegkefgieekteejvdfffeeiueeugeek hefhuddvgeeiffenucffohhmrghinhepohhpvghnghhrohhuphdrohhrghenucfkphepud dtledrieeirdduhedrvdefleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Date: Sat, 9 May 2020 15:35:42 +0000 From: Daniel Shahaf To: Martijn Dekker Cc: Zsh hackers list Subject: Re: [PATCH] return status 126 for execution failures other than 'not found' Message-ID: <20200509153542.1061b041@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Martijn Dekker wrote on Fri, 08 May 2020 21:36 +0100: > When the argument list to an external command is too long (exceeds=20 > ARG_MAX), zsh returns exit status 127. This is incorrect because status=20 > 127 means the command was not found. >=20 > POSIX says in "2.8.2 Exit Status for Commands": > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html= #tag_18_08_02 > | If a command is not found, the exit status shall be 127. If the > | command name is found, but it is not an executable utility, the exit > | status shall be 126. >=20 In the test case you added, I think the answers to "Was =C2=ABenv=C2=BB fou= nd?" and "Is =C2=ABenv=C2=BB an executable utility?" are both "yes". Thus, neit= her of the sentence quoted from =C2=A72.8.2 applies: the exit status in that case = is neither required to be=C2=A0127 nor required to be=C2=A0126. That would appear to be a lacuna: the standard does not specify what the exit status shall be when the command _is_ found and _is_ an "executable utility", but execution fails for some other reason, such as an argument being too long. Furthermore, the standard doesn't _forbid_ the exit status of the test you added from being either 126 or 127. (That's the plain meaning of quoted sentences: they say "if A then B", not "A iff B".) It _would_ be useful for error codes to only be caused by specific failure modes, in order to enable scripts to handle error codes selectively. However, the incumbent code has this property too: status=C2=A0126 has only two specific causes. We could still make the change you propose, of course, but it's not a black and white case of the incumbent behaviour being "incorrect". Therefore, in particular, we should consider not only whether we'd be compatible with other shells, but also whether the proposed change might constitute a regression for people upgrading from older zsh to newer zsh. For example, might some zsh users be relying on the incumbent "status=C2=A0126 can only be caused by EACCES and ENOEXEC" semantics? To be clear, I'm not objecting to the change; I'm only trying to ensure all viewpoints are taken into account. Thanks, Martijn. Daniel > Now, the phrasing "it is not an executable utility" is a little vague,=20 > but the current versions of all other shells return 126 upon any failure= =20 > to execute a utility that was found, so they seem to interpret that=20 > phrase as meaning "it could not be executed for whatever reason (other=20 > than 'not found')". In any case, 126 is better than any alternative, as=20 > all other exit codes potentially conflict with other meanings. >=20 > Currently, the execute() function in Src/exec.c only returns status 126=20 > if the error code is EACCES (permission denied) or ENOEXEC (exec format=20 > error). In all other cases, 127 is returned. >=20 > That logic is not right, because 127 is the specific case: it is only to= =20 > be used if the command was not found. Any failure to execute after the=20 > command is found should yield status 126. >=20 > The attached patch changes that logic to return status 127 if there is=20 > no error number (which happens if a PATH search does not find a command)= =20 > or if the error number is ENOENT (no such file or directory). In all=20 > other cases it now returns 126. >=20 > I've also added a test for the "argument list too long" case.