Bug Summary

File:root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/chromium/src/third_party/./../../../../../ipc/chromium/src/third_party/libevent/signal.c
Warning:line 284, column 21
Value stored to 'sig' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_c_src_third_party0.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/chromium/src/third_party -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/chromium/src/third_party -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_CONFIG_H -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/ipc/chromium/src/third_party -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/ipc/chromium/src/third_party -I /root/firefox-clang/ipc/chromium/src/third_party/libevent -I /root/firefox-clang/ipc/chromium/src/third_party/libevent/compat -I /root/firefox-clang/ipc/chromium/src/third_party/libevent/include -I /root/firefox-clang/ipc/chromium/src/third_party/libevent/linux -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c Unified_c_src_third_party0.c
1/* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */
2
3/*
4 * Copyright 2000-2007 Niels Provos <provos@citi.umich.edu>
5 * Copyright 2007-2012 Niels Provos and Nick Mathewson
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29#include "event2/event-config.h"
30#include "evconfig-private.h"
31
32#ifdef _WIN32
33#define WIN32_LEAN_AND_MEAN
34#include <winsock2.h>
35#include <windows.h>
36#undef WIN32_LEAN_AND_MEAN
37#endif
38#include <sys/types.h>
39#ifdef EVENT__HAVE_SYS_TIME_H1
40#include <sys/time.h>
41#endif
42#include <sys/queue.h>
43#ifdef EVENT__HAVE_SYS_SOCKET_H1
44#include <sys/socket.h>
45#endif
46#include <signal.h>
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50#ifdef EVENT__HAVE_UNISTD_H1
51#include <unistd.h>
52#endif
53#include <errno(*__errno_location ()).h>
54#ifdef EVENT__HAVE_FCNTL_H1
55#include <fcntl.h>
56#endif
57
58#include "event2/event.h"
59#include "event2/event_struct.h"
60#include "event-internal.h"
61#include "event2/util.h"
62#include "evsignal-internal.h"
63#include "log-internal.h"
64#include "evmap-internal.h"
65#include "evthread-internal.h"
66
67#include "mozilla/Assertions.h"
68
69/*
70 signal.c
71
72 This is the signal-handling implementation we use for backends that don't
73 have a better way to do signal handling. It uses sigaction() or signal()
74 to set a signal handler, and a socket pair to tell the event base when
75
76 Note that I said "the event base" : only one event base can be set up to use
77 this at a time. For historical reasons and backward compatibility, if you
78 add an event for a signal to event_base A, then add an event for a signal
79 (any signal!) to event_base B, event_base B will get informed about the
80 signal, but event_base A won't.
81
82 It would be neat to change this behavior in some future version of Libevent.
83 kqueue already does something far more sensible. We can make all backends
84 on Linux do a reasonable thing using signalfd.
85*/
86
87#ifndef _WIN32
88/* Windows wants us to call our signal handlers as __cdecl. Nobody else
89 * expects you to do anything crazy like this. */
90#ifndef __cdecl
91#define __cdecl
92#endif
93#endif
94
95static int evsig_add(struct event_base *, evutil_socket_tint, short, short, void *);
96static int evsig_del(struct event_base *, evutil_socket_tint, short, short, void *);
97
98static const struct eventop evsigops = {
99 "signal",
100 NULL((void*)0),
101 evsig_add,
102 evsig_del,
103 NULL((void*)0),
104 NULL((void*)0),
105 0, 0, 0
106};
107
108#ifndef EVENT__DISABLE_THREAD_SUPPORT
109/* Lock for evsig_base and evsig_base_n_signals_added fields. */
110static void *evsig_base_lock = NULL((void*)0);
111#endif
112/* The event base that's currently getting informed about signals. */
113static struct event_base *evsig_base = NULL((void*)0);
114/* A copy of evsig_base->sigev_n_signals_added. */
115static int evsig_base_n_signals_added = 0;
116static evutil_socket_tint evsig_base_fd = -1;
117
118static void __cdecl evsig_handler(int sig);
119
120#define EVSIGBASE_LOCK()do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
EVLOCK_LOCK(evsig_base_lock, 0)do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
121#define EVSIGBASE_UNLOCK()do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
EVLOCK_UNLOCK(evsig_base_lock, 0)do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
122
123void
124evsig_set_base_(struct event_base *base)
125{
126 EVSIGBASE_LOCK()do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
;
127 evsig_base = base;
128 evsig_base_n_signals_added = base->sig.ev_n_signals_added;
129 evsig_base_fd = base->sig.ev_signal_pair[1];
130 EVSIGBASE_UNLOCK()do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
;
131}
132
133/* Callback for when the signal handler write a byte to our signaling socket */
134static void
135evsig_cb(evutil_socket_tint fd, short what, void *arg)
136{
137 static char signals[1024];
138 ev_ssize_tssize_t n;
139 int i;
140 int ncaught[NSIG(64 + 1)];
141 struct event_base *base;
142
143 base = arg;
144
145 memset(&ncaught, 0, sizeof(ncaught));
146
147 while (1) {
148#ifdef _WIN32
149 n = recv(fd, signals, sizeof(signals), 0);
150#else
151 n = read(fd, signals, sizeof(signals));
152#endif
153 if (n == -1) {
154 int err = evutil_socket_geterror(fd)((*__errno_location ()));
155 if (! EVUTIL_ERR_RW_RETRIABLE(err)((err) == 4 || ((err) == 11)))
156 event_sock_err(1, fd, "%s: recv", __func____func__);
157 break;
158 } else if (n == 0) {
159 /* XXX warn? */
160 break;
161 }
162 for (i = 0; i < n; ++i) {
163 ev_uint8_tuint8_t sig = signals[i];
164 if (sig < NSIG(64 + 1))
165 ncaught[sig]++;
166 }
167 }
168
169 EVBASE_ACQUIRE_LOCK(base, th_base_lock)do { do { if ((base)->th_base_lock) evthread_lock_fns_.lock
(0, (base)->th_base_lock); } while (0); } while (0)
;
170 for (i = 0; i < NSIG(64 + 1); ++i) {
171 if (ncaught[i])
172 evmap_signal_active_(base, i, ncaught[i]);
173 }
174 EVBASE_RELEASE_LOCK(base, th_base_lock)do { do { if ((base)->th_base_lock) evthread_lock_fns_.unlock
(0, (base)->th_base_lock); } while (0); } while (0)
;
175}
176
177int
178evsig_init_(struct event_base *base)
179{
180 /*
181 * Our signal handler is going to write to one end of the socket
182 * pair to wake up our event loop. The event loop then scans for
183 * signals that got delivered.
184 */
185 if (evutil_make_internal_pipe_(base->sig.ev_signal_pair) == -1) {
186#ifdef _WIN32
187 /* Make this nonfatal on win32, where sometimes people
188 have localhost firewalled. */
189 event_sock_warn(-1, "%s: socketpair", __func____func__);
190#else
191 event_sock_err(1, -1, "%s: socketpair", __func____func__);
192#endif
193 return -1;
194 }
195
196 if (base->sig.sh_old) {
197 mm_free(base->sig.sh_old)event_mm_free_(base->sig.sh_old);
198 }
199 base->sig.sh_old = NULL((void*)0);
200 base->sig.sh_old_max = 0;
201
202 event_assign(&base->sig.ev_signal, base, base->sig.ev_signal_pair[0],
203 EV_READ0x02 | EV_PERSIST0x10, evsig_cb, base);
204
205 base->sig.ev_signal.ev_flagsev_evcallback.evcb_flags |= EVLIST_INTERNAL0x10;
206 event_priority_set(&base->sig.ev_signal, 0);
207
208 base->evsigsel = &evsigops;
209
210 return 0;
211}
212
213/* Helper: set the signal handler for evsignal to handler in base, so that
214 * we can restore the original handler when we clear the current one. */
215int
216evsig_set_handler_(struct event_base *base,
217 int evsignal, void (__cdecl *handler)(int))
218{
219#ifdef EVENT__HAVE_SIGACTION1
220 struct sigaction sa;
221#else
222 ev_sighandler_t sh;
223#endif
224 struct evsig_info *sig = &base->sig;
225 void *p;
226
227 /*
228 * resize saved signal handler array up to the highest signal number.
229 * a dynamic array is used to keep footprint on the low side.
230 */
231 if (evsignal >= sig->sh_old_max) {
232 int new_max = evsignal + 1;
233 event_debug(("%s: evsignal (%d) >= sh_old_max (%d), resizing",do { if ((event_debug_logging_mask_)) { event_debugx_ ("%s: evsignal (%d) >= sh_old_max (%d), resizing"
, __func__, evsignal, sig->sh_old_max); } } while (0)
234 __func__, evsignal, sig->sh_old_max))do { if ((event_debug_logging_mask_)) { event_debugx_ ("%s: evsignal (%d) >= sh_old_max (%d), resizing"
, __func__, evsignal, sig->sh_old_max); } } while (0)
;
235 p = mm_realloc(sig->sh_old, new_max * sizeof(*sig->sh_old))event_mm_realloc_((sig->sh_old), (new_max * sizeof(*sig->
sh_old)))
;
236 if (p == NULL((void*)0)) {
237 event_warn("realloc");
238 return (-1);
239 }
240
241 memset((char *)p + sig->sh_old_max * sizeof(*sig->sh_old),
242 0, (new_max - sig->sh_old_max) * sizeof(*sig->sh_old));
243
244 sig->sh_old_max = new_max;
245 sig->sh_old = p;
246 }
247
248 /* allocate space for previous handler out of dynamic array */
249 sig->sh_old[evsignal] = mm_malloc(sizeof *sig->sh_old[evsignal])event_mm_malloc_(sizeof *sig->sh_old[evsignal]);
250 if (sig->sh_old[evsignal] == NULL((void*)0)) {
251 event_warn("malloc");
252 return (-1);
253 }
254
255 /* save previous handler and setup new handler */
256#ifdef EVENT__HAVE_SIGACTION1
257 memset(&sa, 0, sizeof(sa));
258 sa.sa_handler__sigaction_handler.sa_handler = handler;
259 sa.sa_flags |= SA_RESTART0x10000000;
260 sigfillset(&sa.sa_mask);
261
262 if (sigaction(evsignal, &sa, sig->sh_old[evsignal]) == -1) {
263 event_warn("sigaction");
264 mm_free(sig->sh_old[evsignal])event_mm_free_(sig->sh_old[evsignal]);
265 sig->sh_old[evsignal] = NULL((void*)0);
266 return (-1);
267 }
268#else
269 if ((sh = signal(evsignal, handler)) == SIG_ERR((__sighandler_t) -1)) {
270 event_warn("signal");
271 mm_free(sig->sh_old[evsignal])event_mm_free_(sig->sh_old[evsignal]);
272 sig->sh_old[evsignal] = NULL((void*)0);
273 return (-1);
274 }
275 *sig->sh_old[evsignal] = sh;
276#endif
277
278 return (0);
279}
280
281static int
282evsig_add(struct event_base *base, evutil_socket_tint evsignal, short old, short events, void *p)
283{
284 struct evsig_info *sig = &base->sig;
Value stored to 'sig' during its initialization is never read
285 (void)p;
286
287 MOZ_CRASH("Don't use this; see bug 1616462")do { do { } while (0); MOZ_ReportCrash("" "Don't use this; see bug 1616462"
, "./../../../../../ipc/chromium/src/third_party/libevent/signal.c"
, 287); AnnotateMozCrashReason("MOZ_CRASH(" "Don't use this; see bug 1616462"
")"); do { MOZ_CrashSequence(((void*)0), 287); __attribute__
((nomerge)) abort(); } while (0); } while (0)
;
288
289 EVUTIL_ASSERT(evsignal >= 0 && evsignal < NSIG)do { if (__builtin_expect(!!(!(evsignal >= 0 && evsignal
< (64 + 1))),0)) { event_errx(((int)0xdeaddead), "%s:%d: Assertion %s failed in %s"
, "./../../../../../ipc/chromium/src/third_party/libevent/signal.c"
,289,"evsignal >= 0 && evsignal < NSIG",__func__
); (void)fprintf(stderr, "%s:%d: Assertion %s failed in %s", "./../../../../../ipc/chromium/src/third_party/libevent/signal.c"
,289,"evsignal >= 0 && evsignal < NSIG",__func__
); abort(); } } while (0)
;
290
291 /* catch signals if they happen quickly */
292 EVSIGBASE_LOCK()do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
;
293 if (evsig_base != base && evsig_base_n_signals_added) {
294 event_warnx("Added a signal to event base %p with signals "
295 "already added to event_base %p. Only one can have "
296 "signals at a time with the %s backend. The base with "
297 "the most recently added signal or the most recent "
298 "event_base_loop() call gets preference; do "
299 "not rely on this behavior in future Libevent versions.",
300 base, evsig_base, base->evsel->name);
301 }
302 evsig_base = base;
303 evsig_base_n_signals_added = ++sig->ev_n_signals_added;
304 evsig_base_fd = base->sig.ev_signal_pair[1];
305 EVSIGBASE_UNLOCK()do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
;
306
307 event_debug(("%s: %d: changing signal handler", __func__, (int)evsignal))do { if ((event_debug_logging_mask_)) { event_debugx_ ("%s: %d: changing signal handler"
, __func__, (int)evsignal); } } while (0)
;
308 if (evsig_set_handler_(base, (int)evsignal, evsig_handler) == -1) {
309 goto err;
310 }
311
312
313 if (!sig->ev_signal_added) {
314 if (event_add_nolock_(&sig->ev_signal, NULL((void*)0), 0))
315 goto err;
316 sig->ev_signal_added = 1;
317 }
318
319 return (0);
320
321err:
322 EVSIGBASE_LOCK()do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
;
323 --evsig_base_n_signals_added;
324 --sig->ev_n_signals_added;
325 EVSIGBASE_UNLOCK()do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
;
326 return (-1);
327}
328
329int
330evsig_restore_handler_(struct event_base *base, int evsignal)
331{
332 int ret = 0;
333 struct evsig_info *sig = &base->sig;
334#ifdef EVENT__HAVE_SIGACTION1
335 struct sigaction *sh;
336#else
337 ev_sighandler_t *sh;
338#endif
339
340 if (evsignal >= sig->sh_old_max) {
341 /* Can't actually restore. */
342 /* XXXX.*/
343 return 0;
344 }
345
346 /* restore previous handler */
347 sh = sig->sh_old[evsignal];
348 sig->sh_old[evsignal] = NULL((void*)0);
349#ifdef EVENT__HAVE_SIGACTION1
350 if (sigaction(evsignal, sh, NULL((void*)0)) == -1) {
351 event_warn("sigaction");
352 ret = -1;
353 }
354#else
355 if (signal(evsignal, *sh) == SIG_ERR((__sighandler_t) -1)) {
356 event_warn("signal");
357 ret = -1;
358 }
359#endif
360
361 mm_free(sh)event_mm_free_(sh);
362
363 return ret;
364}
365
366static int
367evsig_del(struct event_base *base, evutil_socket_tint evsignal, short old, short events, void *p)
368{
369 EVUTIL_ASSERT(evsignal >= 0 && evsignal < NSIG)do { if (__builtin_expect(!!(!(evsignal >= 0 && evsignal
< (64 + 1))),0)) { event_errx(((int)0xdeaddead), "%s:%d: Assertion %s failed in %s"
, "./../../../../../ipc/chromium/src/third_party/libevent/signal.c"
,369,"evsignal >= 0 && evsignal < NSIG",__func__
); (void)fprintf(stderr, "%s:%d: Assertion %s failed in %s", "./../../../../../ipc/chromium/src/third_party/libevent/signal.c"
,369,"evsignal >= 0 && evsignal < NSIG",__func__
); abort(); } } while (0)
;
370
371 event_debug(("%s: "EV_SOCK_FMT": restoring signal handler",do { if ((event_debug_logging_mask_)) { event_debugx_ ("%s: "
"%d"": restoring signal handler", __func__, (evsignal)); } } while
(0)
372 __func__, EV_SOCK_ARG(evsignal)))do { if ((event_debug_logging_mask_)) { event_debugx_ ("%s: "
"%d"": restoring signal handler", __func__, (evsignal)); } } while
(0)
;
373
374 EVSIGBASE_LOCK()do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
;
375 --evsig_base_n_signals_added;
376 --base->sig.ev_n_signals_added;
377 EVSIGBASE_UNLOCK()do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
;
378
379 return (evsig_restore_handler_(base, (int)evsignal));
380}
381
382static void __cdecl
383evsig_handler(int sig)
384{
385 int save_errno = errno(*__errno_location ());
386#ifdef _WIN32
387 int socket_errno = EVUTIL_SOCKET_ERROR()((*__errno_location ()));
388#endif
389 ev_uint8_tuint8_t msg;
390
391 if (evsig_base == NULL((void*)0)) {
392 event_warnx(
393 "%s: received signal %d, but have no base configured",
394 __func____func__, sig);
395 return;
396 }
397
398#ifndef EVENT__HAVE_SIGACTION1
399 signal(sig, evsig_handler);
400#endif
401
402 /* Wake up our notification mechanism */
403 msg = sig;
404#ifdef _WIN32
405 send(evsig_base_fd, (char*)&msg, 1, 0);
406#else
407 {
408 int r = write(evsig_base_fd, (char*)&msg, 1);
409 (void)r; /* Suppress 'unused return value' and 'unused var' */
410 }
411#endif
412 errno(*__errno_location ()) = save_errno;
413#ifdef _WIN32
414 EVUTIL_SET_SOCKET_ERROR(socket_errno)do { (*__errno_location ()) = (socket_errno); } while (0);
415#endif
416}
417
418void
419evsig_dealloc_(struct event_base *base)
420{
421 int i = 0;
422 if (base->sig.ev_signal_added) {
423 event_del(&base->sig.ev_signal);
424 base->sig.ev_signal_added = 0;
425 }
426 /* debug event is created in evsig_init_/event_assign even when
427 * ev_signal_added == 0, so unassign is required */
428 event_debug_unassign(&base->sig.ev_signal);
429
430 for (i = 0; i < NSIG(64 + 1); ++i) {
431 if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL((void*)0))
432 evsig_restore_handler_(base, i);
433 }
434 EVSIGBASE_LOCK()do { if (evsig_base_lock) evthread_lock_fns_.lock(0, evsig_base_lock
); } while (0)
;
435 if (base == evsig_base) {
436 evsig_base = NULL((void*)0);
437 evsig_base_n_signals_added = 0;
438 evsig_base_fd = -1;
439 }
440 EVSIGBASE_UNLOCK()do { if (evsig_base_lock) evthread_lock_fns_.unlock(0, evsig_base_lock
); } while (0)
;
441
442 if (base->sig.ev_signal_pair[0] != -1) {
443 evutil_closesocket(base->sig.ev_signal_pair[0]);
444 base->sig.ev_signal_pair[0] = -1;
445 }
446 if (base->sig.ev_signal_pair[1] != -1) {
447 evutil_closesocket(base->sig.ev_signal_pair[1]);
448 base->sig.ev_signal_pair[1] = -1;
449 }
450 base->sig.sh_old_max = 0;
451
452 /* per index frees are handled in evsig_del() */
453 if (base->sig.sh_old) {
454 mm_free(base->sig.sh_old)event_mm_free_(base->sig.sh_old);
455 base->sig.sh_old = NULL((void*)0);
456 }
457}
458
459static void
460evsig_free_globals_locks(void)
461{
462#ifndef EVENT__DISABLE_THREAD_SUPPORT
463 if (evsig_base_lock != NULL((void*)0)) {
464 EVTHREAD_FREE_LOCK(evsig_base_lock, 0)do { void *lock_tmp_ = (evsig_base_lock); if (lock_tmp_ &&
evthread_lock_fns_.free) evthread_lock_fns_.free(lock_tmp_, (
0)); } while (0)
;
465 evsig_base_lock = NULL((void*)0);
466 }
467#endif
468 return;
469}
470
471void
472evsig_free_globals_(void)
473{
474 evsig_free_globals_locks();
475}
476
477#ifndef EVENT__DISABLE_THREAD_SUPPORT
478int
479evsig_global_setup_locks_(const int enable_locks)
480{
481 EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0)do { evsig_base_lock = evthread_setup_global_lock_(evsig_base_lock
, (0), enable_locks); if (!evsig_base_lock) { event_warn("Couldn't allocate %s"
, "evsig_base_lock"); return -1; } } while (0);
;
482 return 0;
483}
484
485#endif