1 #include <fcntl.h> // open
2 #include <stdio.h> // perror
3 #include <string.h> // strdup
4 #include <stdlib.h> // exit
5 #include <unistd.h> // fexecve
7 int main(int argc
, char **argv
, char** envp
)
9 char *exe
= "/usr/bin/true";
11 int fd
= open(exe
, O_RDONLY
);
14 perror("open failed:");
17 char ** new_argv
= malloc(2*sizeof(char *));
18 char ** new_envp
= malloc(2*sizeof(char *));
19 char * arg1
= strdup("./fexecve");
20 char * env1
= strdup("FOO=bar");
21 int * new_fd
= malloc(sizeof(int));
23 new_argv
[1] = new_envp
[1] = NULL
;
29 if (-1 == fexecve(*new_fd
, new_argv
, new_envp
))
31 perror("fexecv failed:");