From b844dc8037d30914ceef5b9e01d77662f462a299 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 11 Oct 2015 02:57:00 +0200 Subject: add execat functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/unistd.h | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 311 insertions(+), 4 deletions(-) (limited to 'include/unistd.h') diff --git a/include/unistd.h b/include/unistd.h index a783f57..33a3db0 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -190,7 +190,7 @@ int execlp(const char*, ... /*, NULL */) * As a slibc extension, it can be empty. * This list shall be terminated by a `NULL` sentinel. * @param envp The list of environment variables the new program shall - * have set. Each element shall be foramtted $name=$value. + * have set. Each element shall be formatted $name=$value. * This list shall be `NULL`-terminated. The behaviour * is system-dependant if this argument is `NULL`. * @return This function does not return on success, @@ -218,7 +218,7 @@ int execle(const char*, ... /*, NULL, char* const[] */) * As a slibc extension, it can be empty. * This list shall be terminated by a `NULL` sentinel. * @param envp The list of environment variables the new program shall - * have set. Each element shall be foramtted $name=$value. + * have set. Each element shall be formatted $name=$value. * This list shall be `NULL`-terminated. The behaviour * is system-dependant if this argument is `NULL`. * @return This function does not return on success, @@ -290,7 +290,7 @@ int execvp(const char*, char* const[]) * be `NULL`-terminated. The behaviour is * system-dependant if this argument is `NULL`. * @param envp The list of environment variables the new program shall - * have set. Each element shall be foramtted $name=$value. + * have set. Each element shall be formatted $name=$value. * This list shall be `NULL`-terminated. The behaviour * is system-dependant if this argument is `NULL`. * @return This function does not return on success, @@ -322,7 +322,7 @@ int execve(const char*, char* const[], char* const[]) * be `NULL`-terminated. The behaviour is * system-dependant if this argument is `NULL`. * @param envp The list of environment variables the new program shall - * have set. Each element shall be foramtted $name=$value. + * have set. Each element shall be formatted $name=$value. * This list shall be `NULL`-terminated. The behaviour * is system-dependant if this argument is `NULL`. * @return This function does not return on success, @@ -336,6 +336,313 @@ int execvpe(const char*, char* const[], char* const[]) #endif +#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE) +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param path The pathname of the file to execute. + * @param ... The arguments with which to execute the file. + * The arguments should have the type `const char*`. + * As a slibc extension, it can be empty. + * This list shall be terminated by a `NULL` sentinel. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `path` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `path` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execlat(int, const char*, ... /*, NULL, int */) + __GCC_ONLY(__attribute__((sentinel(1), nonnull(2)))); + +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param file The pathname of the file to execute, + * or the filename of a file in $PATH, + * to execute. If $PATH is not set, the current + * working directory (yes, you read that right,) + * and a default value for $PATH will be used. + * @param ... The arguments with which to execute the file. + * The arguments should have the type `const char*`. + * As a slibc extension, it can be empty. + * This list shall be terminated by a `NULL` sentinel. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `file` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `file` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execlpat(int, const char*, ... /*, NULL, int */) + __GCC_ONLY(__attribute__((sentinel(1), nonnull(2)))); + +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param path The pathname of the file to execute. + * @param ... The arguments with which to execute the file. + * The arguments should have the type `const char*`. + * As a slibc extension, it can be empty. + * This list shall be terminated by a `NULL` sentinel. + * @param envp The list of environment variables the new program shall + * have set. Each element shall be formatted $name=$value. + * This list shall be `NULL`-terminated. The behaviour + * is system-dependant if this argument is `NULL`. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `path` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `path` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execleat(int, const char*, ... /*, NULL, char* const[], int */) + __GCC_ONLY(__attribute__((sentinel(2), nonnull(2)))); + +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param file The pathname of the file to execute, + * or the filename of a file in $PATH, + * to execute. If $PATH is not set, the current + * working directory (yes, you read that right,) + * and a default value for $PATH will be used. + * @param ... The arguments with which to execute the file. + * The arguments should have the type `const char*`. + * As a slibc extension, it can be empty. + * This list shall be terminated by a `NULL` sentinel. + * @param envp The list of environment variables the new program shall + * have set. Each element shall be formatted $name=$value. + * This list shall be `NULL`-terminated. The behaviour + * is system-dependant if this argument is `NULL`. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `file` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `file` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execlpeat(int, const char*, ... /*, NULL, char* const[], int */) + __GCC_ONLY(__attribute__((sentinel(2), nonnull(2)))); + +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param path The pathname of the file to execute. + * @param argv The arguments with which to execute the file. + * This parameter should really have the type + * `const char* const[]`, but that probably not + * so because compiles take issue with casts + * adding const to any pointer in the type + * except the outmost pointer. This list shall + * be `NULL`-terminated. The behaviour is + * system-dependant if this argument is `NULL`. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `path` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `path` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execvat(int, const char*, char* const[], int) + __GCC_ONLY(__attribute__((nonnull(2)))); + +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param file The pathname of the file to execute, + * or the filename of a file in $PATH, + * to execute. If $PATH is not set, the current + * working directory (yes, you read that right,) + * and a default value for $PATH will be used. + * @param argv The arguments with which to execute the file. + * This parameter should really have the type + * `const char* const[]`, but that probably not + * so because compiles take issue with casts + * adding const to any pointer in the type + * except the outmost pointer. This list shall + * be `NULL`-terminated. The behaviour is + * system-dependant if this argument is `NULL`. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `file` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `file` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execvpat(int, const char*, char* const[], int) + __GCC_ONLY(__attribute__((nonnull(2)))); +#endif + +/** + * Replace the current process image with a new process image. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param path The pathname of the file to execute. + * @param argv The arguments with which to execute the file. + * This parameter should really have the type + * `const char* const[]`, but that probably not + * so because compiles take issue with casts + * adding const to any pointer in the type + * except the outmost pointer. This list shall + * be `NULL`-terminated. The behaviour is + * system-dependant if this argument is `NULL`. + * @param envp The list of environment variables the new program shall + * have set. Each element shall be formatted $name=$value. + * This list shall be `NULL`-terminated. The behaviour + * is system-dependant if this argument is `NULL`. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `path` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `path` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execveat(int, const char*, char* const[], char* const[], int) + __GCC_ONLY(__attribute__((nonnull(2)))); + +#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE) +/** + * Replace the current process image with a new process image. + * + * This is a slibc extension. + * + * @param dirfd File descriptor for a directory (opened with + * with the open(2) `O_PATH` flag,) that will + * act as the current working directory. + * If `AT_FDCWD`, the current working directory + * will be used. + * @param file The pathname of the file to execute, + * or the filename of a file in $PATH, + * to execute. If $PATH is not set, the current + * working directory (yes, you read that right,) + * and a default value for $PATH will be used. + * @param argv The arguments with which to execute the file. + * This parameter should really have the type + * `const char* const[]`, but that probably not + * so because compiles take issue with casts + * adding const to any pointer in the type + * except the outmost pointer. This list shall + * be `NULL`-terminated. The behaviour is + * system-dependant if this argument is `NULL`. + * @param envp The list of environment variables the new program shall + * have set. Each element shall be formatted $name=$value. + * This list shall be `NULL`-terminated. The behaviour + * is system-dependant if this argument is `NULL`. + * @param flags Bit mask that can include zero or more of the + * following flags: + * AT_EMPTY_PATH: + * If `file` is an empty string, operate on the + * file (not directory) referred to by `dirfd`. + * AT_SYMLINK_NOFOLLOW: + * If `file` is relative is a symbolic link, + * fail with `errno` set to `ELOOP`. + * @return This function does not return on success, + * on error, -1 is returned and `errno` is + * set to describe the error. + * + * @throws Any error specified for execveat(2). + */ +int execvpeat(int, const char*, char* const[], char* const[], int) + __GCC_ONLY(__attribute__((nonnull(2)))); +#endif + + #endif -- cgit v1.2.3-70-g09d2