diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-11-28 13:00:55 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-11-28 13:00:55 +0000 |
commit | 395ccb4e9581ac7a54c8666371275d2ae90fcca0 (patch) | |
tree | 5ea246351d2622f6b16ae0d0befa249cfb25ee4f /src | |
parent | 37566e067645bf881b170796251a14d8d20202b8 (diff) | |
download | gnunet-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')
-rw-r--r-- | src/include/gnunet_signal_lib.h | 11 | ||||
-rw-r--r-- | src/util/os_priority.c | 2 | ||||
-rw-r--r-- | src/util/signal.c | 35 |
3 files changed, 47 insertions, 1 deletions
diff --git a/src/include/gnunet_signal_lib.h b/src/include/gnunet_signal_lib.h index 04037b4ca..32f8963e0 100644 --- a/src/include/gnunet_signal_lib.h +++ b/src/include/gnunet_signal_lib.h | |||
@@ -72,6 +72,17 @@ void | |||
72 | GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx); | 72 | GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx); |
73 | 73 | ||
74 | 74 | ||
75 | /** | ||
76 | * Raise the given signal by calling the installed signal handlers. This will | ||
77 | * not use the @em raise() system call but only calls the handlers registered | ||
78 | * through GNUNET_SIGNAL_handler_install(). | ||
79 | * | ||
80 | * @param sig the signal to raise | ||
81 | */ | ||
82 | void | ||
83 | GNUNET_SIGNAL_raise (const int sig); | ||
84 | |||
85 | |||
75 | #if 0 /* keep Emacsens' auto-indent happy */ | 86 | #if 0 /* keep Emacsens' auto-indent happy */ |
76 | { | 87 | { |
77 | #endif | 88 | #endif |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 1466ce059..d772e3c87 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -107,7 +107,7 @@ parent_control_handler (void *cls, | |||
107 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 107 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
108 | control_pipe, &parent_control_handler, | 108 | control_pipe, &parent_control_handler, |
109 | control_pipe); | 109 | control_pipe); |
110 | raise ((int) sig); | 110 | GNUNET_SIGNAL_raise ((int) sig); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
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 | ||
33 | struct GNUNET_SIGNAL_Context | 33 | struct 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 | ||
49 | static struct GNUNET_SIGNAL_Context *sc_head; | ||
50 | |||
51 | static struct GNUNET_SIGNAL_Context *sc_tail; | ||
52 | |||
53 | |||
44 | #ifdef WINDOWS | 54 | #ifdef WINDOWS |
45 | GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL; | 55 | GNUNET_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 | */ | ||
119 | void | ||
120 | GNUNET_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 | } | ||