00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (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 00015 // Free Software Foundation, Inc., 00016 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 /*! 00019 * @defgroup exec Command execution wrappers 00020 * 00021 * The exec family of functions provide convenient wrappers around fork(2), 00022 * execve(2), waitpid(2) and pipe(2). 00023 * 00024 * These functions combine one or more of the above system calls in one 00025 * function, thus allowing fast and simple process creation in applications. 00026 * 00027 * @{ 00028 */ 00029 00030 #ifndef _LUCID_EXEC_H 00031 #define _LUCID_EXEC_H 00032 00033 /*! 00034 * @brief maximum number of arguments that will be converted for execvp(2) 00035 */ 00036 #define EXEC_MAX_ARGV 64 00037 00038 /*! 00039 * @brief fork, execvp and wait 00040 * 00041 * @param[in] fmt format string passed to printf 00042 * @param[in] ... variable number of arguments according to fmt 00043 * 00044 * @return status obtained by wait(2) or -1 with errno set 00045 * 00046 * @see printf 00047 * @see execvp(2) 00048 */ 00049 int exec_fork(const char *fmt, ...); 00050 00051 /*! 00052 * @brief fork, execvp and ignore child 00053 * 00054 * @param[in] fmt format string passed to printf 00055 * @param[in] ... variable number of arguments according to fmt 00056 * 00057 * @return 0 on success or -1 with errno set 00058 * 00059 * @see printf 00060 * @see execvp(2) 00061 * 00062 * @note this function closes file descriptors 0-100 before execvp 00063 */ 00064 int exec_fork_background(const char *fmt, ...); 00065 00066 /*! 00067 * @brief pipe, fork, execvp and wait 00068 * 00069 * @param[out] out empty pointer to store combined stdout/stderr 00070 * @param[in] fmt format string passed to printf 00071 * @param[in] ... variable number of arguments according to fmt 00072 * 00073 * @return status obtained by wait(2) or -1 with errno set 00074 * 00075 * @note The caller should free obtained memory for out using free(3) 00076 * 00077 * @see printf 00078 * @see malloc(3) 00079 * @see free(3) 00080 * @see execvp(2) 00081 */ 00082 int exec_fork_pipe(char **out, const char *fmt, ...); 00083 00084 /*! 00085 * @brief plain execvp 00086 * 00087 * @param[in] fmt format string passed to printf 00088 * @param[in] ... variable number of arguments according to fmt 00089 * 00090 * @return only returns on error with errno set 00091 * 00092 * @see printf 00093 * @see execvp(2) 00094 */ 00095 int exec_replace(const char *fmt, ...); 00096 00097 #endif 00098 00099 /*! @} exec */