27.10.2022 09:40, Laurent Vivier wrote:
..
I tried O_CLOEXEC, but it seems the fd is closed before it is needed by execveat() to re-spawn the process, so it exits with an error (something
like EBADF)
It works here for me with a simple test program:
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>
#define AT_EMPTY_PATH 0x1000
static char *argv[] = { "ls", NULL };
static char *envp[] = { NULL };
int main(void) {
int fd = open("/usr/bin/ls", O_RDONLY);
fcntl(fd, F_SETFD, O_CLOEXEC);
//execveat(fd, "", argv, envp, AT_EMPTY_PATH);
syscall(__NR_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
return 0;
}