mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
LibC: Add execvpe() and make execvp()'ed children inherit environment.
This commit is contained in:
parent
0a68e0046f
commit
490e89e240
Notes:
sideshowbarker
2024-07-19 14:34:59 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/490e89e2406
3 changed files with 13 additions and 5 deletions
|
@ -442,6 +442,8 @@ int Process::sys$execve(const char* filename, const char** argv, const char** en
|
|||
// On success, the kernel stack will be lost.
|
||||
if (!validate_read_str(filename))
|
||||
return -EFAULT;
|
||||
if (!*filename)
|
||||
return -ENOENT;
|
||||
if (argv) {
|
||||
if (!validate_read_typed(argv))
|
||||
return -EFAULT;
|
||||
|
|
|
@ -45,11 +45,11 @@ int execve(const char* filename, char* const argv[], char* const envp[])
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int execvp(const char* filename, char* const argv[])
|
||||
int execvpe(const char* filename, char* const argv[], char* const envp[])
|
||||
{
|
||||
int rc = execve(filename, argv, nullptr);
|
||||
int rc = execve(filename, argv, environ);
|
||||
if (rc < 0 && errno != ENOENT) {
|
||||
printf("execvp failed on first with %s\n", strerror(errno));
|
||||
fprintf(stderr, "execvpe() failed on first with %s\n", strerror(errno));
|
||||
return rc;
|
||||
}
|
||||
String path = getenv("PATH");
|
||||
|
@ -58,9 +58,9 @@ int execvp(const char* filename, char* const argv[])
|
|||
auto parts = path.split(':');
|
||||
for (auto& part : parts) {
|
||||
auto candidate = String::format("%s/%s", part.characters(), filename);
|
||||
rc = execve(candidate.characters(), argv, environ);
|
||||
int rc = execve(candidate.characters(), argv, environ);
|
||||
if (rc < 0 && errno != ENOENT) {
|
||||
printf("execvp failed on attempt (%s) with %s\n", candidate.characters(), strerror(errno));
|
||||
printf("execvpe() failed on attempt (%s) with %s\n", candidate.characters(), strerror(errno));
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,11 @@ int execvp(const char* filename, char* const argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
int execvp(const char* filename, char* const argv[])
|
||||
{
|
||||
return execvpe(filename, argv, environ);
|
||||
}
|
||||
|
||||
int execl(const char* filename, const char* arg0, ...)
|
||||
{
|
||||
Vector<const char*, 16> args;
|
||||
|
|
|
@ -28,6 +28,7 @@ inline int getpagesize() { return 4096; }
|
|||
pid_t fork();
|
||||
int execv(const char* path, char* const argv[]);
|
||||
int execve(const char* filename, char* const argv[], char* const envp[]);
|
||||
int execvpe(const char* filename, char* const argv[], char* const envp[]);
|
||||
int execvp(const char* filename, char* const argv[]);
|
||||
int execl(const char* filename, const char* arg, ...);
|
||||
void sync();
|
||||
|
|
Loading…
Add table
Reference in a new issue