dsignal.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef foodaemonsignalhfoo
  2. #define foodaemonsignalhfoo
  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. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /** \file
  22. *
  23. * Contains the API for serializing signals to a pipe for
  24. * usage with select() or poll().
  25. *
  26. * You should register all signals you
  27. * wish to handle with select() in your main loop with
  28. * daemon_signal_init() or daemon_signal_install(). After that you
  29. * should sleep on the file descriptor returned by daemon_signal_fd()
  30. * and get the next signal recieved with daemon_signal_next(). You
  31. * should call daemon_signal_done() before exiting.
  32. */
  33. /** Installs signal handlers for the specified signals
  34. * @param s, ... The signals to install handlers for. The list should be terminated by 0
  35. * @return zero on success, nonzero on failure
  36. */
  37. int daemon_signal_init(int s, ...);
  38. /** Install a signal handler for the specified signal
  39. * @param s The signalto install handler for
  40. * @return zero onsuccess,nonzero on failure
  41. */
  42. int daemon_signal_install(int s);
  43. /** Free resources of signal handling, should be called before daemon exit
  44. */
  45. void daemon_signal_done(void);
  46. /** Return the next signal recieved. This function will not
  47. * block. Instead it returns 0 if no signal is queued.
  48. * @return The next queued signal if one is queued, zero if none is
  49. * queued, negative on failure.
  50. */
  51. int daemon_signal_next(void);
  52. /** Return the file descriptor the daemon should select() on for
  53. * reading. Whenever the descriptor is ready you should call
  54. * daemon_signal_next() to get the next signal queued.
  55. * @return The file descriptor or negative on failure
  56. */
  57. int daemon_signal_fd(void);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif