dpid.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef foodaemonpidhfoo
  2. #define foodaemonpidhfoo
  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 <sys/types.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /** \file
  23. *
  24. * Contains an API for manipulating PID files.
  25. */
  26. /** Prototype of a function for generating the name of a PID file.
  27. */
  28. typedef const char* (*daemon_pid_file_proc_t)(void);
  29. /** Identification string for the PID file name, only used when
  30. * daemon_pid_file_proc is set to daemon_pid_file_proc_default(). Use
  31. * daemon_ident_from_argv0() to generate an identification string from
  32. * argv[0]
  33. */
  34. extern const char *daemon_pid_file_ident;
  35. /** A function pointer which is used to generate the name of the PID
  36. * file to manipulate. Points to daemon_pid_file_proc_default() by
  37. * default.
  38. */
  39. extern daemon_pid_file_proc_t daemon_pid_file_proc;
  40. /** A function for creating a pid file name from
  41. * daemon_pid_file_ident
  42. * @return The PID file path
  43. */
  44. const char *daemon_pid_file_proc_default(void);
  45. /** Creates PID pid file for the current process
  46. * @return zero on success, nonzero on failure
  47. */
  48. int daemon_pid_file_create(void);
  49. /** Removes the PID file of the current process
  50. * @return zero on success, nonzero on failure
  51. */
  52. int daemon_pid_file_remove(void);
  53. /** Returns the PID file of a running daemon, if available
  54. * @return The PID or negative on failure
  55. */
  56. pid_t daemon_pid_file_is_running(void);
  57. /** Kills a running daemon, if available
  58. * @param s The signal to send
  59. * @return zero on success, nonzero on failure
  60. */
  61. int daemon_pid_file_kill(int s);
  62. /** This variable is defined to 1 iff daemon_pid_file_kill_wait() is supported.
  63. * @since 0.3
  64. * @see daemon_pid_file_kill_wait() */
  65. #define DAEMON_PID_FILE_KILL_WAIT_AVAILABLE 1
  66. /** Similar to daemon_pid_file_kill() but waits until the process
  67. * died. This functions is new in libdaemon 0.3. The macro
  68. * DAEMON_PID_FILE_KILL_WAIT_AVAILABLE is defined iff libdaemon
  69. * supports this function.
  70. *
  71. * @param s The signal to send
  72. * @param m Seconds to wait at maximum
  73. * @return zero on success, nonzero on failure (timeout condition is considered a failure)
  74. * @since 0.3
  75. * @see DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
  76. */
  77. int daemon_pid_file_kill_wait(int s, int m);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif