Home | History | Annotate | Download | only in libdaemon
      1 #ifndef foodexechfoo
      2 #define foodexechfoo
      3 
      4 /***
      5   This file is part of libdaemon.
      6 
      7   Copyright 2003-2008 Lennart Poettering
      8 
      9   Permission is hereby granted, free of charge, to any person obtaining a copy
     10   of this software and associated documentation files (the "Software"), to deal
     11   in the Software without restriction, including without limitation the rights
     12   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     13   copies of the Software, and to permit persons to whom the Software is
     14   furnished to do so, subject to the following conditions:
     15 
     16   The above copyright notice and this permission notice shall be included in
     17   all copies or substantial portions of the Software.
     18 
     19   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     20   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     21   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     22   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     23   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     24   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     25   SOFTWARE.
     26 
     27 ***/
     28 
     29 #include <stdarg.h>
     30 
     31 #ifdef __cplusplus
     32 extern "C" {
     33 #endif
     34 
     35 /** \file
     36  *
     37  * Contains a robust API for running sub processes with STDOUT and
     38  * STDERR redirected to syslog
     39  */
     40 
     41 /** This variable is defined to 1 iff daemon_exec() is supported.
     42  * @since 0.4
     43  * @see daemon_exec() */
     44 #define DAEMON_EXEC_AVAILABLE 1
     45 
     46 #if defined(__GNUC__) && ! defined(DAEMON_GCC_SENTINEL)
     47 #define DAEMON_GCC_SENTINEL __attribute__ ((sentinel))
     48 #else
     49 /** A macro for making use of GCCs printf compilation warnings */
     50 #define DAEMON_GCC_SENTINEL
     51 #endif
     52 
     53 /** Run the specified executable with the specified arguments in the
     54  * specified directory and return the return value of the program in
     55  * the specified pointer. The calling process is blocked until the
     56  * child finishes and all child output (either STDOUT or STDIN) has
     57  * been written to syslog. Running this function requires that
     58  * daemon_signal() has been called with SIGCHLD as argument.
     59  *
     60  * @param dir Working directory for the process.
     61  * @param ret A pointer to an integer to write the return value of the program to.
     62  * @param prog The path to the executable
     63  * @param ... The arguments to be passed to the program, followed by a (char *) NULL
     64  * @return Nonzero on failure, zero on success
     65  * @since 0.4
     66  * @see DAEMON_EXEC_AVAILABLE
     67  */
     68 int daemon_exec(const char *dir, int *ret, const char *prog, ...) DAEMON_GCC_SENTINEL;
     69 
     70 /** This variable is defined to 1 iff daemon_execv() is supported.
     71  * @since 0.11
     72  * @see daemon_execv() */
     73 #define DAEMON_EXECV_AVAILABLE 1
     74 
     75 /** The same as daemon_exec, but without variadic arguments
     76  * @since 0.11
     77  * @see DAEMON_EXECV_AVAILABLE */
     78 int daemon_execv(const char *dir, int *ret, const char *prog, va_list ap);
     79 
     80 #ifdef __cplusplus
     81 }
     82 #endif
     83 
     84 #endif
     85