Changeset fb96152 for select.c


Ignore:
Timestamp:
Apr 3, 2011, 3:06:00 PM (10 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
8ba9313
Parents:
f2d71cfa
git-author:
Nelson Elhage <nelhage@nelhage.com> (02/24/11 09:59:45)
git-committer:
Nelson Elhage <nelhage@mit.edu> (04/03/11 15:06:00)
Message:
Don't die horribly if perl registers a dispatch and then closes the fd.

Well-behaved perl code should of course remove the dispatch when it
closes the fd, but there's no reason not to be robust to this failure
mode.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • select.c

    rd4927a7 rfb96152  
    11#include "owl.h"
     2#include <sys/stat.h>
    23
    34static int dispatch_active = 0;
     
    353354  owl_select_psa_gc();
    354355  return ret;
     356}
     357
     358static void owl_select_prune_bad_fds(void) {
     359  owl_list *dl = owl_global_get_io_dispatch_list(&g);
     360  int len, i;
     361  struct stat st;
     362  owl_io_dispatch *d;
     363
     364  len = owl_list_get_size(dl);
     365  for (i = 0; i < len; i++) {
     366    d = owl_list_get_element(dl, i);
     367    if (fstat(d->fd, &st) < 0 && errno == EBADF) {
     368      owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
     369      d->needs_gc = 1;
     370    }
     371  }
     372  owl_select_io_dispatch_gc();
    355373}
    356374
     
    416434  ret = pselect(max_fd+1, &r, &w, &e, &timeout, &mask);
    417435
    418   if(ret < 0 && errno == EINTR) {
    419     if(owl_global_is_interrupted(&g)) {
    420       owl_select_handle_intr(NULL);
     436  if(ret < 0) {
     437    if (errno == EINTR) {
     438      if(owl_global_is_interrupted(&g)) {
     439        owl_select_handle_intr(NULL);
     440      }
     441    } else if (errno == EBADF) {
     442      /* Perl must have closed an fd on us without removing it first. */
     443      owl_select_prune_bad_fds();
    421444    }
    422445    sigprocmask(SIG_SETMASK, &mask, NULL);
Note: See TracChangeset for help on using the changeset viewer.