From d45b0f627409c6646c65012bce6819dae7f9db1b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 1 Jan 2016 17:50:30 +0100 Subject: m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/unistd/exec.c | 1 + src/unistd/execat.c | 15 +++++++++++++-- src/unistd/fexec.c | 17 +++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/unistd/exec.c b/src/unistd/exec.c index 69edc4e..2d121e7 100644 --- a/src/unistd/exec.c +++ b/src/unistd/exec.c @@ -285,6 +285,7 @@ int execve(const char* path, char* const argv[], char* const envp[]) return errno = ENOTSUP, -1; (void) path, (void) argv, (void) envp; /* TODO implement execve */ + /* TODO support wrapping in valgrind, strace, &c. */ } diff --git a/src/unistd/execat.c b/src/unistd/execat.c index 87519e4..0005877 100644 --- a/src/unistd/execat.c +++ b/src/unistd/execat.c @@ -34,6 +34,17 @@ struct stat { int st_mode; }; +/** + * The directory where all the process's file descriptors are available. + */ +#if defined(_LINUX_) +# define FD_PATH "/proc/self/fd" /* /dev/fd works but it is a symbolic link. */ +#else +# define FD_PATH "/dev/fd" +#endif + + + /** * The current environment variables. * @@ -415,11 +426,11 @@ int execveat(int dirfd, const char* path, char* const argv[], char* const envp[] return errno = ELOOP, -1; } - pathname = malloc(sizeof("/dev/fd//") + (3 * sizeof(int) + strlen(path)) * sizeof(char)); + pathname = malloc(sizeof(FD_PATH "//") + (3 * sizeof(int) + strlen(path)) * sizeof(char)); if (pathname == NULL) return -1; - sprintf(pathname, "/dev/fd/%i%s%s", dirfd, *path ? "/" : "", path); + sprintf(pathname, FD_PATH "/%i%s%s", dirfd, *path ? "/" : "", path); execve(pathname, argv, envp); saved_errno = errno; diff --git a/src/unistd/fexec.c b/src/unistd/fexec.c index 36352ce..ec592d1 100644 --- a/src/unistd/fexec.c +++ b/src/unistd/fexec.c @@ -23,6 +23,17 @@ +/** + * The directory where all the process's file descriptors are available. + */ +#if defined(_LINUX_) +# define FD_PATH "/proc/self/fd" /* /dev/fd works but it is a symbolic link. */ +#else +# define FD_PATH "/dev/fd" +#endif + + + /** * The current environment variables. * @@ -186,12 +197,6 @@ int fexecv(int fd, char* const argv[]) */ int fexecve(int fd, char* const argv[], char* const envp[]) { -#if defined(_LINUX_) -# define FD_PATH "/proc/self/fd" /* /dev/fd works but it is a symbolic link. */ -#else -# define FD_PATH "/dev/fd" -#endif - char pathname[sizeof(FD_PATH "//") + 3 * sizeof(int)]; int saved_errno; -- cgit v1.2.3-70-g09d2