diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index fba619e9..415e95e8 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -68,9 +68,21 @@ extern "C" int err = errno; execve(file.chars(), argv, envp); - if (errno != ENOENT && errno != EACCES) return -1; + if (errno != ENOENT && errno != EACCES && errno != ENOEXEC) return -1; - // FIXME: POSIX says that if errno == ENOEXEC, we should run /bin/sh . + if (errno == ENOEXEC) + { + Vector shell_argv; + shell_argv.try_append(const_cast("sh")); + char* const* arg = argv; + do { + shell_argv.try_append(*arg); + } while (*(arg++)); + + execve("/bin/sh", shell_argv.data(), envp); + errno = ENOEXEC; + return -1; + } if (err == EACCES) errno = err; }