aboutsummaryrefslogtreecommitdiff
path: root/src/util/signal.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-11-28 13:00:55 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-11-28 13:00:55 +0000
commit395ccb4e9581ac7a54c8666371275d2ae90fcca0 (patch)
tree5ea246351d2622f6b16ae0d0befa249cfb25ee4f /src/util/signal.c
parent37566e067645bf881b170796251a14d8d20202b8 (diff)
downloadgnunet-395ccb4e9581ac7a54c8666371275d2ae90fcca0.tar.gz
gnunet-395ccb4e9581ac7a54c8666371275d2ae90fcca0.zip
- raise a signal after receiving it from the control pipe by calling the respective callback registered with GNUNET_SIGNAL_handler_install().
Diffstat (limited to 'src/util/signal.c')
-rw-r--r--src/util/signal.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/util/signal.c b/src/util/signal.c
index edce5f653..92042018f 100644
--- a/src/util/signal.c
+++ b/src/util/signal.c
@@ -32,6 +32,11 @@
32 32
33struct GNUNET_SIGNAL_Context 33struct GNUNET_SIGNAL_Context
34{ 34{
35
36 struct GNUNET_SIGNAL_Context *next;
37
38 struct GNUNET_SIGNAL_Context *prev;
39
35 int sig; 40 int sig;
36 41
37 GNUNET_SIGNAL_Handler method; 42 GNUNET_SIGNAL_Handler method;
@@ -41,6 +46,11 @@ struct GNUNET_SIGNAL_Context
41#endif 46#endif
42}; 47};
43 48
49static struct GNUNET_SIGNAL_Context *sc_head;
50
51static struct GNUNET_SIGNAL_Context *sc_tail;
52
53
44#ifdef WINDOWS 54#ifdef WINDOWS
45GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL; 55GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL;
46#endif 56#endif
@@ -81,6 +91,7 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
81 } 91 }
82 } 92 }
83#endif 93#endif
94 GNUNET_CONTAINER_DLL_insert_tail (sc_head, sc_tail, ret);
84 return ret; 95 return ret;
85} 96}
86 97
@@ -93,5 +104,29 @@ GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx)
93 sigemptyset (&sig.sa_mask); 104 sigemptyset (&sig.sa_mask);
94 sigaction (ctx->sig, &ctx->oldsig, &sig); 105 sigaction (ctx->sig, &ctx->oldsig, &sig);
95#endif 106#endif
107 GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, ctx);
96 GNUNET_free (ctx); 108 GNUNET_free (ctx);
97} 109}
110
111
112/**
113 * Raise the given signal by calling the installed signal handlers. This will
114 * not use the @em raise() system call but only calls the handlers registered
115 * through GNUNET_SIGNAL_handler_install().
116 *
117 * @param sig the signal to raise
118 */
119void
120GNUNET_SIGNAL_raise (const int sig)
121{
122 struct GNUNET_SIGNAL_Context *ctx;
123
124 for (ctx = sc_head; NULL != sc_head; ctx = ctx->next)
125 {
126 if (sig != ctx->sig)
127 continue;
128 if (NULL == ctx->method)
129 continue;
130 ctx->method ();
131 }
132}