From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22491 invoked from network); 29 May 2006 15:33:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.2 (2006-05-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.2 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 29 May 2006 15:33:23 -0000 Received: (qmail 32054 invoked from network); 29 May 2006 15:33:15 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 29 May 2006 15:33:15 -0000 Received: (qmail 8917 invoked by alias); 29 May 2006 15:33:08 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10343 Received: (qmail 8904 invoked from network); 29 May 2006 15:33:07 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 29 May 2006 15:33:07 -0000 Received: (qmail 30814 invoked from network); 29 May 2006 15:33:07 -0000 Received: from mta08-winn.ispmail.ntl.com (HELO mtaout02-winn.ispmail.ntl.com) (81.103.221.48) by a.mx.sunsite.dk with SMTP; 29 May 2006 15:33:06 -0000 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20060529153304.VKAR29040.mtaout02-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Mon, 29 May 2006 16:33:04 +0100 Received: from pwslaptop.csr.com ([81.107.47.162]) by aamtaout01-winn.ispmail.ntl.com with ESMTP id <20060529153304.YEVV19763.aamtaout01-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Mon, 29 May 2006 16:33:04 +0100 Received: from pwslaptop.csr.com (pwslaptop.csr.com [127.0.0.1]) by pwslaptop.csr.com (8.13.6/8.13.4) with ESMTP id k4TFWueM011027 for ; Mon, 29 May 2006 16:32:57 +0100 Message-Id: <200605291532.k4TFWueM011027@pwslaptop.csr.com> From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: Vanishing files ? In-Reply-To: Message from Anssi Saari of "Mon, 29 May 2006 10:57:22 +0300." <20060529075722.GA28846@sci.fi> Date: Mon, 29 May 2006 16:32:56 +0100 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/