[PATCH] argv[0] of execvp when ENOEXEC

Wei-cheng Wang cole945 at gmail.com
Tue Aug 20 16:42:57 UTC 2013


Hi,

When execvp executes the file and gets NOEXECV, it shall execute
a command interpreter as if the process is invoked by sh, and the
argv[0] shall point to the filename being started.  Therefore,
a script file without hashbang (#!) is still executed by sh utility.

However, currently uClibc set argv[0] to be the filename of the script
itself instead of the name of shell, e.g., "/bin/sh", and it is
inconsistent with the behaviors of other libc (e.g., BSD libc, glibc,
bionic libc) and how Linux kernel passed interpreter as argv[0] in
binfmt_script.   Although it’s not mandatory in terms of POSIX.1, but
busybox relies on argv[0] for "sh" applet to be run.

Without this patch, busybox complains "foo.sh: applet not found"
when executing a shell script without hashbang.

Any comment?

Thanks,
Wei-cheng Wang

diff --git a/libc/unistd/exec.c b/libc/unistd/exec.c
index 8fa42e5..91b34ad 100644
--- a/libc/unistd/exec.c
+++ b/libc/unistd/exec.c
@@ -269,7 +269,7 @@ int execvpe(const char *path, char *const argv[], 
char *const envp[])
  #elif defined (L_execvpe)
  			nargv = (char **) EXEC_ALLOC((n+2) * sizeof(char *), size2, 
EXEC_FUNC_EXECVPE);
  #endif
-			nargv[0] = argv[0];
+			nargv[0] = "/bin/sh";
  			nargv[1] = (char *)path;
  			memcpy(nargv+2, argv+1, n*sizeof(char *));
  #if defined (L_execvp)


More information about the uClibc mailing list