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       pathname
57              is relative but dirfd is neither AT_FDCWD nor a valid  file  de‐
58              scriptor.
59
60       EINVAL Invalid flag specified in flags.
61
62       ELOOP  flags  includes  AT_SYMLINK_NOFOLLOW  and the file identified by
63              dirfd and a non-NULL pathname is a symbolic link.
64
65       ENOENT The program identified by dirfd and pathname requires the use of
66              an  interpreter  program  (such as a script starting with "#!"),
67              but the file descriptor dirfd  was  opened  with  the  O_CLOEXEC
68              flag,  with  the result that the program file is inaccessible to
69              the launched interpreter.  See BUGS.
70
71       ENOTDIR
72              pathname is relative and dirfd is a file descriptor referring to
73              a file other than a directory.
74

VERSIONS

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

CONFORMING TO

80       The execveat() system call is Linux-specific.
81

NOTES

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

BUGS

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

SEE ALSO

113       execve(2), openat(2), fexecve(3)
114

COLOPHON

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