Subject: Re: more user-friendly error message for /bin/sh?
To: None <tech-userlevel@netbsd.org>
From: James K. Lowden <jklowden@schemamania.org>
List: tech-userlevel
Date: 01/16/2007 20:16:19
Christos Zoulas wrote:
> In article <45AD2E2A.7060908@NetBSD.org>,
> Roland Illig  <rillig@NetBSD.org> wrote:
> >-=-=-=-=-=-
> >
> >Currently, I can do this:
> >
> >$ /bin/sh /bin/cat
> >/bin/cat: 1: Syntax error: "(" unexpected
> >
> >What about the following error message, which says what's really the 
> >problem:?
> >
> >$ ./sh /bin/cat
> >./sh: Cannot execute ELF binary /bin/cat
> >
> >(I just hope no one says they really have shell scripts starting with 
> >the ELF magic code, and that they need those bytes at the start of the 
> >script. ;))
> >
> 
> What about other binary files that the kernel can run? a.out for
> example? coff?
> 
> I would say just check if the first few bytes of the file are non ascii,
> and say that you cannot execute binary /bin/cat...

I disagree.  Roland's patch converts one common, mysterious message into
something useful. Why isn't that enough?  Surely ELF is by far the most
common flavor.  

For extra credit, the shell could read its own magic number and compare
that to the input.  That would work even after NetBSD moves on to ELF's
successor, whatever that is.  

It's also not necessary IMO to check if fd is a regular file.  If it
seeks, it seeks, else it returns -1, errno will be ESPIPE, and life goes
on.  

--jkl