• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef foodaemonsignalhfoo
2 #define foodaemonsignalhfoo
3 
4 /***
5   This file is part of libdaemon.
6 
7   Copyright 2003-2008 Lennart Poettering
8 
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:
15 
16   The above copyright notice and this permission notice shall be included in
17   all copies or substantial portions of the Software.
18 
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 
27 ***/
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /** \file
34  *
35  * Contains the API for serializing signals to a pipe for
36  * usage with select() or poll().
37  *
38  * You should register all signals you
39  * wish to handle with select() in your main loop with
40  * daemon_signal_init() or daemon_signal_install(). After that you
41  * should sleep on the file descriptor returned by daemon_signal_fd()
42  * and get the next signal recieved with daemon_signal_next(). You
43  * should call daemon_signal_done() before exiting.
44  */
45 
46 /** Installs signal handlers for the specified signals
47  * @param s, ... The signals to install handlers for. The list should be terminated by 0
48  * @return zero on success, nonzero on failure
49  */
50 int daemon_signal_init(int s, ...);
51 
52 /** Install a  signal handler for the specified signal
53  * @param s The signalto install handler for
54  * @return zero onsuccess,nonzero on failure
55  */
56 int daemon_signal_install(int s);
57 
58 /** Free resources of signal handling, should be called before daemon exit
59  */
60 void daemon_signal_done(void);
61 
62 /** Return the next signal recieved. This function will not
63  * block. Instead it returns 0 if no signal is queued.
64  * @return The next queued signal if one is queued, zero if none is
65  * queued, negative on failure.
66  */
67 int daemon_signal_next(void);
68 
69 /** Return the file descriptor the daemon should select() on for
70  * reading. Whenever the descriptor is ready you should call
71  * daemon_signal_next() to get the next signal queued.
72  * @return The file descriptor or negative on failure
73  */
74 int daemon_signal_fd(void);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif
81