Listing 3. scanlist, Detecting the Source of a Signal

int scanlist(fd_set set)
{
  struct list_proc *p;
  char message;
  int alert=0;
  p = ini_list;
/* We only service the first routine which is
   found to be ready, so that there is exactly one
   '.' read from a pipe per SIGUSR1.  If we did
   not do this, there is a risk that a single
   interrupt might service two processes'
   requests; this would cause one of them to time
   out and send a SIGALRM */
  while (p != NULL) {
    if (FD_ISSET(p->p_num, &set)) {
      read(p->p_num, &message, sizeof(char));
      if (message == '.') {
        /* Call the requested routines */
        (* p->rout_hndl)();
        return 0;
      }
      else {
        fprintf(stderr,
                "Interrupt handler: ALERT!!\n");
        alert = 1;
      }
    }
    p = p->next;
  }
  return alert;
}