Changeset fafb842


Ignore:
Timestamp:
Mar 25, 2011, 3:46:46 AM (12 years ago)
Author:
David Benjamin <davidben@mit.edu>
Children:
96ade35
Parents:
cd28517
git-author:
David Benjamin <davidben@mit.edu> (02/26/11 00:15:35)
git-committer:
David Benjamin <davidben@mit.edu> (03/25/11 03:46:46)
Message:
First go at sigwait-based signal handling

SIGINT doesn't quite work.
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rce35060 rfafb842  
    4545     aim.c buddy.c buddylist.c style.c errqueue.c \
    4646     zbuddylist.c popexec.c select.c wcwidth.c \
    47      glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c
     47     glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c signal.c
    4848
    4949NORMAL_SRCS = filterproc.c window.c windowcb.c
  • functions.c

    r1a30f05 rfafb842  
    29952995      i--;
    29962996    }
     2997#if 0
     2998    /* FIXME!!! */
    29972999    owl_function_mask_sigint(NULL);
    29983000    if(owl_global_is_interrupted(&g)) {
     
    30043006    }
    30053007    owl_function_unmask_sigint(NULL);
     3008#endif
    30063009  }
    30073010  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     
    30863089          ret=ZLocateUser(zstr(user), &numlocs, ZAUTH);
    30873090
     3091#if 0
     3092          /* FIXME!! */
    30883093          owl_function_mask_sigint(NULL);
    30893094          if(owl_global_is_interrupted(&g)) {
     
    30963101
    30973102          owl_function_unmask_sigint(NULL);
     3103#endif
    30983104
    30993105          if (ret!=ZERR_NONE) {
  • global.c

    rb279013 rfafb842  
    1616
    1717  g_type_init();
     18  g_thread_init(NULL);
    1819
    1920  owl_select_init();
     
    101102
    102103  owl_errqueue_init(&(g->errqueue));
    103   g->got_err_signal=0;
    104104
    105105  owl_zbuddylist_create(&(g->zbuddies));
     
    112112  owl_list_create(&(g->psa_list));
    113113  g->timerlist = NULL;
    114   g->interrupted = FALSE;
    115114  g->kill_buffer = NULL;
    116115}
     
    826825}
    827826
    828 void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)
    829 {
    830   g->got_err_signal = signum;
    831   if (siginfo) {
    832     g->err_signal_info = *siginfo;
    833   } else {
    834     siginfo_t si;
    835     memset(&si, 0, sizeof(si));
    836     g->err_signal_info = si;
    837   }
    838 }
    839 
    840 int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)
    841 {
    842   int signum;
    843   if (siginfo && g->got_err_signal) {
    844     *siginfo = g->err_signal_info;
    845   }
    846   signum = g->got_err_signal;
    847   g->got_err_signal = 0;
    848   return signum;
    849 }
    850 
    851 
    852827owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
    853828{
     
    888863{
    889864  return &(g->timerlist);
    890 }
    891 
    892 int owl_global_is_interrupted(const owl_global *g) {
    893   return g->interrupted;
    894 }
    895 
    896 void owl_global_set_interrupted(owl_global *g) {
    897   g->interrupted = 1;
    898 }
    899 
    900 void owl_global_unset_interrupted(owl_global *g) {
    901   g->interrupted = 0;
    902865}
    903866
  • owl.c

    r5eb392f rfafb842  
    354354}
    355355
    356 void sig_handler(int sig, siginfo_t *si, void *data)
    357 {
    358   if (sig==SIGWINCH) {
     356static void sig_handler(int sig, void *data) {
     357  owl_function_debugmsg("Got signal %d", sig);
     358  /* TODO: These don't need to be re-entrant anymore! */
     359  if (sig == SIGWINCH) {
    359360    /* we can't inturrupt a malloc here, so it just sets a flag
    360361     * schedulding a resize for later
    361362     */
    362363    owl_function_resize();
    363   } else if (sig==SIGPIPE || sig==SIGCHLD) {
    364     /* Set a flag and some info that we got the sigpipe
    365      * so we can record that we got it and why... */
    366     owl_global_set_errsignal(&g, sig, si);
    367   } else if (sig==SIGTERM || sig==SIGHUP) {
     364  } else if (sig == SIGPIPE || sig == SIGCHLD) {
     365    owl_function_error("Got unexpected signal: %d %s",
     366                       sig, (sig == SIGPIPE) ? "SIGPIPE" : "SIGCHLD");
     367  } else if (sig == SIGTERM || sig == SIGHUP) {
    368368    owl_function_quit();
    369   }
    370 }
    371 
    372 void sigint_handler(int sig, siginfo_t *si, void *data)
    373 {
    374   owl_global_set_interrupted(&g);
    375 }
    376 
    377 static int owl_errsignal_pre_select_action(owl_ps_action *a, void *data)
    378 {
    379   siginfo_t si;
    380   int signum;
    381   if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
    382     owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
    383         signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
    384         si.si_code, si.si_band, si.si_errno);
    385   }
    386   return 0;
     369  } else if (sig == SIGINT) {
     370    owl_input in;
     371    in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
     372    owl_process_input_char(in);
     373  }
    387374}
    388375
    389376void owl_register_signal_handlers(void) {
    390   struct sigaction sigact;
    391 
    392   /* signal handler */
    393   /*sigact.sa_handler=sig_handler;*/
    394   sigact.sa_sigaction=sig_handler;
    395   sigemptyset(&sigact.sa_mask);
    396   sigact.sa_flags=SA_SIGINFO;
    397   sigaction(SIGWINCH, &sigact, NULL);
    398   sigaction(SIGALRM, &sigact, NULL);
    399   sigaction(SIGPIPE, &sigact, NULL);
    400   sigaction(SIGTERM, &sigact, NULL);
    401   sigaction(SIGHUP, &sigact, NULL);
    402 
    403   sigact.sa_sigaction=sigint_handler;
    404   sigaction(SIGINT, &sigact, NULL);
     377  sigset_t sigset;
     378
     379  sigemptyset(&sigset);
     380  sigaddset(&sigset, SIGWINCH);
     381  sigaddset(&sigset, SIGALRM);
     382  sigaddset(&sigset, SIGPIPE);
     383  sigaddset(&sigset, SIGTERM);
     384  sigaddset(&sigset, SIGHUP);
     385  sigaddset(&sigset, SIGINT);
     386
     387  owl_signal_init(&sigset, sig_handler, NULL);
    405388}
    406389
     
    479462  g.load_initial_subs = opts.load_initial_subs;
    480463
    481   owl_register_signal_handlers();
    482464  owl_start_curses();
    483465
     
    491473  g_strfreev(argv_copy);
    492474  owl_global_set_haveaim(&g);
     475
     476  owl_register_signal_handlers();
    493477
    494478  /* register STDIN dispatch; throw away return, we won't need it */
     
    591575  g_source_unref(source);
    592576
    593   owl_select_add_pre_select_action(owl_errsignal_pre_select_action, NULL, NULL);
    594 
    595577  owl_function_debugmsg("startup: entering main loop");
    596578  owl_select_run_loop();
  • owl.h

    rb279013 rfafb842  
    629629  int haveaim;
    630630  int ignoreaimlogin;
    631   volatile sig_atomic_t got_err_signal; /* 1 if we got an unexpected signal */
    632   volatile siginfo_t err_signal_info;
    633631  owl_zbuddylist zbuddies;
    634632  GList *zaldlist;
     
    640638  owl_timer *aim_nop_timer;
    641639  int load_initial_subs;
    642   volatile sig_atomic_t interrupted;
    643640  FILE *debug_file;
    644641  char *kill_buffer;
  • select.c

    rb279013 rfafb842  
    335335    owl_function_makemsg("Unable to handle keypress");
    336336  }
    337 }
    338 
    339 void owl_select_mask_signals(sigset_t *oldmask) {
    340   sigset_t set;
    341 
    342   sigemptyset(&set);
    343   sigaddset(&set, SIGWINCH);
    344   sigaddset(&set, SIGALRM);
    345   sigaddset(&set, SIGPIPE);
    346   sigaddset(&set, SIGTERM);
    347   sigaddset(&set, SIGHUP);
    348   sigaddset(&set, SIGINT);
    349   sigprocmask(SIG_BLOCK, &set, oldmask);
    350 }
    351 
    352 void owl_select_handle_intr(sigset_t *restore)
    353 {
    354   owl_input in;
    355 
    356   owl_global_unset_interrupted(&g);
    357 
    358   sigprocmask(SIG_SETMASK, restore, NULL);
    359 
    360   in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
    361   owl_process_input_char(in);
    362337}
    363338
Note: See TracChangeset for help on using the changeset viewer.