Changeset 6bd485e


Ignore:
Timestamp:
May 23, 2011, 8:57:46 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
08e9842
Parents:
47128d9
git-author:
David Benjamin <davidben@mit.edu> (02/28/11 10:12:15)
git-committer:
David Benjamin <davidben@mit.edu> (05/23/11 20:57:46)
Message:
Reset signal dispositions and mask, in case our parent was lame

Also check return values more carefully.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r47128d9 r6bd485e  
    389389}
    390390
     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
    391399void 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 };
    393402  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  }
    394418
    395419  /* Turn off SIGPIPE; we check the return value of write. */
    396   sigaction(SIGPIPE, &ignore, NULL);
     420  CHECK_RESULT("sigaction", sigaction(SIGPIPE, &sig_ignore, NULL));
    397421
    398422  /* 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));
    404427  owl_signal_init(&sigset, sig_handler, g_main_context_default());
    405428}
  • signal.c

    r81db142 r6bd485e  
    11#include <glib.h>
     2#include <errno.h>
    23#include <pthread.h>
    34#include <signal.h>
     
    2122void owl_signal_init(const sigset_t *set, void (*callback)(int, void*), void *data) {
    2223  GError *error = NULL;
     24  int ret;
    2325
    2426  signal_set = *set;
     
    2628  signal_cbdata = data;
    2729  /* 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  }
    2934  /* Spawn a dedicated thread to sigwait. */
    3035  signal_thread = g_thread_create(signal_thread_func, NULL, FALSE, &error);
Note: See TracChangeset for help on using the changeset viewer.