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.c27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/util/signal.c b/src/util/signal.c
index 96e40ba7f..ada4db5ad 100644
--- a/src/util/signal.c
+++ b/src/util/signal.c
@@ -39,33 +39,24 @@ struct GNUNET_SIGNAL_Context {
39 39
40 GNUNET_SIGNAL_Handler method; 40 GNUNET_SIGNAL_Handler method;
41 41
42#ifndef MINGW
43 struct sigaction oldsig; 42 struct sigaction oldsig;
44#endif
45}; 43};
46 44
47static struct GNUNET_SIGNAL_Context *sc_head; 45static struct GNUNET_SIGNAL_Context *sc_head;
48 46
49static struct GNUNET_SIGNAL_Context *sc_tail; 47static struct GNUNET_SIGNAL_Context *sc_tail;
50 48
51
52#ifdef WINDOWS
53GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL;
54#endif
55
56struct GNUNET_SIGNAL_Context * 49struct GNUNET_SIGNAL_Context *
57GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) 50GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler)
58{ 51{
59 struct GNUNET_SIGNAL_Context *ret; 52 struct GNUNET_SIGNAL_Context *ret;
60 53
61#ifndef MINGW
62 struct sigaction sig; 54 struct sigaction sig;
63#endif
64 55
65 ret = GNUNET_new(struct GNUNET_SIGNAL_Context); 56 ret = GNUNET_new(struct GNUNET_SIGNAL_Context);
66 ret->sig = signum; 57 ret->sig = signum;
67 ret->method = handler; 58 ret->method = handler;
68#ifndef MINGW 59
69 memset(&sig, 0, sizeof(sig)); 60 memset(&sig, 0, sizeof(sig));
70 sig.sa_handler = (void *)handler; 61 sig.sa_handler = (void *)handler;
71 sigemptyset(&sig.sa_mask); 62 sigemptyset(&sig.sa_mask);
@@ -75,20 +66,7 @@ GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler)
75 sig.sa_flags = SA_RESTART; 66 sig.sa_flags = SA_RESTART;
76#endif 67#endif
77 sigaction(signum, &sig, &ret->oldsig); 68 sigaction(signum, &sig, &ret->oldsig);
78#else
79 if (signum == GNUNET_SIGCHLD)
80 w32_sigchld_handler = handler;
81 else
82 {
83 __p_sig_fn_t sigret = signal(signum, (__p_sig_fn_t)handler);
84 69
85 if (sigret == SIG_ERR)
86 {
87 LOG(GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"),
88 signum, handler, sigret);
89 }
90 }
91#endif
92 GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret); 70 GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret);
93 return ret; 71 return ret;
94} 72}
@@ -96,12 +74,11 @@ GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler)
96void 74void
97GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx) 75GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
98{ 76{
99#ifndef MINGW
100 struct sigaction sig; 77 struct sigaction sig;
101 78
102 sigemptyset(&sig.sa_mask); 79 sigemptyset(&sig.sa_mask);
103 sigaction(ctx->sig, &ctx->oldsig, &sig); 80 sigaction(ctx->sig, &ctx->oldsig, &sig);
104#endif 81
105 GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx); 82 GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx);
106 GNUNET_free(ctx); 83 GNUNET_free(ctx);
107} 84}