diff options
Diffstat (limited to 'term/users.c')
-rw-r--r-- | term/users.c | 225 |
1 files changed, 84 insertions, 141 deletions
diff --git a/term/users.c b/term/users.c index eacd150a..3f558390 100644 --- a/term/users.c +++ b/term/users.c @@ -902,19 +902,18 @@ trivfs_S_io_revoke (struct trivfs_protid *cred, /* TIOCMODG ioctl -- Get modem state */ kern_return_t -S_tioctl_tiocmodg (io_t port, +S_tioctl_tiocmodg (struct trivfs_protid *cred, int *state) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err = 0; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -922,24 +921,22 @@ S_tioctl_tiocmodg (io_t port, err = (*bottom->mdmstate) (state); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCMODS ioctl -- Set modem state */ kern_return_t -S_tioctl_tiocmods (io_t port, +S_tioctl_tiocmods (struct trivfs_protid *cred, int state) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -952,23 +949,21 @@ S_tioctl_tiocmods (io_t port, pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCEXCL ioctl -- Set exclusive use */ kern_return_t -S_tioctl_tiocexcl (io_t port) +S_tioctl_tiocexcl (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -983,24 +978,22 @@ S_tioctl_tiocexcl (io_t port) } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCNXCL ioctl -- Clear exclusive use */ kern_return_t -S_tioctl_tiocnxcl (io_t port) +S_tioctl_tiocnxcl (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1014,25 +1007,23 @@ S_tioctl_tiocnxcl (io_t port) } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCFLUSH ioctl -- Flush input, output, or both */ kern_return_t -S_tioctl_tiocflush (io_t port, +S_tioctl_tiocflush (struct trivfs_protid *cred, int flags) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err = 0; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1056,26 +1047,23 @@ S_tioctl_tiocflush (io_t port, } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCGETA ioctl -- Get termios state */ kern_return_t -S_tioctl_tiocgeta (io_t port, +S_tioctl_tiocgeta (struct trivfs_protid *cred, tcflag_t *modes, cc_t *ccs, speed_t *speeds) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); - - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1089,30 +1077,28 @@ S_tioctl_tiocgeta (io_t port, speeds[1] = termstate.__ospeed; pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return 0; } /* Common code for the varios TIOCSET* commands. */ static error_t -set_state (io_t port, +set_state (struct trivfs_protid *cred, tcflag_t *modes, cc_t *ccs, speed_t *speeds, int draino, int flushi) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; struct termios state; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1181,80 +1167,75 @@ set_state (io_t port, leave: pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSETA -- Set termios state */ kern_return_t -S_tioctl_tiocseta (io_t port, +S_tioctl_tiocseta (struct trivfs_protid *cred, tcflag_t *modes, cc_t *ccs, speed_t *speeds) { - return set_state (port, modes, ccs, speeds, 0, 0); + return set_state (cred, modes, ccs, speeds, 0, 0); } /* Drain output, then set term state. */ kern_return_t -S_tioctl_tiocsetaw (io_t port, +S_tioctl_tiocsetaw (struct trivfs_protid *cred, tcflag_t *modes, cc_t *ccs, speed_t *speeds) { - return set_state (port, modes, ccs, speeds, 1, 0); + return set_state (cred, modes, ccs, speeds, 1, 0); } /* Flush input, drain output, then set term state. */ kern_return_t -S_tioctl_tiocsetaf (io_t port, +S_tioctl_tiocsetaf (struct trivfs_protid *cred, tcflag_t *modes, cc_t *ccs, speed_t *speeds) { - return set_state (port, modes, ccs, speeds, 1, 1); + return set_state (cred, modes, ccs, speeds, 1, 1); } /* TIOCGETD -- Return line discipline */ kern_return_t -S_tioctl_tiocgetd (io_t port, +S_tioctl_tiocgetd (struct trivfs_protid *cred, int *disc) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); - - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } *disc = 0; - ports_port_deref (cred); return 0; } /* TIOCSETD -- Set line discipline */ kern_return_t -S_tioctl_tiocsetd (io_t port, +S_tioctl_tiocsetd (struct trivfs_protid *cred, int disc) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1268,24 +1249,22 @@ S_tioctl_tiocsetd (io_t port, else err = 0; - ports_port_deref (cred); return err; } /* TIOCDRAIN -- Wait for output to drain */ kern_return_t -S_tioctl_tiocdrain (io_t port) +S_tioctl_tiocdrain (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1293,31 +1272,28 @@ S_tioctl_tiocdrain (io_t port) if (!(cred->po->openmodes & O_WRITE)) { pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return EBADF; } err = drain_output (); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSWINSZ -- Set window size */ kern_return_t -S_tioctl_tiocswinsz (io_t port, +S_tioctl_tiocswinsz (struct trivfs_protid *cred, struct winsize size) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1328,8 +1304,6 @@ S_tioctl_tiocswinsz (io_t port, else err = 0; - ports_port_deref (cred); - if (! err && (size.ws_row != window_size.ws_row || size.ws_col != window_size.ws_col @@ -1348,18 +1322,16 @@ S_tioctl_tiocswinsz (io_t port, /* TIOCGWINSZ -- Fetch window size */ kern_return_t -S_tioctl_tiocgwinsz (io_t port, +S_tioctl_tiocgwinsz (struct trivfs_protid *cred, struct winsize *size) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); - - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1367,25 +1339,23 @@ S_tioctl_tiocgwinsz (io_t port, *size = window_size; pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return 0; } /* TIOCMGET -- Fetch all modem bits */ kern_return_t -S_tioctl_tiocmget (io_t port, +S_tioctl_tiocmget (struct trivfs_protid *cred, int *bits) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err = 0; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1393,25 +1363,23 @@ S_tioctl_tiocmget (io_t port, err = (*bottom->mdmstate) (bits); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCMSET -- Set all modem bits */ kern_return_t -S_tioctl_tiocmset (io_t port, +S_tioctl_tiocmset (struct trivfs_protid *cred, int bits) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1422,25 +1390,23 @@ S_tioctl_tiocmset (io_t port, err = (*bottom->mdmctl) (MDMCTL_SET, bits); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCMBIC -- Clear some modem bits */ kern_return_t -S_tioctl_tiocmbic (io_t port, +S_tioctl_tiocmbic (struct trivfs_protid *cred, int bits) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1451,25 +1417,23 @@ S_tioctl_tiocmbic (io_t port, err = (*bottom->mdmctl) (MDMCTL_BIC, bits); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCMBIS -- Set some modem bits */ kern_return_t -S_tioctl_tiocmbis (io_t port, +S_tioctl_tiocmbis (struct trivfs_protid *cred, int bits) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1480,24 +1444,22 @@ S_tioctl_tiocmbis (io_t port, else err = (*bottom->mdmctl) (MDMCTL_BIS, bits); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSTART -- start output as if VSTART were typed */ kern_return_t -S_tioctl_tiocstart (io_t port) +S_tioctl_tiocstart (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1516,24 +1478,22 @@ S_tioctl_tiocstart (io_t port) } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSTOP -- stop output as if VSTOP were typed */ kern_return_t -S_tioctl_tiocstop (io_t port) +S_tioctl_tiocstop (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } pthread_mutex_lock (&global_lock); @@ -1550,25 +1510,23 @@ S_tioctl_tiocstop (io_t port) } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSTI -- Simulate terminal input */ kern_return_t -S_tioctl_tiocsti (io_t port, +S_tioctl_tiocsti (struct trivfs_protid *cred, char c) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1587,25 +1545,23 @@ S_tioctl_tiocsti (io_t port, } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCOUTQ -- return output queue size */ kern_return_t -S_tioctl_tiocoutq (io_t port, +S_tioctl_tiocoutq (struct trivfs_protid *cred, int *queue_size) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1620,25 +1576,23 @@ S_tioctl_tiocoutq (io_t port, } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSPGRP -- set pgrp of terminal */ kern_return_t -S_tioctl_tiocspgrp (io_t port, +S_tioctl_tiocspgrp (struct trivfs_protid *cred, int pgrp) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1653,25 +1607,23 @@ S_tioctl_tiocspgrp (io_t port, } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCGPGRP --- fetch pgrp of terminal */ kern_return_t -S_tioctl_tiocgpgrp (io_t port, +S_tioctl_tiocgpgrp (struct trivfs_protid *cred, int *pgrp) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t ret; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1685,24 +1637,22 @@ S_tioctl_tiocgpgrp (io_t port, } pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return ret; } /* TIOCCDTR -- clear DTR */ kern_return_t -S_tioctl_tioccdtr (io_t port) +S_tioctl_tioccdtr (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1713,24 +1663,22 @@ S_tioctl_tioccdtr (io_t port) err = (*bottom->mdmctl) (MDMCTL_BIC, TIOCM_DTR); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSDTR -- set DTR */ kern_return_t -S_tioctl_tiocsdtr (io_t port) +S_tioctl_tiocsdtr (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1741,24 +1689,22 @@ S_tioctl_tiocsdtr (io_t port) err = (*bottom->mdmctl) (MDMCTL_BIS, TIOCM_DTR); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCCBRK -- Clear break condition */ kern_return_t -S_tioctl_tioccbrk (io_t port) +S_tioctl_tioccbrk (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1769,24 +1715,22 @@ S_tioctl_tioccbrk (io_t port) err = (*bottom->clear_break) (); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } /* TIOCSBRK -- Set break condition */ kern_return_t -S_tioctl_tiocsbrk (io_t port) +S_tioctl_tiocsbrk (struct trivfs_protid *cred) { - struct trivfs_protid *cred = ports_lookup_port (term_bucket, port, 0); error_t err; - if (!cred) + if (!cred + || cred->pi.bucket != term_bucket) return EOPNOTSUPP; if (cred->pi.class != pty_class && cred->pi.class != tty_class) { - ports_port_deref (cred); return EOPNOTSUPP; } @@ -1797,7 +1741,6 @@ S_tioctl_tiocsbrk (io_t port) err = (*bottom->set_break) (); pthread_mutex_unlock (&global_lock); - ports_port_deref (cred); return err; } |