00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 /*! 00018 * @defgroup exec Command execution wrappers 00019 * 00020 * The exec family of functions provide convenient wrappers around fork(2), 00021 * execve(2), waitpid(2) and pipe(2). 00022 * 00023 * These functions combine one or more of the above system calls in one 00024 * function, thus allowing fast and simple process creation in applications. 00025 * 00026 * @{ 00027 */ 00028 00029 #ifndef _LUCID_EXEC_H 00030 #define _LUCID_EXEC_H 00031 00032 /*! 00033 * @brief maximum number of arguments that will be converted for execvp(2) 00034 */ 00035 #define EXEC_MAX_ARGV 64 00036 00037 /*! 00038 * @brief fork, execvp and wait 00039 * 00040 * @param[in] fmt format string passed to printf 00041 * @param[in] ... variable number of arguments according to fmt 00042 * 00043 * @return status obtained by wait(2) or -1 with errno set 00044 * 00045 * @see printf 00046 * @see execvp(2) 00047 */ 00048 int exec_fork(const char *fmt, ...); 00049 00050 /*! 00051 * @brief fork, execvp and ignore child 00052 * 00053 * @param[in] fmt format string passed to printf 00054 * @param[in] ... variable number of arguments according to fmt 00055 * 00056 * @return 0 on success or -1 with errno set 00057 * 00058 * @see printf 00059 * @see execvp(2) 00060 * 00061 * @note this function closes file descriptors 0-100 before execvp 00062 */ 00063 int exec_fork_background(const char *fmt, ...); 00064 00065 /*! 00066 * @brief pipe, fork, execvp and wait 00067 * 00068 * @param[out] out empty pointer to store combined stdout/stderr 00069 * @param[in] fmt format string passed to printf 00070 * @param[in] ... variable number of arguments according to fmt 00071 * 00072 * @return status obtained by wait(2) or -1 with errno set 00073 * 00074 * @note The caller should free obtained memory for out using free(3) 00075 * 00076 * @see printf 00077 * @see malloc(3) 00078 * @see free(3) 00079 * @see execvp(2) 00080 */ 00081 int exec_fork_pipe(char **out, const char *fmt, ...); 00082 00083 /*! 00084 * @brief plain execvp 00085 * 00086 * @param[in] fmt format string passed to printf 00087 * @param[in] ... variable number of arguments according to fmt 00088 * 00089 * @return only returns on error with errno set 00090 * 00091 * @see printf 00092 * @see execvp(2) 00093 */ 00094 int exec_replace(const char *fmt, ...); 00095 00096 #endif 00097 00098 /*! @} exec */