diff options
author | Mattias Andrée <maandree@member.fsf.org> | 2015-12-20 18:51:19 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@member.fsf.org> | 2015-12-20 18:51:19 +0100 |
commit | 613c7c10dca07571a57dc608754e181ab6754e5f (patch) | |
tree | 49650e222728b8244a2462c515e50243e782f394 /src/unistd/execat.c | |
parent | add searchpath and searchpath2 (diff) | |
download | slibc-613c7c10dca07571a57dc608754e181ab6754e5f.tar.gz slibc-613c7c10dca07571a57dc608754e181ab6754e5f.tar.bz2 slibc-613c7c10dca07571a57dc608754e181ab6754e5f.tar.xz |
change semantics of searchpath2 and add searchpath3
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to '')
-rw-r--r-- | src/unistd/execat.c | 49 |
1 files changed, 7 insertions, 42 deletions
diff --git a/src/unistd/execat.c b/src/unistd/execat.c index 68d9cfd..700db2f 100644 --- a/src/unistd/execat.c +++ b/src/unistd/execat.c @@ -474,65 +474,30 @@ int execveat(int dirfd, const char* path, char* const argv[], char* const envp[] */ int execvpeat(int dirfd, const char* file, char* const argv[], char* const envp[], int flags) { - char* path = NULL; char* pathname = NULL; - char* p; - char* q; - size_t len = 0; int eacces = 0; int saved_errno; if (strchr(file, '/') || !*file) return execveat(dirfd, file, argv, envp, flags); - path = getenv("PATH"); - if (path == NULL) + if (getenv("PATH") == NULL) { execveat(dirfd, file, argv, envp, flags); if (errno == EACCES) eacces = 1; - else if (errno != ENOENT) goto fail; - - if ((len = confstr(_CS_PATH, NULL, 0))) - { - path = malloc(len * sizeof(char)); - if (path == NULL) - goto fail; - if (!confstr(_CS_PATH, path, len)) - free(path), path = NULL; - } - if (path == NULL) - path = strdup("/usr/local/bin:/bin:/usr/bin"); + else if (errno != ENOENT) return -1; } - else - path = strdup(path); - if (path == NULL) - goto fail; - pathname = malloc((strlen(path) + strlen(file) + 2) * sizeof(char)); + pathname = searchpath3(file, NULL, ""); if (pathname == NULL) - goto fail; - - for (p = path; *p; p = q + 1) - { - if (p == (q = strchr(p, ':'))) - continue; - *q = '\0'; - - stpcpy(stpcpy(stpcpy(pathname, p), "/"), file); - - execve(pathname, argv, envp); - if (errno == EACCES) eacces = 1; - else if (errno != ENOENT) goto fail; - } + return -1; - free(path); - free(pathname); - return errno = (eacces ? EACCES : ENOENT), -1; + execve(pathname, argv, envp); - fail: saved_errno = errno; - free(path); free(pathname); + if (eacces && (saved_errno == ENOENT)) + saved_errno = EACCES; errno = saved_errno; return -1; } |