Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: third_party/libevent/signal.c

Issue 412006: posix: upgrade libevent from 1.4.7 to 1.4.13 (Closed)
Patch Set: better readme Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ 1 /* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */
2 2
3 /* 3 /*
4 * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu> 4 * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "log.h" 64 #include "log.h"
65 65
66 struct event_base *evsignal_base = NULL; 66 struct event_base *evsignal_base = NULL;
67 67
68 static void evsignal_handler(int sig); 68 static void evsignal_handler(int sig);
69 69
70 /* Callback for when the signal handler write a byte to our signaling socket */ 70 /* Callback for when the signal handler write a byte to our signaling socket */
71 static void 71 static void
72 evsignal_cb(int fd, short what, void *arg) 72 evsignal_cb(int fd, short what, void *arg)
73 { 73 {
74 » static char signals[100]; 74 » static char signals[1];
75 #ifdef WIN32 75 #ifdef WIN32
76 SSIZE_T n; 76 SSIZE_T n;
77 #else 77 #else
78 ssize_t n; 78 ssize_t n;
79 #endif 79 #endif
80 80
81 n = recv(fd, signals, sizeof(signals), 0); 81 n = recv(fd, signals, sizeof(signals), 0);
82 if (n == -1) 82 if (n == -1)
83 event_err(1, "%s: read", __func__); 83 event_err(1, "%s: read", __func__);
84 } 84 }
85 85
86 #ifdef HAVE_SETFD 86 #ifdef HAVE_SETFD
87 #define FD_CLOSEONEXEC(x) do { \ 87 #define FD_CLOSEONEXEC(x) do { \
88 if (fcntl(x, F_SETFD, 1) == -1) \ 88 if (fcntl(x, F_SETFD, 1) == -1) \
89 event_warn("fcntl(%d, F_SETFD)", x); \ 89 event_warn("fcntl(%d, F_SETFD)", x); \
90 } while (0) 90 } while (0)
91 #else 91 #else
92 #define FD_CLOSEONEXEC(x) 92 #define FD_CLOSEONEXEC(x)
93 #endif 93 #endif
94 94
95 void 95 int
96 evsignal_init(struct event_base *base) 96 evsignal_init(struct event_base *base)
97 { 97 {
98 int i; 98 int i;
99 99
100 /* 100 /*
101 * Our signal handler is going to write to one end of the socket 101 * Our signal handler is going to write to one end of the socket
102 * pair to wake up our event loop. The event loop then scans for 102 * pair to wake up our event loop. The event loop then scans for
103 * signals that got delivered. 103 * signals that got delivered.
104 */ 104 */
105 if (evutil_socketpair( 105 if (evutil_socketpair(
106 » » AF_UNIX, SOCK_STREAM, 0, base->sig.ev_signal_pair) == -1) 106 » » AF_UNIX, SOCK_STREAM, 0, base->sig.ev_signal_pair) == -1) {
107 #ifdef WIN32
108 » » /* Make this nonfatal on win32, where sometimes people
109 » » have localhost firewalled. */
110 » » event_warn("%s: socketpair", __func__);
111 #else
107 event_err(1, "%s: socketpair", __func__); 112 event_err(1, "%s: socketpair", __func__);
113 #endif
114 return -1;
115 }
108 116
109 FD_CLOSEONEXEC(base->sig.ev_signal_pair[0]); 117 FD_CLOSEONEXEC(base->sig.ev_signal_pair[0]);
110 FD_CLOSEONEXEC(base->sig.ev_signal_pair[1]); 118 FD_CLOSEONEXEC(base->sig.ev_signal_pair[1]);
111 base->sig.sh_old = NULL; 119 base->sig.sh_old = NULL;
112 base->sig.sh_old_max = 0; 120 base->sig.sh_old_max = 0;
113 base->sig.evsignal_caught = 0; 121 base->sig.evsignal_caught = 0;
114 memset(&base->sig.evsigcaught, 0, sizeof(sig_atomic_t)*NSIG); 122 memset(&base->sig.evsigcaught, 0, sizeof(sig_atomic_t)*NSIG);
115 /* initialize the queues for all events */ 123 /* initialize the queues for all events */
116 for (i = 0; i < NSIG; ++i) 124 for (i = 0; i < NSIG; ++i)
117 TAILQ_INIT(&base->sig.evsigevents[i]); 125 TAILQ_INIT(&base->sig.evsigevents[i]);
118 126
119 evutil_make_socket_nonblocking(base->sig.ev_signal_pair[0]); 127 evutil_make_socket_nonblocking(base->sig.ev_signal_pair[0]);
120 128
121 event_set(&base->sig.ev_signal, base->sig.ev_signal_pair[1], 129 event_set(&base->sig.ev_signal, base->sig.ev_signal_pair[1],
122 EV_READ | EV_PERSIST, evsignal_cb, &base->sig.ev_signal); 130 EV_READ | EV_PERSIST, evsignal_cb, &base->sig.ev_signal);
123 base->sig.ev_signal.ev_base = base; 131 base->sig.ev_signal.ev_base = base;
124 base->sig.ev_signal.ev_flags |= EVLIST_INTERNAL; 132 base->sig.ev_signal.ev_flags |= EVLIST_INTERNAL;
133
134 return 0;
125 } 135 }
126 136
127 /* Helper: set the signal handler for evsignal to handler in base, so that 137 /* Helper: set the signal handler for evsignal to handler in base, so that
128 * we can restore the original handler when we clear the current one. */ 138 * we can restore the original handler when we clear the current one. */
129 int 139 int
130 _evsignal_set_handler(struct event_base *base, 140 _evsignal_set_handler(struct event_base *base,
131 int evsignal, void (*handler)(int)) 141 int evsignal, void (*handler)(int))
132 { 142 {
133 #ifdef HAVE_SIGACTION 143 #ifdef HAVE_SIGACTION
134 struct sigaction sa; 144 struct sigaction sa;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 struct evsignal_info *sig = &base->sig; 313 struct evsignal_info *sig = &base->sig;
304 struct event *ev, *next_ev; 314 struct event *ev, *next_ev;
305 sig_atomic_t ncalls; 315 sig_atomic_t ncalls;
306 int i; 316 int i;
307 317
308 base->sig.evsignal_caught = 0; 318 base->sig.evsignal_caught = 0;
309 for (i = 1; i < NSIG; ++i) { 319 for (i = 1; i < NSIG; ++i) {
310 ncalls = sig->evsigcaught[i]; 320 ncalls = sig->evsigcaught[i];
311 if (ncalls == 0) 321 if (ncalls == 0)
312 continue; 322 continue;
323 sig->evsigcaught[i] -= ncalls;
313 324
314 for (ev = TAILQ_FIRST(&sig->evsigevents[i]); 325 for (ev = TAILQ_FIRST(&sig->evsigevents[i]);
315 ev != NULL; ev = next_ev) { 326 ev != NULL; ev = next_ev) {
316 next_ev = TAILQ_NEXT(ev, ev_signal_next); 327 next_ev = TAILQ_NEXT(ev, ev_signal_next);
317 if (!(ev->ev_events & EV_PERSIST)) 328 if (!(ev->ev_events & EV_PERSIST))
318 event_del(ev); 329 event_del(ev);
319 event_active(ev, EV_SIGNAL, ncalls); 330 event_active(ev, EV_SIGNAL, ncalls);
320 } 331 }
321 332
322 sig->evsigcaught[i] = 0;
323 } 333 }
324 } 334 }
325 335
326 void 336 void
327 evsignal_dealloc(struct event_base *base) 337 evsignal_dealloc(struct event_base *base)
328 { 338 {
329 int i = 0; 339 int i = 0;
330 if (base->sig.ev_signal_added) { 340 if (base->sig.ev_signal_added) {
331 event_del(&base->sig.ev_signal); 341 event_del(&base->sig.ev_signal);
332 base->sig.ev_signal_added = 0; 342 base->sig.ev_signal_added = 0;
333 } 343 }
334 for (i = 0; i < NSIG; ++i) { 344 for (i = 0; i < NSIG; ++i) {
335 if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL) 345 if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL)
336 _evsignal_restore_handler(base, i); 346 _evsignal_restore_handler(base, i);
337 } 347 }
338 348
339 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); 349 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]);
340 base->sig.ev_signal_pair[0] = -1; 350 base->sig.ev_signal_pair[0] = -1;
341 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); 351 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]);
342 base->sig.ev_signal_pair[1] = -1; 352 base->sig.ev_signal_pair[1] = -1;
343 base->sig.sh_old_max = 0; 353 base->sig.sh_old_max = 0;
344 354
345 /* per index frees are handled in evsignal_del() */ 355 /* per index frees are handled in evsignal_del() */
346 free(base->sig.sh_old); 356 free(base->sig.sh_old);
347 } 357 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698