1EXECVEAT(2)                Linux Programmer's Manual               EXECVEAT(2)
2
3
4

NAME

6       execveat - execute program relative to a directory file descriptor
7

SYNOPSIS

9       #include <unistd.h>
10
11       int execveat(int dirfd, const char *pathname,
12                    char *const argv[], char *const envp[],
13                    int flags);
14

DESCRIPTION

16       The execveat() system call executes the program referred to by the com‐
17       bination of dirfd and pathname.  It operates in exactly the same way as
18       execve(2), except for the differences described in this manual page.
19
20       If  the  pathname given in pathname is relative, then it is interpreted
21       relative to the directory referred to  by  the  file  descriptor  dirfd
22       (rather  than  relative to the current working directory of the calling
23       process, as is done by execve(2) for a relative pathname).
24
25       If pathname is relative and dirfd is the special value  AT_FDCWD,  then
26       pathname  is  interpreted  relative to the current working directory of
27       the calling process (like execve(2)).
28
29       If pathname is absolute, then dirfd is ignored.
30
31       If pathname is an empty string and the AT_EMPTY_PATH flag is specified,
32       then the file descriptor dirfd specifies the file to be executed (i.e.,
33       dirfd refers to an executable file, rather than a directory).
34
35       The flags argument is a bit mask that can include zero or more  of  the
36       following flags:
37
38       AT_EMPTY_PATH
39              If  pathname is an empty string, operate on the file referred to
40              by dirfd (which may have been obtained using the open(2)  O_PATH
41              flag).
42
43       AT_SYMLINK_NOFOLLOW
44              If  the  file  identified  by dirfd and a non-NULL pathname is a
45              symbolic link, then the call fails with the error ELOOP.
46

RETURN VALUE

48       On success, execveat() does not return.  On error, -1 is returned,  and
49       errno is set appropriately.
50

ERRORS

52       The same errors that occur for execve(2) can also occur for execveat().
53       The following additional errors can occur for execveat():
54
55       EBADF  dirfd is not a valid file descriptor.
56
57       EINVAL Invalid flag specified in flags.
58
59       ELOOP  flags includes AT_SYMLINK_NOFOLLOW and the  file  identified  by
60              dirfd and a non-NULL pathname is a symbolic link.
61
62       ENOENT The program identified by dirfd and pathname requires the use of
63              an interpreter program (such as a script  starting  with  "#!"),
64              but  the  file  descriptor  dirfd  was opened with the O_CLOEXEC
65              flag, with the result that the program file is  inaccessible  to
66              the launched interpreter.  See BUGS.
67
68       ENOTDIR
69              pathname is relative and dirfd is a file descriptor referring to
70              a file other than a directory.
71

VERSIONS

73       execveat() was added to Linux in kernel 3.19.  GNU C library support is
74       pending.
75

CONFORMING TO

77       The execveat() system call is Linux-specific.
78

NOTES

80       In  addition to the reasons explained in openat(2), the execveat() sys‐
81       tem call is also needed to allow fexecve(3) to be implemented  on  sys‐
82       tems that do not have the /proc filesystem mounted.
83
84       When  asked to execute a script file, the argv[0] that is passed to the
85       script interpreter is a string of the form  /dev/fd/N  or  /dev/fd/N/P,
86       where N is the number of the file descriptor passed via the dirfd argu‐
87       ment.  A  string  of  the  first  form  occurs  when  AT_EMPTY_PATH  is
88       employed.  A string of the second form occurs when the script is speci‐
89       fied via both dirfd and pathname; in this case, P is the value given in
90       pathname.
91
92       For  the  same  reasons described in fexecve(3), the natural idiom when
93       using execveat() is to set the close-on-exec flag on dirfd.   (But  see
94       BUGS.)
95

BUGS

97       The  ENOENT  error described above means that it is not possible to set
98       the close-on-exec flag on the file descriptor given to a  call  of  the
99       form:
100
101           execveat(fd, "", argv, envp, AT_EMPTY_PATH);
102
103       However,  the inability to set the close-on-exec flag means that a file
104       descriptor referring to the script leaks through to the script  itself.
105       As  well  as  wasting a file descriptor, this leakage can lead to file-
106       descriptor exhaustion in scenarios  where  scripts  recursively  employ
107       execveat().
108

SEE ALSO

110       execve(2), openat(2), fexecve(3)
111

COLOPHON

113       This  page  is  part of release 4.16 of the Linux man-pages project.  A
114       description of the project, information about reporting bugs,  and  the
115       latest     version     of     this    page,    can    be    found    at
116       https://www.kernel.org/doc/man-pages/.
117
118
119
120Linux                             2017-09-15                       EXECVEAT(2)
Impressum