From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@sunsite.dk
Subject: Re: Vanishing files ?
Date: Mon, 29 May 2006 16:32:56 +0100 [thread overview]
Message-ID: <200605291532.k4TFWueM011027@pwslaptop.csr.com> (raw)
In-Reply-To: Message from Anssi Saari <as@sci.fi> of "Mon, 29 May 2006 10:57:22 +0300." <20060529075722.GA28846@sci.fi>
Anssi Saari wrote:
> Now that we're on the topic, I think bash does this a little better. If you h
> ave an
> invalid interpreter, it tells you, like this:
>
> bash: ./foo: /bin/foo: bad interpreter: No such file or directory
This turns out to be easy; the function already does path look up and
even has code to search for the interpreter (to emulate #! on older
systems where it wasn't implemented natively). It relies on the error
being ENOENT (no such file or directory), not ENOEXEC (exec format
error); this is the case on all the systems I know about (haven't check
any relevant standards).
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.98
diff -u -r1.98 exec.c
--- Src/exec.c 19 Apr 2006 16:09:07 -0000 1.98
+++ Src/exec.c 29 May 2006 15:28:29 -0000
@@ -385,7 +385,7 @@
* then check for an errno equal to ENOEXEC. This errno is set *
* if the process file has the appropriate access permission, *
* but has an invalid magic number in its header. */
- if ((eno = errno) == ENOEXEC) {
+ if ((eno = errno) == ENOEXEC || eno == ENOENT) {
char execvebuf[POUNDBANGLIMIT + 1], *ptr, *ptr2, *argv0;
int fd, ct, t0;
@@ -405,7 +405,14 @@
execvebuf[POUNDBANGLIMIT] = '\0';
for (ptr = execvebuf + 2; *ptr && *ptr == ' '; ptr++);
for (ptr2 = ptr; *ptr && *ptr != ' '; ptr++);
- if (*ptr) {
+ if (eno == ENOENT) {
+ char *buf;
+ if (*ptr)
+ *ptr = '\0';
+ buf = tricat("%s: bad interpreter: ", ptr2,
+ ": %e");
+ zerr(buf, pth, eno);
+ } else if (*ptr) {
*ptr = '\0';
argv[-2] = ptr2;
argv[-1] = ptr + 1;
@@ -414,11 +421,11 @@
argv[-1] = ptr2;
execve(ptr2, argv - 1, environ);
}
- } else {
+ } else if (eno == ENOEXEC) {
argv[-1] = "sh";
execve("/bin/sh", argv - 1, environ);
}
- } else {
+ } else if (eno == ENOEXEC) {
for (t0 = 0; t0 != ct; t0++)
if (!execvebuf[t0])
break;
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
next prev parent reply other threads:[~2006-05-29 15:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-28 15:24 Meino Christian Cramer
2006-05-28 18:32 ` Bart Schaefer
2006-05-28 18:38 ` Meino Christian Cramer
2006-05-28 23:24 ` Bart Schaefer
2006-05-29 2:38 ` Meino Christian Cramer
2006-05-29 7:57 ` Anssi Saari
2006-05-29 15:32 ` Peter Stephenson [this message]
2006-05-29 17:51 ` Paul Lew
2006-05-29 18:16 ` De-script (Re: Vanishing files ?) Bart Schaefer
2006-05-28 18:37 ` Vanishing files ? DervishD
2006-05-28 18:44 ` Meino Christian Cramer
2006-05-29 6:11 ` DervishD
2006-05-29 8:56 ` Meino Christian Cramer
2006-05-29 8:58 ` DervishD
2006-05-30 21:59 ` Tobias Gruetzmacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200605291532.k4TFWueM011027@pwslaptop.csr.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).