execveat(2)


NAME

   execveat - execute program relative to a directory file descriptor

SYNOPSIS

   #include <unistd.h>

   int execveat(int dirfd, const char *pathname,
                char *const argv[], char *const envp[],
                int flags);

DESCRIPTION

   The  execveat()  system  call  executes  the program referred to by the
   combination of dirfd and pathname.  It operates in exactly the same way
   as execve(2), except for the differences described in this manual page.

   If  the  pathname given in pathname is relative, then it is interpreted
   relative to the directory referred to  by  the  file  descriptor  dirfd
   (rather  than  relative to the current working directory of the calling
   process, as is done by execve(2) for a relative pathname).

   If pathname is relative and dirfd is the special value  AT_FDCWD,  then
   pathname  is  interpreted  relative to the current working directory of
   the calling process (like execve(2)).

   If pathname is absolute, then dirfd is ignored.

   If pathname is an empty string and the AT_EMPTY_PATH flag is specified,
   then the file descriptor dirfd specifies the file to be executed (i.e.,
   dirfd refers to an executable file, rather than a directory).

   The flags argument is a bit mask that can include zero or more  of  the
   following flags:

   AT_EMPTY_PATH
          If  pathname is an empty string, operate on the file referred to
          by dirfd (which may have been obtained using the open(2)  O_PATH
          flag).

   AT_SYMLINK_NOFOLLOW
          If  the  file  identified  by dirfd and a non-NULL pathname is a
          symbolic link, then the call fails with the error ELOOP.

RETURN VALUE

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

ERRORS

   The same errors that occur for execve(2) can also occur for execveat().
   The following additional errors can occur for execveat():

   EBADF  dirfd is not a valid file descriptor.

   EINVAL Invalid flag specified in flags.

   ELOOP  flags includes AT_SYMLINK_NOFOLLOW and the  file  identified  by
          dirfd and a non-NULL pathname is a symbolic link.

   ENOENT The program identified by dirfd and pathname requires the use of
          an interpreter program (such as a script  starting  with  "#!"),
          but  the  file  descriptor  dirfd  was opened with the O_CLOEXEC
          flag, with the result that the program file is  inaccessible  to
          the launched interpreter.  See BUGS.

   ENOTDIR
          pathname is relative and dirfd is a file descriptor referring to
          a file other than a directory.

VERSIONS

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

CONFORMING TO

   The execveat() system call is Linux-specific.

NOTES

   In  addition  to  the  reasons  explained  in openat(2), the execveat()
   system call is also needed to allow fexecve(3)  to  be  implemented  on
   systems that do not have the /proc filesystem mounted.

   When  asked to execute a script file, the argv[0] that is passed to the
   script interpreter is a string of the form  /dev/fd/N  or  /dev/fd/N/P,
   where  N  is  the  number  of  the file descriptor passed via the dirfd
   argument.  A string of the first  form  occurs  when  AT_EMPTY_PATH  is
   employed.   A  string  of  the  second  form  occurs when the script is
   specified via both dirfd and pathname; in this case,  P  is  the  value
   given in pathname.

   For  the  same  reasons described in fexecve(3), the natural idiom when
   using execveat() is to set the close-on-exec flag on dirfd.   (But  see
   BUGS.)

BUGS

   The  ENOENT  error described above means that it is not possible to set
   the close-on-exec flag on the file descriptor given to a  call  of  the
   form:

       execveat(fd, "", argv, envp, AT_EMPTY_PATH);

   However,  the inability to set the close-on-exec flag means that a file
   descriptor referring to the script leaks through to the script  itself.
   As  well  as  wasting a file descriptor, this leakage can lead to file-
   descriptor exhaustion in scenarios  where  scripts  recursively  employ
   execveat().

SEE ALSO

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

COLOPHON

   This  page  is  part of release 4.09 of the Linux man-pages project.  A
   description of the project, information about reporting bugs,  and  the
   latest     version     of     this    page,    can    be    found    at
   https://www.kernel.org/doc/man-pages/.


More Linux Commands

manpages/XkbGetAccessXTimeout.3.html
XkbGetAccessXTimeout(3) - Queries the current AccessXTimeout
XkbGetAccessXTimeout.3 - In environments where computers are shared, features such as SlowKeys present a problem: if SlowKeys is on, the keyboard can appear to

manpages/Tcl_Alloc.3.html
Tcl_Alloc(3) - allocate or free heap memory - Linux man page
Tcl_Alloc.3 - These procedures provide a platform and compiler independent interface for memory allocation. Programs that need to transfer ownership of memory b

manpages/gluEndTrim.3gl.html
gluEndTrim(3gl) - delimit a NURBS trimming loop definition
Use gluBeginTrim to mark the beginning of a trimming loop, and gluEndTrim to mark the end of a trimming loop. A trimming loop is a set of oriented curve segment

manpages/glutSpaceballRotateFunc.3.html
glutSpaceballRotateFunc(3) - sets the Spaceball rotation cal
glutSpaceballRotateFunc sets the Spaceball rotate callback for the current window. The Spaceball rotate callback for a window is called when the window has Spac

manpages/sasl_client_new.3.html
sasl_client_new(3) - Create a new client authentication obje
sasl_client_new() creates a new SASL context. This context will be used for all SASL calls for one connection. It handles both authentication and integrity/encr

manpages/link.2.html
link(2) - make a new name for a file - Linux manual page....
link() creates a new link (also known as a hard link) to an existing file. If newpath exists, it will not be overwritten. This new name may be used exactly as t

manpages/ops.3pm.html
ops(3pm) - Perl pragma to restrict unsafe operations when co
Since the ops pragma currently has an irreversible global effect, it is only of significant practical use with the -M option on the command line. See the Opcode

manpages/Tk_DrawFocusHighlight.3.html
Tk_DrawFocusHighlight(3) - draw the traversal highlight ring
Tk_DrawFocusHighlight is a utility procedure that draws the traversal highlight ring for a widget. It is typically invoked by widgets during redisplay. KEYWORDS

manpages/Tk_SetGrid.3.html
Tk_SetGrid(3) - control the grid for interactive resizing...
Tk_SetGrid turns on gridded geometry management for tkwins toplevel window and specifies the geometry of the grid. Tk_SetGrid is typically invoked by a widget w

manpages/fsck.ext3.8.html
fsck.ext3(8) - check a Linux ext2/ext3/ext4 file system.....
e2fsck is used to check the ext2/ext3/ext4 family of file systems. For ext3 and ext4 filesystems that use a journal, if the system has been shut down uncleanly

manpages/pcre32_get_named_substring.3.html
pcre32_get_named_substring(3) Perl-compatible regular expres
This is a convenience function for extracting a captured substring by name. The arguments are: code Compiled pattern subject Subject that has been successfully

manpages/IO::WrapTie.3pm.html
IO::WrapTie(3pm) - wrap tieable objects in IO::Handle interf
Suppose you have a class FooHandle, where... * FooHandle does not inherit from IO::Handle; that is, it performs filehandle-like I/O, but to something other than





We can't live, work or learn in freedom unless the software we use is free.