summaryrefslogtreecommitdiff
path: root/LibC
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-26 03:16:26 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-26 03:16:26 +0200
commit490e89e24067500e2e7b672ffaf96dd888fca3a1 (patch)
tree489641b868b86a419f9f38a5603c864540514662 /LibC
parent0a68e0046fe01ada175cb4813be6ab5fb447d35b (diff)
downloadserenity-490e89e24067500e2e7b672ffaf96dd888fca3a1.zip
LibC: Add execvpe() and make execvp()'ed children inherit environment.
Diffstat (limited to 'LibC')
-rw-r--r--LibC/unistd.cpp15
-rw-r--r--LibC/unistd.h1
2 files changed, 11 insertions, 5 deletions
diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp
index ab691151e5..41051bb53b 100644
--- a/LibC/unistd.cpp
+++ b/LibC/unistd.cpp
@@ -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;
diff --git a/LibC/unistd.h b/LibC/unistd.h
index 2f9f7d01e6..e3d0d85ffb 100644
--- a/LibC/unistd.h
+++ b/LibC/unistd.h
@@ -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();