static lck_grp_attr_t *tty_lck_grp_attr;
static lck_attr_t *tty_lck_attr;
-static int ttnread(struct tty *tp);
+__private_extern__ int ttnread(struct tty *tp);
static void ttyecho(int c, struct tty *tp);
static int ttyoutput(int c, struct tty *tp);
static void ttypend(struct tty *tp);
return (-1);
}
+/*
+ * Sets the tty state to not allow any more changes of foreground process
+ * group. This is required to be done so that a subsequent revoke on a vnode
+ * is able to always successfully complete.
+ *
+ * Locks : Assumes tty_lock held on entry
+ */
+void
+ttysetpgrphup(struct tty *tp)
+{
+ TTY_LOCK_OWNED(tp); /* debug assert */
+ SET(tp->t_state, TS_PGRPHUP);
+}
+
+/*
+ * Locks : Assumes tty lock held on entry
+ */
+void
+ttyclrpgrphup(struct tty *tp)
+{
+ TTY_LOCK_OWNED(tp); /* debug assert */
+ CLR(tp->t_state, TS_PGRPHUP);
+}
/*
* ttioctl
error = EPERM;
goto out;
}
+ /*
+ * The session leader is going away and is possibly going to revoke
+ * the terminal, we can't change the process group when that is the
+ * case.
+ */
+ if (ISSET(tp->t_state, TS_PGRPHUP)) {
+ error = EPERM;
+ goto out;
+ }
proc_list_lock();
oldpg = tp->t_pgrp;
tp->t_pgrp = pgrp;
/*
* Locks: Assumes tp is locked on entry, remains locked on exit
*/
-static int
+__private_extern__ int
ttnread(struct tty *tp)
{
int nread;
char ibuf[IBUFSIZ];
int icc;
- icc = min(uio_resid(uio), IBUFSIZ);
+ icc = MIN(uio_resid(uio), IBUFSIZ);
icc = q_to_b(qp, (u_char *)ibuf, icc);
if (icc <= 0) {
if (first)
tty_pgsignal(tp, SIGTSTP, 1);
tty_lock(tp);
if (first) {
- error = ttysleep(tp, &lbolt, TTIPRI | PCATCH,
- "ttybg3", 0);
+ error = ttysleep(tp, &ttread, TTIPRI | PCATCH,
+ "ttybg3", hz);
if (error)
break;
goto loop;
* leftover from last time.
*/
if (cc == 0) {
- cc = min(uio_resid(uio), OBUFSIZ);
+ cc = MIN(uio_resid(uio), OBUFSIZ);
cp = obuf;
error = uiomove(cp, cc, uio);
if (error) {