blob: 7c03017b507f283a8f8ef53c9f9ea6b650e740a1 [file] [log] [blame]
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +00001#ifndef foodexechfoo
2#define foodexechfoo
3
Lennart Poettering7892e9b2008-07-28 20:50:57 +02004/***
5 This file is part of libdaemon.
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +00006
Lennart Poettering7892e9b2008-07-28 20:50:57 +02007 Copyright 2003-2008 Lennart Poettering
8
Brandon Philips0630da02012-08-29 17:42:24 -07009 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 Poettering7892e9b2008-07-28 20:50:57 +020015
Brandon Philips0630da02012-08-29 17:42:24 -070016 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
Lennart Poettering7892e9b2008-07-28 20:50:57 +020018
Brandon Philips0630da02012-08-29 17:42:24 -070019 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 Poettering7892e9b2008-07-28 20:50:57 +020027***/
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000028
Lennart Poetteringb45cd332007-06-11 15:16:09 +000029#include <stdarg.h>
30
Lennart Poetteringfeb9b772004-11-12 15:22:45 +000031#ifdef __cplusplus
32extern "C" {
33#endif
34
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000035/** \file
36 *
37 * Contains a robust API for running sub processes with STDOUT and
38 * STDERR redirected to syslog
39 */
40
Lennart Poettering1368b792009-10-18 04:22:26 +020041/** This variable is defined to 1 iff daemon_exec() is supported.
42 * @since 0.4
43 * @see daemon_exec() */
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000044#define DAEMON_EXEC_AVAILABLE 1
45
Lennart Poettering5be2d892007-06-11 15:42:31 +000046#if defined(__GNUC__) && ! defined(DAEMON_GCC_SENTINEL)
Lennart Poettering5be2d892007-06-11 15:42:31 +000047#define DAEMON_GCC_SENTINEL __attribute__ ((sentinel))
48#else
Lennart Poettering1368b792009-10-18 04:22:26 +020049/** A macro for making use of GCCs printf compilation warnings */
Lennart Poettering5be2d892007-06-11 15:42:31 +000050#define DAEMON_GCC_SENTINEL
51#endif
Lennart Poettering7892e9b2008-07-28 20:50:57 +020052
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000053/** 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 Poettering8f34edf2004-01-10 18:45:49 +000056 * child finishes and all child output (either STDOUT or STDIN) has
Lennart Poettering5e885532005-09-10 09:52:24 +000057 * been written to syslog. Running this function requires that
Lennart Poettering57855da2007-06-11 15:34:47 +000058 * daemon_signal() has been called with SIGCHLD as argument.
Lennart Poettering7892e9b2008-07-28 20:50:57 +020059 *
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000060 * @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 Poettering1368b792009-10-18 04:22:26 +020065 * @since 0.4
66 * @see DAEMON_EXEC_AVAILABLE
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000067 */
Lennart Poettering5be2d892007-06-11 15:42:31 +000068int daemon_exec(const char *dir, int *ret, const char *prog, ...) DAEMON_GCC_SENTINEL;
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000069
Lennart Poettering1368b792009-10-18 04:22:26 +020070/** This variable is defined to 1 iff daemon_execv() is supported.
71 * @since 0.11
72 * @see daemon_execv() */
Lennart Poetteringb45cd332007-06-11 15:16:09 +000073#define DAEMON_EXECV_AVAILABLE 1
74
Lennart Poettering1368b792009-10-18 04:22:26 +020075/** The same as daemon_exec, but without variadic arguments
76 * @since 0.11
77 * @see DAEMON_EXECV_AVAILABLE */
Lennart Poetteringb45cd332007-06-11 15:16:09 +000078int daemon_execv(const char *dir, int *ret, const char *prog, va_list ap);
Lennart Poettering7892e9b2008-07-28 20:50:57 +020079
Lennart Poetteringfeb9b772004-11-12 15:22:45 +000080#ifdef __cplusplus
81}
82#endif
83
Lennart Poetteringf4aa9a82003-12-11 18:56:42 +000084#endif