static void handle_control (int fd) { for (;;) { char c ; int r = sanitize_read(fd_read(fd, &c, 1)) ; if (r == -1) panic("read control pipe") ; else if (!r) break ; else switch (c) { case 'p' : finish_arg = "poweroff" ; break ; case 'h' : hup() ; return ; case 'r' : finish_arg = "reboot" ; break ; case 'a' : wantscan = 1 ; break ; case 't' : term() ; return ; case 's' : finish_arg = "halt" ; break ; case 'z' : wantreap = 1 ; break ; case 'b' : cont = 0 ; return ; case 'n' : wantkill = 2 ; break ; case 'N' : wantkill = 6 ; break ; case '6' : case 'i' : intr() ; return ; case 'q' : quit() ; return ; case '0' : finish_arg = "halt" ; term() ; return ; case '7' : usr1() ; return ; case '8' : finish_arg = "other" ; term() ; return ; default : { char s[2] = { c, 0 } ; strerr_warnw2x("received unknown control command: ", s) ; } } } }
static void handle_signals (void) { for (;;) { switch (selfpipe_read()) { case -1 : panic("selfpipe_read") ; case 0 : return ; case SIGCHLD : wantreap = 1 ; break ; case SIGALRM : wantscan = 1 ; break ; case SIGTERM : term() ; break ; case SIGHUP : hup() ; break ; case SIGQUIT : quit() ; break ; case SIGABRT : cont = 0 ; break ; case SIGINT : intr() ; break ; case SIGUSR1 : usr1() ; break ; } } }
short UARTSerial::poll(short events) const { short revents = 0; /* Check the Circular Buffer if space available for writing out */ if (!_rxbuf.empty()) { revents |= POLLIN; } /* POLLHUP and POLLOUT are mutually exclusive */ if (hup()) { revents |= POLLHUP; } else if (!_txbuf.full()) { revents |= POLLOUT; } /*TODO Handle other event types */ return revents; }
// Also called from write to start transfer void UARTSerial::tx_irq(void) { bool was_full = _txbuf.full(); /* Write to the peripheral if there is something to write * and if the peripheral is available to write. */ while (!_txbuf.empty() && SerialBase::writeable()) { char data; _txbuf.pop(data); SerialBase::_base_putc(data); } if (_tx_irq_enabled && _txbuf.empty()) { SerialBase::attach(NULL, TxIrq); _tx_irq_enabled = false; } /* Report the File handler that data can be written to peripheral. */ if (was_full && !_txbuf.full() && !hup()) { wake(); } }