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 <linux/fcntl.h>      /* Definition of AT_* constants */
10       #include <unistd.h>
11
12       int execveat(int dirfd, const char *pathname,
13                    const char *const argv[], const char *const envp[],
14                    int flags);
15

DESCRIPTION

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

RETURN VALUE

49       On success, execveat() does not return.  On error, -1 is returned,  and
50       errno is set to indicate the error.
51

ERRORS

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

VERSIONS

74       execveat() was added to Linux in  kernel  3.19.   Library  support  was
75       added to glibc in version 2.34.
76

CONFORMING TO

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

NOTES

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

BUGS

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

SEE ALSO

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

COLOPHON

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