fix bad free
[oweals/gnunet.git] / src / include / gnunet_signal_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Christian Grothoff
21  *
22  * @file
23  * Functions related to signals
24  *
25  * @defgroup signal  Signal library
26  * Manage signal handlers.
27  * @{
28  */
29
30 #ifndef GNUNET_SIGNAL_LIB_H
31 #define GNUNET_SIGNAL_LIB_H
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #if 0                           /* keep Emacsens' auto-indent happy */
37 }
38 #endif
39 #endif
40
41 /**
42  * Context created when a signal handler is installed;
43  * can be used to restore it to the previous state later.
44  */
45 struct GNUNET_SIGNAL_Context;
46
47
48 /**
49  * A signal handler.  Since different OSes have different signatures
50  * for their handlers, the API only gives the most restrictive
51  * signature -- no arguments, no return value.  Note that this will
52  * work even if the OS expects a function with arguments.  However,
53  * the implementation must guarantee that this handler is not called
54  * for signals other than the one that it has been registered for.
55  */
56 typedef void
57 (*GNUNET_SIGNAL_Handler) (void);
58
59
60 /**
61  * Install a signal handler that will be run if the
62  * given signal is received.
63  *
64  * @param signal the number of the signal
65  * @param handler the function to call
66  * @return context that can be used to restore, NULL on error
67  */
68 struct GNUNET_SIGNAL_Context *
69 GNUNET_SIGNAL_handler_install (int signal,
70                                GNUNET_SIGNAL_Handler handler);
71
72
73 /**
74  * Uninstall a previously installed signal hander.
75  *
76  * @param ctx context that was returned when the
77  *            signal handler was installed
78  */
79 void
80 GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx);
81
82
83 /**
84  * Raise the given signal by calling the installed signal handlers.  This will
85  * not use the @em raise() system call but only calls the handlers registered
86  * through GNUNET_SIGNAL_handler_install().
87  *
88  * @param sig the signal to raise
89  */
90 void
91 GNUNET_SIGNAL_raise (const int sig);
92
93
94 #if 0                           /* keep Emacsens' auto-indent happy */
95 {
96 #endif
97 #ifdef __cplusplus
98 }
99 #endif
100
101 /* ifndef GNUNET_SIGNAL_LIB_H */
102 #endif
103
104 /** @} */  /* end of group */
105
106 /* end of gnunet_signal_lib.h */