dexec.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef foodexechfoo
  2. #define foodexechfoo
  3. /***
  4. This file is part of libdaemon.
  5. Copyright 2003-2008 Lennart Poettering
  6. libdaemon is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as
  8. published by the Free Software Foundation, either version 2.1 of the
  9. License, or (at your option) any later version.
  10. libdaemon is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with libdaemon. If not, see
  16. <http://www.gnu.org/licenses/>.
  17. ***/
  18. #include <stdarg.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /** \file
  23. *
  24. * Contains a robust API for running sub processes with STDOUT and
  25. * STDERR redirected to syslog
  26. */
  27. /** This variable is defined to 1 iff daemon_exec() is supported.
  28. * @since 0.4
  29. * @see daemon_exec() */
  30. #define DAEMON_EXEC_AVAILABLE 1
  31. #if defined(__GNUC__) && ! defined(DAEMON_GCC_SENTINEL)
  32. #define DAEMON_GCC_SENTINEL __attribute__ ((sentinel))
  33. #else
  34. /** A macro for making use of GCCs printf compilation warnings */
  35. #define DAEMON_GCC_SENTINEL
  36. #endif
  37. /** Run the specified executable with the specified arguments in the
  38. * specified directory and return the return value of the program in
  39. * the specified pointer. The calling process is blocked until the
  40. * child finishes and all child output (either STDOUT or STDIN) has
  41. * been written to syslog. Running this function requires that
  42. * daemon_signal() has been called with SIGCHLD as argument.
  43. *
  44. * @param dir Working directory for the process.
  45. * @param ret A pointer to an integer to write the return value of the program to.
  46. * @param prog The path to the executable
  47. * @param ... The arguments to be passed to the program, followed by a (char *) NULL
  48. * @return Nonzero on failure, zero on success
  49. * @since 0.4
  50. * @see DAEMON_EXEC_AVAILABLE
  51. */
  52. int daemon_exec(const char *dir, int *ret, const char *prog, ...) DAEMON_GCC_SENTINEL;
  53. /** This variable is defined to 1 iff daemon_execv() is supported.
  54. * @since 0.11
  55. * @see daemon_execv() */
  56. #define DAEMON_EXECV_AVAILABLE 1
  57. /** The same as daemon_exec, but without variadic arguments
  58. * @since 0.11
  59. * @see DAEMON_EXECV_AVAILABLE */
  60. int daemon_execv(const char *dir, int *ret, const char *prog, va_list ap);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif