+ return (retval);
+}
+
+
+/*
+ * ttioctl_locked
+ *
+ * Ioctls for all tty devices.
+ *
+ * Parameters: tp Tty on which ioctl() is being called
+ * cmd ioctl() command parameter
+ * data ioctl() data argument (if any)
+ * flag fileglob open modes from fcntl.h;
+ * if called internally, this is usually
+ * set to 0, rather than something useful
+ * p Process context for the call; if the
+ * call is proxied to a worker thread,
+ * this will not be the current process!!!
+ *
+ * Returns: 0 Success
+ * EIO I/O error (no process group, job
+ * control, etc.)
+ * EINTR Interrupted by signal
+ * EBUSY Attempt to become the console while
+ * the console is busy
+ * ENOTTY TIOCGPGRP on a non-controlling tty
+ * EINVAL Invalid baud rate
+ * ENXIO TIOCSETD of invalid line discipline
+ * EPERM TIOCSTI, not root, not open for read
+ * EACCES TIOCSTI, not root, not your controlling
+ * tty
+ * EPERM TIOCSCTTY failed
+ * ENOTTY/EINVAL/EPERM TIOCSPGRP failed
+ * EPERM TIOCSDRAINWAIT as non-root user
+ * suser:EPERM Console control denied
+ * ttywait:EIO t_timeout too small/expired
+ * ttywait:ERESTART Upper layer must redrive the call;
+ * this is usually done by the Libc
+ * stub in user space
+ * ttywait:EINTR Interrupted (usually a signal)
+ * ttcompat:EINVAL
+ * ttcompat:ENOTTY
+ * ttcompat:EIOCTL
+ * ttcompat:ENOTTY TIOCGSID, if no session or session
+ * leader
+ * ttcompat:ENOTTY All unrecognized ioctls
+ * *tp->t_param:? TIOCSETA* underlying function
+ * *linesw[t].l_open:? TIOCSETD line discipline open failure
+ *
+ *
+ * Locks: This function assumes that the tty_lock() is held for the
+ * tp at the time of the call. The lock remains held on return.
+ *
+ * Notes: This function is called after line-discipline specific ioctl
+ * has been called to do discipline-specific functions and/or
+ * reject any of these ioctl() commands.
+ *
+ * This function calls ttcompat(), which can re-call ttioctl()
+ * to a depth of one (FORTRAN style mutual recursion); at some
+ * point, we should just in-line ttcompat() here.
+ */
+int
+ttioctl_locked(struct tty *tp, u_long cmd, caddr_t data, int flag, proc_t p)
+{
+ int error = 0;
+ struct uthread *ut;
+ struct pgrp *pg, *oldpg;
+ struct session *sessp, *oldsessp;
+ struct tty *oldtp;
+
+ TTY_LOCK_OWNED(tp); /* debug assert */
+
+ ut = (struct uthread *)get_bsdthread_info(current_thread());
+ /* If the ioctl involves modification, signal if in the background. */