diff options
Diffstat (limited to 'src/util/signal.c')
-rw-r--r-- | src/util/signal.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/util/signal.c b/src/util/signal.c index 3e23f4a59..96e40ba7f 100644 --- a/src/util/signal.c +++ b/src/util/signal.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file util/signal.c | 22 | * @file util/signal.c |
@@ -27,12 +27,10 @@ | |||
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 | ||
33 | struct GNUNET_SIGNAL_Context | 33 | struct GNUNET_SIGNAL_Context { |
34 | { | ||
35 | |||
36 | struct GNUNET_SIGNAL_Context *next; | 34 | struct GNUNET_SIGNAL_Context *next; |
37 | 35 | ||
38 | struct GNUNET_SIGNAL_Context *prev; | 36 | struct GNUNET_SIGNAL_Context *prev; |
@@ -56,7 +54,7 @@ GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL; | |||
56 | #endif | 54 | #endif |
57 | 55 | ||
58 | struct GNUNET_SIGNAL_Context * | 56 | struct GNUNET_SIGNAL_Context * |
59 | GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) | 57 | GNUNET_SIGNAL_handler_install(int signum, GNUNET_SIGNAL_Handler handler) |
60 | { | 58 | { |
61 | struct GNUNET_SIGNAL_Context *ret; | 59 | struct GNUNET_SIGNAL_Context *ret; |
62 | 60 | ||
@@ -64,48 +62,48 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler) | |||
64 | struct sigaction sig; | 62 | struct sigaction sig; |
65 | #endif | 63 | #endif |
66 | 64 | ||
67 | ret = GNUNET_new (struct GNUNET_SIGNAL_Context); | 65 | ret = GNUNET_new(struct GNUNET_SIGNAL_Context); |
68 | ret->sig = signum; | 66 | ret->sig = signum; |
69 | ret->method = handler; | 67 | ret->method = handler; |
70 | #ifndef MINGW | 68 | #ifndef MINGW |
71 | memset (&sig, 0, sizeof (sig)); | 69 | memset(&sig, 0, sizeof(sig)); |
72 | sig.sa_handler = (void *) handler; | 70 | sig.sa_handler = (void *)handler; |
73 | sigemptyset (&sig.sa_mask); | 71 | sigemptyset(&sig.sa_mask); |
74 | #ifdef SA_INTERRUPT | 72 | #ifdef SA_INTERRUPT |
75 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | 73 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ |
76 | #else | 74 | #else |
77 | sig.sa_flags = SA_RESTART; | 75 | sig.sa_flags = SA_RESTART; |
78 | #endif | 76 | #endif |
79 | sigaction (signum, &sig, &ret->oldsig); | 77 | sigaction(signum, &sig, &ret->oldsig); |
80 | #else | 78 | #else |
81 | if (signum == GNUNET_SIGCHLD) | 79 | if (signum == GNUNET_SIGCHLD) |
82 | w32_sigchld_handler = handler; | 80 | w32_sigchld_handler = handler; |
83 | else | 81 | else |
84 | { | ||
85 | __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler); | ||
86 | |||
87 | if (sigret == SIG_ERR) | ||
88 | { | 82 | { |
89 | LOG (GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"), | 83 | __p_sig_fn_t sigret = signal(signum, (__p_sig_fn_t)handler); |
90 | signum, handler, sigret); | 84 | |
85 | if (sigret == SIG_ERR) | ||
86 | { | ||
87 | LOG(GNUNET_ERROR_TYPE_WARNING, _("signal (%d, %p) returned %d.\n"), | ||
88 | signum, handler, sigret); | ||
89 | } | ||
91 | } | 90 | } |
92 | } | ||
93 | #endif | 91 | #endif |
94 | GNUNET_CONTAINER_DLL_insert_tail (sc_head, sc_tail, ret); | 92 | GNUNET_CONTAINER_DLL_insert_tail(sc_head, sc_tail, ret); |
95 | return ret; | 93 | return ret; |
96 | } | 94 | } |
97 | 95 | ||
98 | void | 96 | void |
99 | GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx) | 97 | GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx) |
100 | { | 98 | { |
101 | #ifndef MINGW | 99 | #ifndef MINGW |
102 | struct sigaction sig; | 100 | struct sigaction sig; |
103 | 101 | ||
104 | sigemptyset (&sig.sa_mask); | 102 | sigemptyset(&sig.sa_mask); |
105 | sigaction (ctx->sig, &ctx->oldsig, &sig); | 103 | sigaction(ctx->sig, &ctx->oldsig, &sig); |
106 | #endif | 104 | #endif |
107 | GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, ctx); | 105 | GNUNET_CONTAINER_DLL_remove(sc_head, sc_tail, ctx); |
108 | GNUNET_free (ctx); | 106 | GNUNET_free(ctx); |
109 | } | 107 | } |
110 | 108 | ||
111 | 109 | ||
@@ -117,16 +115,16 @@ GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx) | |||
117 | * @param sig the signal to raise | 115 | * @param sig the signal to raise |
118 | */ | 116 | */ |
119 | void | 117 | void |
120 | GNUNET_SIGNAL_raise (const int sig) | 118 | GNUNET_SIGNAL_raise(const int sig) |
121 | { | 119 | { |
122 | struct GNUNET_SIGNAL_Context *ctx; | 120 | struct GNUNET_SIGNAL_Context *ctx; |
123 | 121 | ||
124 | for (ctx = sc_head; NULL != ctx; ctx = ctx->next) | 122 | for (ctx = sc_head; NULL != ctx; ctx = ctx->next) |
125 | { | 123 | { |
126 | if (sig != ctx->sig) | 124 | if (sig != ctx->sig) |
127 | continue; | 125 | continue; |
128 | if (NULL == ctx->method) | 126 | if (NULL == ctx->method) |
129 | continue; | 127 | continue; |
130 | ctx->method (); | 128 | ctx->method(); |
131 | } | 129 | } |
132 | } | 130 | } |