X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/b0d623f7f2ae71ed96e60569f61f9a9a27016e80..13f56ec4e58bf8687e2a68032c093c0213dd519b:/bsd/kern/tty.c?ds=sidebyside diff --git a/bsd/kern/tty.c b/bsd/kern/tty.c index a03e1f437..b97eb780e 100644 --- a/bsd/kern/tty.c +++ b/bsd/kern/tty.c @@ -1498,6 +1498,8 @@ out: int ttyselect(struct tty *tp, int rw, void *wql, proc_t p) { + int retval = 0; + if (tp == NULL) return (ENXIO); @@ -1505,20 +1507,32 @@ ttyselect(struct tty *tp, int rw, void *wql, proc_t p) switch (rw) { case FREAD: - if (ttnread(tp) > 0 || ISSET(tp->t_state, TS_ZOMBIE)) + if (ISSET(tp->t_state, TS_ZOMBIE)) { return(1); + } + + retval = ttnread(tp); + if (retval > 0) { + break; + } + selrecord(p, &tp->t_rsel, wql); break; case FWRITE: - if ((tp->t_outq.c_cc <= tp->t_lowat && - ISSET(tp->t_state, TS_CONNECTED)) - || ISSET(tp->t_state, TS_ZOMBIE)) { - return (1); + if (ISSET(tp->t_state, TS_ZOMBIE)) { + return(1); } + + if ((tp->t_outq.c_cc <= tp->t_lowat) && + ISSET(tp->t_state, TS_CONNECTED)) { + retval = tp->t_hiwat - tp->t_outq.c_cc; + break; + } + selrecord(p, &tp->t_wsel, wql); break; } - return (0); + return retval; } @@ -3022,6 +3036,8 @@ ttymalloc(void) /* output queue doesn't need quoting */ clalloc(&tp->t_outq, TTYCLSIZE, 0); lck_mtx_init(&tp->t_lock, tty_lck_grp, tty_lck_attr); + klist_init(&tp->t_rsel.si_note); + klist_init(&tp->t_wsel.si_note); } return(tp); } @@ -3038,6 +3054,12 @@ ttyfree(struct tty *tp) { TTY_LOCK_NOTOWNED(tp); /* debug assert */ +#if DEBUG + if (!(SLIST_EMPTY(&tp->t_rsel.si_note) && SLIST_EMPTY(&tp->t_wsel.si_note))) { + panic("knotes hooked into a tty when the tty is freed.\n"); + } +#endif /* DEBUG */ + clfree(&tp->t_rawq); clfree(&tp->t_canq); clfree(&tp->t_outq);