|
|
Message-ID: <20180902171124.GW1878@brightrain.aerifal.cx>
Date: Sun, 2 Sep 2018 13:11:24 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] fexecve: implement in terms of execveat when it
exists
On Sun, Sep 02, 2018 at 12:04:55AM -0400, Joseph Sible wrote:
> This lets fexecve work even when /proc isn't mounted.
> ---
> src/process/fexecve.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/src/process/fexecve.c b/src/process/fexecve.c
> index 6507b42..905487e 100644
> --- a/src/process/fexecve.c
> +++ b/src/process/fexecve.c
> @@ -1,13 +1,20 @@
> +#define _GNU_SOURCE
> #include <unistd.h>
> #include <errno.h>
> +#include <fcntl.h>
> +#include "syscall.h"
>
> void __procfdname(char *, unsigned);
>
> int fexecve(int fd, char *const argv[], char *const envp[])
> {
> +#ifdef SYS_execveat
> + return syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
> +#else
> char buf[15 + 3*sizeof(int)];
> __procfdname(buf, fd);
> execve(buf, argv, envp);
> if (errno == ENOENT) errno = EBADF;
> return -1;
> +#endif
> }
> --
> 2.7.4
This breaks programs running on any kernel older than 3.19.
Instead it needs to be something like
int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
if (r!=-ENOSYS) return __syscall_ret(r);
...
with no #ifdef. #ifdef SYS_anything is only valid in musl when the
existence of the syscall is arch-specific. The defines come from musl
itself, so trying to use it for something version-specific does not
make sense; it would be unconditionally true or false.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.