Changeset f3b5dc8
- Timestamp:
- Mar 25, 2011, 3:55:41 AM (13 years ago)
- Children:
- 567de81
- Parents:
- 8eb6068
- git-author:
- David Benjamin <davidben@mit.edu> (02/28/11 10:12:15)
- git-committer:
- David Benjamin <davidben@mit.edu> (03/25/11 03:55:41)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.c
r8eb6068 rf3b5dc8 389 389 } 390 390 391 #define CHECK_RESULT(s, syscall) \ 392 G_STMT_START { \ 393 if ((syscall) != 0) { \ 394 perror((s)); \ 395 exit(1); \ 396 } \ 397 } G_STMT_END 398 391 399 void owl_register_signal_handlers(void) { 392 struct sigaction ignore = { .sa_handler = SIG_IGN }; 400 struct sigaction sig_ignore = { .sa_handler = SIG_IGN }; 401 struct sigaction sig_default = { .sa_handler = SIG_DFL }; 393 402 sigset_t sigset; 403 int ret, i; 404 const int signals[] = { SIGABRT, SIGBUS, SIGCHLD, SIGFPE, SIGHUP, SIGILL, 405 SIGINT, SIGQUIT, SIGSEGV, SIGTERM, SIGWINCH }; 406 407 /* Sanitize our signals; the mask and dispositions from our parent 408 * aren't really useful. Signal list taken from equivalent code in 409 * Chromium. */ 410 CHECK_RESULT("sigemptyset", sigemptyset(&sigset)); 411 if ((ret = pthread_sigmask(SIG_SETMASK, &sigset, NULL)) != 0) { 412 errno = ret; 413 perror("pthread_sigmask"); 414 } 415 for (i = 0; i < G_N_ELEMENTS(signals); i++) { 416 CHECK_RESULT("sigaction", sigaction(signals[i], &sig_default, NULL)); 417 } 394 418 395 419 /* Turn off SIGPIPE; we check the return value of write. */ 396 sigaction(SIGPIPE, &ignore, NULL);420 CHECK_RESULT("sigaction", sigaction(SIGPIPE, &sig_ignore, NULL)); 397 421 398 422 /* Register some signals with the signal thread. */ 399 sigemptyset(&sigset); 400 sigaddset(&sigset, SIGWINCH); 401 sigaddset(&sigset, SIGTERM); 402 sigaddset(&sigset, SIGHUP); 403 sigaddset(&sigset, SIGINT); 423 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGWINCH)); 424 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGTERM)); 425 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGHUP)); 426 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGINT)); 404 427 owl_signal_init(&sigset, sig_handler, g_main_context_default()); 405 428 } -
signal.c
r87833a8 rf3b5dc8 1 1 #include <glib.h> 2 #include <errno.h> 2 3 #include <pthread.h> 3 4 #include <signal.h> … … 21 22 void owl_signal_init(const sigset_t *set, void (*callback)(int, void*), void *data) { 22 23 GError *error = NULL; 24 int ret; 23 25 24 26 signal_set = *set; … … 26 28 signal_cbdata = data; 27 29 /* Block these signals in all threads, so we can get them. */ 28 pthread_sigmask(SIG_BLOCK, set, NULL); 30 if ((ret = pthread_sigmask(SIG_BLOCK, set, NULL)) != 0) { 31 errno = ret; 32 perror("pthread_sigmask"); 33 } 29 34 /* Spawn a dedicated thread to sigwait. */ 30 35 signal_thread = g_thread_create(signal_thread_func, NULL, FALSE, &error);
Note: See TracChangeset
for help on using the changeset viewer.