summaryrefslogtreecommitdiff
path: root/src/util/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/signal.c')
-rw-r--r--src/util/signal.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/util/signal.c b/src/util/signal.c
index ada4db5ad..fd7eecdd3 100644
--- a/src/util/signal.c
+++ b/src/util/signal.c
@@ -27,10 +27,11 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30#define LOG(kind, ...) GNUNET_log_from(kind, "util-signal", __VA_ARGS__) 30#define LOG(kind, ...) GNUNET_log_from (kind, "util-signal", __VA_ARGS__)
31 31
32 32
33struct GNUNET_SIGNAL_Context { 33struct GNUNET_SIGNAL_Context
34{
34 struct GNUNET_SIGNAL_Context *next; 35 struct GNUNET_SIGNAL_Context *next;
35 36
36 struct GNUNET_SIGNAL_Context *prev; 37 struct GNUNET_SIGNAL_Context *prev;
@@ -47,40 +48,40 @@ static struct GNUNET_SIGNAL_Context *sc_head;
47static struct GNUNET_SIGNAL_Context *sc_tail; 48static struct GNUNET_SIGNAL_Context *sc_tail;
48 49
49struct GNUNET_SIGNAL_Context * 50struct GNUNET_SIGNAL_Context *
50GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) 51GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
51{ 52{
52 struct GNUNET_SIGNAL_Context *ret; 53 struct GNUNET_SIGNAL_Context *ret;
53 54
54 struct sigaction sig; 55 struct sigaction sig;
55 56
56 ret = GNUNET_new(struct GNUNET_SIGNAL_Context); 57 ret = GNUNET_new (struct GNUNET_SIGNAL_Context);
57 ret->sig = signum; 58 ret->sig = signum;
58 ret->method = handler; 59 ret->method = handler;
59 60
60 memset(&sig, 0, sizeof(sig)); 61 memset (&sig, 0, sizeof(sig));
61 sig.sa_handler = (void *)handler; 62 sig.sa_handler = (void *) handler;
62 sigemptyset(&sig.sa_mask); 63 sigemptyset (&sig.sa_mask);
63#ifdef SA_INTERRUPT 64#ifdef SA_INTERRUPT
64 sig.sa_flags = SA_INTERRUPT; /* SunOS */ 65 sig.sa_flags = SA_INTERRUPT; /* SunOS */
65#else 66#else
66 sig.sa_flags = SA_RESTART; 67 sig.sa_flags = SA_RESTART;
67#endif 68#endif
68 sigaction(signum, &sig, &ret->oldsig); 69 sigaction (signum, &sig, &ret->oldsig);
69 70
70 GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret); 71 GNUNET_CONTAINER_DLL_insert_tail (sc_head, sc_tail, ret);
71 return ret; 72 return ret;
72} 73}
73 74
74void 75void
75GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx) 76GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx)
76{ 77{
77 struct sigaction sig; 78 struct sigaction sig;
78 79
79 sigemptyset(&sig.sa_mask); 80 sigemptyset (&sig.sa_mask);
80 sigaction(ctx->sig, &ctx->oldsig, &sig); 81 sigaction (ctx->sig, &ctx->oldsig, &sig);
81 82
82 GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx); 83 GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, ctx);
83 GNUNET_free(ctx); 84 GNUNET_free (ctx);
84} 85}
85 86
86 87
@@ -92,16 +93,16 @@ GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
92 * @param sig the signal to raise 93 * @param sig the signal to raise
93 */ 94 */
94void 95void
95GNUNET_SIGNAL_raise(const int sig) 96GNUNET_SIGNAL_raise (const int sig)
96{ 97{
97 struct GNUNET_SIGNAL_Context *ctx; 98 struct GNUNET_SIGNAL_Context *ctx;
98 99
99 for (ctx = sc_head; NULL != ctx; ctx = ctx->next) 100 for (ctx = sc_head; NULL != ctx; ctx = ctx->next)
100 { 101 {
101 if (sig != ctx->sig) 102 if (sig != ctx->sig)
102 continue; 103 continue;
103 if (NULL == ctx->method) 104 if (NULL == ctx->method)
104 continue; 105 continue;
105 ctx->method(); 106 ctx->method ();
106 } 107 }
107} 108}