-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfexecve.c
48 lines (40 loc) · 1013 Bytes
/
fexecve.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright 2021-2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifdef __linux__
#include <errno.h>
#include <sys/syscall.h>
#include <fcntl.h>
#include <unistd.h>
#include "iamroot.h"
#define __syscall syscall
/*
* Stolen from musl (src/process/fexecve.c)
*
* SPDX-FileCopyrightText: The musl Contributors
*
* SPDX-License-Identifier: MIT
*/
static int __fexecve(int fd, char * const argv[], char * const envp[])
{
#ifdef SYS_execveat
int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH);
if (r != -ENOSYS) return __syscall_ret(r);
#endif
char buf[15 + 3*sizeof(int)];
__procfdname(buf, fd);
execve(buf, argv, envp);
if (errno == ENOENT) errno = EBADF;
return -1;
}
#undef __syscall
int fexecve(int fd, char * const argv[], char * const envp[])
{
__debug("%s(fd: %i <-> '%s', argv: { '%s', '%s', ... }, envp: %p)\n",
__func__, fd, __fpath(fd), argv[0], argv[1], envp);
/* Forward to local function */
return __fexecve(fd, argv, envp);
}
#endif