Reduce memory requirements for execve()
This commit is contained in:
@@ -25,15 +25,16 @@
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int execve$sysv(const char *prog, char *const argv[], char *const envp[]) {
|
||||
size_t i, n;
|
||||
char **shargs, bash[PATH_MAX];
|
||||
size_t i;
|
||||
char **shargs;
|
||||
if (__execve$sysv(prog, argv, envp) != -1) return 0;
|
||||
if (errno != ENOEXEC) return -1;
|
||||
for (i = 0; argv[i];) ++i;
|
||||
shargs = alloca((i + 2) * sizeof(char *));
|
||||
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
|
||||
shargs[0] = !IsFreebsd() ? _PATH_BSHELL
|
||||
: firstnonnull(commandv("bash", bash), _PATH_BSHELL);
|
||||
: firstnonnull(commandv("bash", alloca(PATH_MAX)),
|
||||
_PATH_BSHELL);
|
||||
shargs[1] = prog;
|
||||
return __execve$sysv(shargs[0], shargs, envp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user