Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 1 | #ifndef foodexechfoo |
| 2 | #define foodexechfoo |
| 3 | |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 4 | /*** |
| 5 | This file is part of libdaemon. |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 6 | |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 7 | Copyright 2003-2008 Lennart Poettering |
| 8 | |
Brandon Philips | 0630da0 | 2012-08-29 17:42:24 -0700 | [diff] [blame] | 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: |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 15 | |
Brandon Philips | 0630da0 | 2012-08-29 17:42:24 -0700 | [diff] [blame] | 16 | The above copyright notice and this permission notice shall be included in |
| 17 | all copies or substantial portions of the Software. |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 18 | |
Brandon Philips | 0630da0 | 2012-08-29 17:42:24 -0700 | [diff] [blame] | 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 | |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 27 | ***/ |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 28 | |
Lennart Poettering | b45cd33 | 2007-06-11 15:16:09 +0000 | [diff] [blame] | 29 | #include <stdarg.h> |
| 30 | |
Lennart Poettering | feb9b77 | 2004-11-12 15:22:45 +0000 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 35 | /** \file |
| 36 | * |
| 37 | * Contains a robust API for running sub processes with STDOUT and |
| 38 | * STDERR redirected to syslog |
| 39 | */ |
| 40 | |
Lennart Poettering | 1368b79 | 2009-10-18 04:22:26 +0200 | [diff] [blame] | 41 | /** This variable is defined to 1 iff daemon_exec() is supported. |
| 42 | * @since 0.4 |
| 43 | * @see daemon_exec() */ |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 44 | #define DAEMON_EXEC_AVAILABLE 1 |
| 45 | |
Lennart Poettering | 5be2d89 | 2007-06-11 15:42:31 +0000 | [diff] [blame] | 46 | #if defined(__GNUC__) && ! defined(DAEMON_GCC_SENTINEL) |
Lennart Poettering | 5be2d89 | 2007-06-11 15:42:31 +0000 | [diff] [blame] | 47 | #define DAEMON_GCC_SENTINEL __attribute__ ((sentinel)) |
| 48 | #else |
Lennart Poettering | 1368b79 | 2009-10-18 04:22:26 +0200 | [diff] [blame] | 49 | /** A macro for making use of GCCs printf compilation warnings */ |
Lennart Poettering | 5be2d89 | 2007-06-11 15:42:31 +0000 | [diff] [blame] | 50 | #define DAEMON_GCC_SENTINEL |
| 51 | #endif |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 52 | |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 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 |
Lennart Poettering | 8f34edf | 2004-01-10 18:45:49 +0000 | [diff] [blame] | 56 | * child finishes and all child output (either STDOUT or STDIN) has |
Lennart Poettering | 5e88553 | 2005-09-10 09:52:24 +0000 | [diff] [blame] | 57 | * been written to syslog. Running this function requires that |
Lennart Poettering | 57855da | 2007-06-11 15:34:47 +0000 | [diff] [blame] | 58 | * daemon_signal() has been called with SIGCHLD as argument. |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 59 | * |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 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 |
Lennart Poettering | 1368b79 | 2009-10-18 04:22:26 +0200 | [diff] [blame] | 65 | * @since 0.4 |
| 66 | * @see DAEMON_EXEC_AVAILABLE |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 67 | */ |
Lennart Poettering | 5be2d89 | 2007-06-11 15:42:31 +0000 | [diff] [blame] | 68 | int daemon_exec(const char *dir, int *ret, const char *prog, ...) DAEMON_GCC_SENTINEL; |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 69 | |
Lennart Poettering | 1368b79 | 2009-10-18 04:22:26 +0200 | [diff] [blame] | 70 | /** This variable is defined to 1 iff daemon_execv() is supported. |
| 71 | * @since 0.11 |
| 72 | * @see daemon_execv() */ |
Lennart Poettering | b45cd33 | 2007-06-11 15:16:09 +0000 | [diff] [blame] | 73 | #define DAEMON_EXECV_AVAILABLE 1 |
| 74 | |
Lennart Poettering | 1368b79 | 2009-10-18 04:22:26 +0200 | [diff] [blame] | 75 | /** The same as daemon_exec, but without variadic arguments |
| 76 | * @since 0.11 |
| 77 | * @see DAEMON_EXECV_AVAILABLE */ |
Lennart Poettering | b45cd33 | 2007-06-11 15:16:09 +0000 | [diff] [blame] | 78 | int daemon_execv(const char *dir, int *ret, const char *prog, va_list ap); |
Lennart Poettering | 7892e9b | 2008-07-28 20:50:57 +0200 | [diff] [blame] | 79 | |
Lennart Poettering | feb9b77 | 2004-11-12 15:22:45 +0000 | [diff] [blame] | 80 | #ifdef __cplusplus |
| 81 | } |
| 82 | #endif |
| 83 | |
Lennart Poettering | f4aa9a8 | 2003-12-11 18:56:42 +0000 | [diff] [blame] | 84 | #endif |