Opened 10 years ago

Last modified 10 years ago

#329 new defect

spawn() and a shell script not started with #!

Reported by: KO Myung-Hun Owned by:
Priority: normal Milestone: libc-0.7
Component: libc Version: 0.6.6
Severity: normal Keywords:
Cc:

Description

Hi/2.

Some shell scripts do not have #! at first line. In this case, spawn() cannot execute it.

For examples,

spawn.sh

eval '(exit $?0)' && eval 'exec perl -w "$0" ${1+"$@"}'
  & eval 'exec perl -w "$0" $argv:q'
    if 0;

my $v='Hello';
print $v, "\n";

spawn.c

#include <stdio.h>
#include <process.h>

int main( int argc, char *argv[])
{
    int rc;

    if( argc < 2 )
    {
        fprintf( stderr, "Usage: spawn program\n");

        return 1;
    }

    rc = spawnvp( P_WAIT, argv[ 1 ], &argv[ 1 ]);
    printf("spawnvp() = %d\n", rc );
    if( rc == -1 )
        perror("spawnvp()");

    return !!rc;
}

When trying

spawn spawn.sh

the result is

spawnvp() = -1
spawnvp(): Invalid executable file format

Change History (1)

comment:1 by dmik, 10 years ago

I don't think that it's a responsibility of kLIBC to decide which shell to use in such a case. It should be done by the shell. I.e. ash (and my recently ported dash) does so explicitly when exec returns ENOEXEC on such a file (using _PATH_BSHELL or itself when _PATH_BSHELL also fails).

How does Linux LIBC behave in such a case?

Note: See TracTickets for help on using tickets.