[Midnightbsd-cvs] src [9953] trunk/sys/kern: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat May 26 10:25:18 EDT 2018
Revision: 9953
http://svnweb.midnightbsd.org/src/?rev=9953
Author: laffer1
Date: 2018-05-26 10:25:17 -0400 (Sat, 26 May 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/sys/kern/tty.c
trunk/sys/kern/tty_compat.c
trunk/sys/kern/tty_info.c
trunk/sys/kern/tty_inq.c
trunk/sys/kern/tty_outq.c
trunk/sys/kern/tty_pts.c
trunk/sys/kern/tty_tty.c
trunk/sys/kern/tty_ttydisc.c
Modified: trunk/sys/kern/tty.c
===================================================================
--- trunk/sys/kern/tty.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Ed Schouten <ed at FreeBSD.org>
* All rights reserved.
@@ -28,13 +29,13 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty.c 302234 2016-06-27 21:50:30Z bdrewery $");
#include "opt_capsicum.h"
#include "opt_compat.h"
#include <sys/param.h>
-#include <sys/capability.h>
+#include <sys/capsicum.h>
#include <sys/conf.h>
#include <sys/cons.h>
#include <sys/fcntl.h>
@@ -114,7 +115,7 @@
/* Set low watermark at 10% (when 90% is available). */
tp->t_inlow = (ttyinq_getallocatedsize(&tp->t_inq) * 9) / 10;
- /* Provide an ouput buffer for 0.2 seconds of data. */
+ /* Provide an output buffer for 0.2 seconds of data. */
bs = MIN(tp->t_termios.c_ospeed / 5, TTYBUF_MAX);
ttyoutq_setsize(&tp->t_outq, tp, bs);
@@ -123,22 +124,39 @@
}
static int
-tty_drain(struct tty *tp)
+tty_drain(struct tty *tp, int leaving)
{
- int error;
+ size_t bytesused;
+ int error, revokecnt;
if (ttyhook_hashook(tp, getc_inject))
/* buffer is inaccessible */
return (0);
- while (ttyoutq_bytesused(&tp->t_outq) > 0) {
+ while (ttyoutq_bytesused(&tp->t_outq) > 0 || ttydevsw_busy(tp)) {
ttydevsw_outwakeup(tp);
/* Could be handled synchronously. */
- if (ttyoutq_bytesused(&tp->t_outq) == 0)
+ bytesused = ttyoutq_bytesused(&tp->t_outq);
+ if (bytesused == 0 && !ttydevsw_busy(tp))
return (0);
/* Wait for data to be drained. */
- error = tty_wait(tp, &tp->t_outwait);
+ if (leaving) {
+ revokecnt = tp->t_revokecnt;
+ error = tty_timedwait(tp, &tp->t_outwait, hz);
+ switch (error) {
+ case ERESTART:
+ if (revokecnt != tp->t_revokecnt)
+ error = 0;
+ break;
+ case EWOULDBLOCK:
+ if (ttyoutq_bytesused(&tp->t_outq) < bytesused)
+ error = 0;
+ break;
+ }
+ } else
+ error = tty_wait(tp, &tp->t_outwait);
+
if (error)
return (error);
}
@@ -158,6 +176,7 @@
static __inline int
ttydev_enter(struct tty *tp)
{
+
tty_lock(tp);
if (tty_gone(tp) || !tty_opened(tp)) {
@@ -172,6 +191,7 @@
static void
ttydev_leave(struct tty *tp)
{
+
tty_lock_assert(tp, MA_OWNED);
if (tty_opened(tp) || tp->t_flags & TF_OPENCLOSE) {
@@ -192,11 +212,11 @@
/* Drain any output. */
MPASS((tp->t_flags & TF_STOPPED) == 0);
if (!tty_gone(tp))
- tty_drain(tp);
+ tty_drain(tp, 1);
ttydisc_close(tp);
- /* Destroy associated buffers already. */
+ /* Free i/o queues now since they might be large. */
ttyinq_free(&tp->t_inq);
tp->t_inlow = 0;
ttyoutq_free(&tp->t_outq);
@@ -217,17 +237,14 @@
* Operations that are exposed through the character device in /dev.
*/
static int
-ttydev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
+ttydev_open(struct cdev *dev, int oflags, int devtype __unused,
+ struct thread *td)
{
struct tty *tp;
- int error = 0;
+ int error;
- while ((tp = dev->si_drv1) == NULL) {
- error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1);
- if (error != EWOULDBLOCK)
- return (error);
- }
-
+ tp = dev->si_drv1;
+ error = 0;
tty_lock(tp);
if (tty_gone(tp)) {
/* Device is already gone. */
@@ -250,10 +267,10 @@
/*
* Make sure the "tty" and "cua" device cannot be opened at the
- * same time.
+ * same time. The console is a "tty" device.
*/
if (TTY_CALLOUT(tp, dev)) {
- if (tp->t_flags & TF_OPENED_IN) {
+ if (tp->t_flags & (TF_OPENED_CONS | TF_OPENED_IN)) {
error = EBUSY;
goto done;
}
@@ -287,7 +304,7 @@
goto done;
ttydisc_open(tp);
- tty_watermarks(tp);
+ tty_watermarks(tp); /* XXXGL: drops lock */
}
/* Wait for Carrier Detect. */
@@ -306,6 +323,8 @@
tp->t_flags |= TF_OPENED_OUT;
else
tp->t_flags |= TF_OPENED_IN;
+ MPASS((tp->t_flags & (TF_OPENED_CONS | TF_OPENED_IN)) == 0 ||
+ (tp->t_flags & TF_OPENED_OUT) == 0);
done: tp->t_flags &= ~TF_OPENCLOSE;
cv_broadcast(&tp->t_dcdwait);
@@ -315,7 +334,8 @@
}
static int
-ttydev_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
+ttydev_close(struct cdev *dev, int fflag, int devtype __unused,
+ struct thread *td __unused)
{
struct tty *tp = dev->si_drv1;
@@ -325,7 +345,8 @@
* Don't actually close the device if it is being used as the
* console.
*/
- MPASS((tp->t_flags & TF_OPENED) != TF_OPENED);
+ MPASS((tp->t_flags & (TF_OPENED_CONS | TF_OPENED_IN)) == 0 ||
+ (tp->t_flags & TF_OPENED_OUT) == 0);
if (dev == dev_console)
tp->t_flags &= ~TF_OPENED_CONS;
else
@@ -356,6 +377,7 @@
static __inline int
tty_is_ctty(struct tty *tp, struct proc *p)
{
+
tty_lock_assert(tp, MA_OWNED);
return (p->p_session == tp->t_session && p->p_flag & P_CONTROLT);
@@ -376,7 +398,7 @@
PROC_LOCK(p);
/*
* The process should only sleep, when:
- * - This terminal is the controling terminal
+ * - This terminal is the controlling terminal
* - Its process group is not the foreground process
* group
* - The parent process isn't waiting for the child to
@@ -636,7 +658,7 @@
}
static int
-tty_kqops_read_event(struct knote *kn, long hint)
+tty_kqops_read_event(struct knote *kn, long hint __unused)
{
struct tty *tp = kn->kn_hook;
@@ -660,7 +682,7 @@
}
static int
-tty_kqops_write_event(struct knote *kn, long hint)
+tty_kqops_write_event(struct knote *kn, long hint __unused)
{
struct tty *tp = kn->kn_hook;
@@ -680,6 +702,7 @@
.f_detach = tty_kqops_read_detach,
.f_event = tty_kqops_read_event,
};
+
static struct filterops tty_kqops_write = {
.f_isfd = 1,
.f_detach = tty_kqops_write_detach,
@@ -735,16 +758,14 @@
*/
static int
-ttyil_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
+ttyil_open(struct cdev *dev, int oflags __unused, int devtype __unused,
+ struct thread *td)
{
struct tty *tp;
- int error = 0;
+ int error;
- while ((tp = dev->si_drv1) == NULL) {
- error = tsleep(&dev->si_drv1, PCATCH, "ttdrv1", 1);
- if (error != EWOULDBLOCK)
- return (error);
- }
+ tp = dev->si_drv1;
+ error = 0;
tty_lock(tp);
if (tty_gone(tp))
error = ENODEV;
@@ -754,14 +775,18 @@
}
static int
-ttyil_close(struct cdev *dev, int flag, int mode, struct thread *td)
+ttyil_close(struct cdev *dev __unused, int flag __unused, int mode __unused,
+ struct thread *td __unused)
{
+
return (0);
}
static int
-ttyil_rdwr(struct cdev *dev, struct uio *uio, int ioflag)
+ttyil_rdwr(struct cdev *dev __unused, struct uio *uio __unused,
+ int ioflag __unused)
{
+
return (ENODEV);
}
@@ -858,7 +883,7 @@
*/
static int
-ttydevsw_defopen(struct tty *tp)
+ttydevsw_defopen(struct tty *tp __unused)
{
return (0);
@@ -865,12 +890,13 @@
}
static void
-ttydevsw_defclose(struct tty *tp)
+ttydevsw_defclose(struct tty *tp __unused)
{
+
}
static void
-ttydevsw_defoutwakeup(struct tty *tp)
+ttydevsw_defoutwakeup(struct tty *tp __unused)
{
panic("Terminal device has output, while not implemented");
@@ -877,12 +903,14 @@
}
static void
-ttydevsw_definwakeup(struct tty *tp)
+ttydevsw_definwakeup(struct tty *tp __unused)
{
+
}
static int
-ttydevsw_defioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
+ttydevsw_defioctl(struct tty *tp __unused, u_long cmd __unused,
+ caddr_t data __unused, struct thread *td __unused)
{
return (ENOIOCTL);
@@ -889,7 +917,8 @@
}
static int
-ttydevsw_defcioctl(struct tty *tp, int unit, u_long cmd, caddr_t data, struct thread *td)
+ttydevsw_defcioctl(struct tty *tp __unused, int unit __unused,
+ u_long cmd __unused, caddr_t data __unused, struct thread *td __unused)
{
return (ENOIOCTL);
@@ -896,7 +925,7 @@
}
static int
-ttydevsw_defparam(struct tty *tp, struct termios *t)
+ttydevsw_defparam(struct tty *tp __unused, struct termios *t)
{
/*
@@ -918,7 +947,8 @@
}
static int
-ttydevsw_defmodem(struct tty *tp, int sigon, int sigoff)
+ttydevsw_defmodem(struct tty *tp __unused, int sigon __unused,
+ int sigoff __unused)
{
/* Simulate a carrier to make the TTY layer happy. */
@@ -926,8 +956,9 @@
}
static int
-ttydevsw_defmmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr,
- int nprot, vm_memattr_t *memattr)
+ttydevsw_defmmap(struct tty *tp __unused, vm_ooffset_t offset __unused,
+ vm_paddr_t *paddr __unused, int nprot __unused,
+ vm_memattr_t *memattr __unused)
{
return (-1);
@@ -934,17 +965,25 @@
}
static void
-ttydevsw_defpktnotify(struct tty *tp, char event)
+ttydevsw_defpktnotify(struct tty *tp __unused, char event __unused)
{
+
}
static void
-ttydevsw_deffree(void *softc)
+ttydevsw_deffree(void *softc __unused)
{
panic("Terminal device freed without a free-handler");
}
+static bool
+ttydevsw_defbusy(struct tty *tp __unused)
+{
+
+ return (FALSE);
+}
+
/*
* TTY allocation and deallocation. TTY devices can be deallocated when
* the driver doesn't use it anymore, when the TTY isn't a session's
@@ -979,6 +1018,7 @@
PATCH_FUNC(mmap);
PATCH_FUNC(pktnotify);
PATCH_FUNC(free);
+ PATCH_FUNC(busy);
#undef PATCH_FUNC
tp = malloc(sizeof(struct tty), M_TTY, M_WAITOK|M_ZERO);
@@ -1005,11 +1045,6 @@
knlist_init_mtx(&tp->t_inpoll.si_note, tp->t_mtx);
knlist_init_mtx(&tp->t_outpoll.si_note, tp->t_mtx);
- sx_xlock(&tty_list_sx);
- TAILQ_INSERT_TAIL(&tty_list, tp, t_list);
- tty_list_count++;
- sx_xunlock(&tty_list_sx);
-
return (tp);
}
@@ -1018,15 +1053,15 @@
{
struct tty *tp = arg;
- sx_xlock(&tty_list_sx);
- TAILQ_REMOVE(&tty_list, tp, t_list);
- tty_list_count--;
- sx_xunlock(&tty_list_sx);
-
- /* Make sure we haven't leaked buffers. */
- MPASS(ttyinq_getsize(&tp->t_inq) == 0);
- MPASS(ttyoutq_getsize(&tp->t_outq) == 0);
-
+ /*
+ * ttyydev_leave() usually frees the i/o queues earlier, but it is
+ * not always called between queue allocation and here. The queues
+ * may be allocated by ioctls on a pty control device without the
+ * corresponding pty slave device ever being open, or after it is
+ * closed.
+ */
+ ttyinq_free(&tp->t_inq);
+ ttyoutq_free(&tp->t_outq);
seldrain(&tp->t_inpoll);
seldrain(&tp->t_outpoll);
knlist_destroy(&tp->t_inpoll.si_note);
@@ -1063,13 +1098,19 @@
tp->t_dev = NULL;
tty_unlock(tp);
- if (dev != NULL)
+ if (dev != NULL) {
+ sx_xlock(&tty_list_sx);
+ TAILQ_REMOVE(&tty_list, tp, t_list);
+ tty_list_count--;
+ sx_xunlock(&tty_list_sx);
destroy_dev_sched_cb(dev, tty_dealloc, tp);
+ }
}
void
tty_rel_pgrp(struct tty *tp, struct pgrp *pg)
{
+
MPASS(tp->t_sessioncnt > 0);
tty_lock_assert(tp, MA_OWNED);
@@ -1082,6 +1123,7 @@
void
tty_rel_sess(struct tty *tp, struct session *sess)
{
+
MPASS(tp->t_sessioncnt > 0);
/* Current session has left. */
@@ -1096,6 +1138,7 @@
void
tty_rel_gone(struct tty *tp)
{
+
MPASS(!tty_gone(tp));
/* Simulate carrier removal. */
@@ -1117,6 +1160,7 @@
static void
tty_to_xtty(struct tty *tp, struct xtty *xt)
{
+
tty_lock_assert(tp, MA_OWNED);
xt->xt_size = sizeof(struct xtty);
@@ -1172,24 +1216,24 @@
* the user.
*/
-void
-tty_makedev(struct tty *tp, struct ucred *cred, const char *fmt, ...)
+static int
+tty_vmakedevf(struct tty *tp, struct ucred *cred, int flags,
+ const char *fmt, va_list ap)
{
- va_list ap;
- struct cdev *dev;
+ struct make_dev_args args;
+ struct cdev *dev, *init, *lock, *cua, *cinit, *clock;
const char *prefix = "tty";
char name[SPECNAMELEN - 3]; /* for "tty" and "cua". */
uid_t uid;
gid_t gid;
mode_t mode;
+ int error;
/* Remove "tty" prefix from devices like PTY's. */
if (tp->t_flags & TF_NOPREFIX)
prefix = "";
- va_start(ap, fmt);
vsnrprintf(name, sizeof name, 32, fmt, ap);
- va_end(ap);
if (cred == NULL) {
/* System device. */
@@ -1203,59 +1247,124 @@
mode = S_IRUSR|S_IWUSR|S_IWGRP;
}
+ flags = flags & TTYMK_CLONING ? MAKEDEV_REF : 0;
+ flags |= MAKEDEV_CHECKNAME;
+
/* Master call-in device. */
- dev = make_dev_cred(&ttydev_cdevsw, 0, cred,
- uid, gid, mode, "%s%s", prefix, name);
- dev->si_drv1 = tp;
- wakeup(&dev->si_drv1);
+ make_dev_args_init(&args);
+ args.mda_flags = flags;
+ args.mda_devsw = &ttydev_cdevsw;
+ args.mda_cr = cred;
+ args.mda_uid = uid;
+ args.mda_gid = gid;
+ args.mda_mode = mode;
+ args.mda_si_drv1 = tp;
+ error = make_dev_s(&args, &dev, "%s%s", prefix, name);
+ if (error != 0)
+ return (error);
tp->t_dev = dev;
+ init = lock = cua = cinit = clock = NULL;
+
/* Slave call-in devices. */
if (tp->t_flags & TF_INITLOCK) {
- dev = make_dev_cred(&ttyil_cdevsw, TTYUNIT_INIT, cred,
- uid, gid, mode, "%s%s.init", prefix, name);
- dev_depends(tp->t_dev, dev);
- dev->si_drv1 = tp;
- wakeup(&dev->si_drv1);
- dev->si_drv2 = &tp->t_termios_init_in;
+ args.mda_devsw = &ttyil_cdevsw;
+ args.mda_unit = TTYUNIT_INIT;
+ args.mda_si_drv1 = tp;
+ args.mda_si_drv2 = &tp->t_termios_init_in;
+ error = make_dev_s(&args, &init, "%s%s.init", prefix, name);
+ if (error != 0)
+ goto fail;
+ dev_depends(dev, init);
- dev = make_dev_cred(&ttyil_cdevsw, TTYUNIT_LOCK, cred,
- uid, gid, mode, "%s%s.lock", prefix, name);
- dev_depends(tp->t_dev, dev);
- dev->si_drv1 = tp;
- wakeup(&dev->si_drv1);
- dev->si_drv2 = &tp->t_termios_lock_in;
+ args.mda_unit = TTYUNIT_LOCK;
+ args.mda_si_drv2 = &tp->t_termios_lock_in;
+ error = make_dev_s(&args, &lock, "%s%s.lock", prefix, name);
+ if (error != 0)
+ goto fail;
+ dev_depends(dev, lock);
}
/* Call-out devices. */
if (tp->t_flags & TF_CALLOUT) {
- dev = make_dev_cred(&ttydev_cdevsw, TTYUNIT_CALLOUT, cred,
- UID_UUCP, GID_DIALER, 0660, "cua%s", name);
- dev_depends(tp->t_dev, dev);
- dev->si_drv1 = tp;
- wakeup(&dev->si_drv1);
+ make_dev_args_init(&args);
+ args.mda_flags = flags;
+ args.mda_devsw = &ttydev_cdevsw;
+ args.mda_cr = cred;
+ args.mda_uid = UID_UUCP;
+ args.mda_gid = GID_DIALER;
+ args.mda_mode = 0660;
+ args.mda_unit = TTYUNIT_CALLOUT;
+ args.mda_si_drv1 = tp;
+ error = make_dev_s(&args, &cua, "cua%s", name);
+ if (error != 0)
+ goto fail;
+ dev_depends(dev, cua);
/* Slave call-out devices. */
if (tp->t_flags & TF_INITLOCK) {
- dev = make_dev_cred(&ttyil_cdevsw,
- TTYUNIT_CALLOUT | TTYUNIT_INIT, cred,
- UID_UUCP, GID_DIALER, 0660, "cua%s.init", name);
- dev_depends(tp->t_dev, dev);
- dev->si_drv1 = tp;
- wakeup(&dev->si_drv1);
- dev->si_drv2 = &tp->t_termios_init_out;
+ args.mda_devsw = &ttyil_cdevsw;
+ args.mda_unit = TTYUNIT_CALLOUT | TTYUNIT_INIT;
+ args.mda_si_drv2 = &tp->t_termios_init_out;
+ error = make_dev_s(&args, &cinit, "cua%s.init", name);
+ if (error != 0)
+ goto fail;
+ dev_depends(dev, cinit);
- dev = make_dev_cred(&ttyil_cdevsw,
- TTYUNIT_CALLOUT | TTYUNIT_LOCK, cred,
- UID_UUCP, GID_DIALER, 0660, "cua%s.lock", name);
- dev_depends(tp->t_dev, dev);
- dev->si_drv1 = tp;
- wakeup(&dev->si_drv1);
- dev->si_drv2 = &tp->t_termios_lock_out;
+ args.mda_unit = TTYUNIT_CALLOUT | TTYUNIT_LOCK;
+ args.mda_si_drv2 = &tp->t_termios_lock_out;
+ error = make_dev_s(&args, &clock, "cua%s.lock", name);
+ if (error != 0)
+ goto fail;
+ dev_depends(dev, clock);
}
}
+
+ sx_xlock(&tty_list_sx);
+ TAILQ_INSERT_TAIL(&tty_list, tp, t_list);
+ tty_list_count++;
+ sx_xunlock(&tty_list_sx);
+
+ return (0);
+
+fail:
+ destroy_dev(dev);
+ if (init)
+ destroy_dev(init);
+ if (lock)
+ destroy_dev(lock);
+ if (cinit)
+ destroy_dev(cinit);
+ if (clock)
+ destroy_dev(clock);
+
+ return (error);
}
+int
+tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
+ const char *fmt, ...)
+{
+ va_list ap;
+ int error;
+
+ va_start(ap, fmt);
+ error = tty_vmakedevf(tp, cred, flags, fmt, ap);
+ va_end(ap);
+
+ return (error);
+}
+
+void
+tty_makedev(struct tty *tp, struct ucred *cred, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void) tty_vmakedevf(tp, cred, 0, fmt, ap);
+ va_end(ap);
+}
+
/*
* Signalling processes.
*/
@@ -1305,6 +1414,7 @@
void
tty_wakeup(struct tty *tp, int flags)
{
+
if (tp->t_flags & TF_ASYNC && tp->t_sigio != NULL)
pgsigio(&tp->t_sigio, SIGIO, (tp->t_session != NULL));
@@ -1331,14 +1441,14 @@
error = cv_wait_sig(cv, tp->t_mtx);
+ /* Bail out when the device slipped away. */
+ if (tty_gone(tp))
+ return (ENXIO);
+
/* Restart the system call when we may have been revoked. */
if (tp->t_revokecnt != revokecnt)
return (ERESTART);
- /* Bail out when the device slipped away. */
- if (tty_gone(tp))
- return (ENXIO);
-
return (error);
}
@@ -1353,14 +1463,14 @@
error = cv_timedwait_sig(cv, tp->t_mtx, hz);
+ /* Bail out when the device slipped away. */
+ if (tty_gone(tp))
+ return (ENXIO);
+
/* Restart the system call when we may have been revoked. */
if (tp->t_revokecnt != revokecnt)
return (ERESTART);
- /* Bail out when the device slipped away. */
- if (tty_gone(tp))
- return (ENXIO);
-
return (error);
}
@@ -1367,6 +1477,7 @@
void
tty_flush(struct tty *tp, int flags)
{
+
if (flags & FWRITE) {
tp->t_flags &= ~TF_HIWAT_OUT;
ttyoutq_flush(&tp->t_outq);
@@ -1381,6 +1492,16 @@
}
}
+void
+tty_set_winsize(struct tty *tp, const struct winsize *wsz)
+{
+
+ if (memcmp(&tp->t_winsize, wsz, sizeof(*wsz)) == 0)
+ return;
+ tp->t_winsize = *wsz;
+ tty_signal_pgrp(tp, SIGWINCH);
+}
+
static int
tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag,
struct thread *td)
@@ -1479,7 +1600,7 @@
/* Set terminal flags through tcsetattr(). */
if (cmd == TIOCSETAW || cmd == TIOCSETAF) {
- error = tty_drain(tp);
+ error = tty_drain(tp, 0);
if (error)
return (error);
if (cmd == TIOCSETAF)
@@ -1658,7 +1779,7 @@
}
case TIOCDRAIN:
/* Drain TTY output. */
- return tty_drain(tp);
+ return tty_drain(tp, 0);
case TIOCCONS:
/* Set terminal as console TTY. */
if (*(int *)data) {
@@ -1689,10 +1810,7 @@
return (0);
case TIOCSWINSZ:
/* Set window size. */
- if (bcmp(&tp->t_winsize, data, sizeof(struct winsize)) == 0)
- return (0);
- tp->t_winsize = *(struct winsize*)data;
- tty_signal_pgrp(tp, SIGWINCH);
+ tty_set_winsize(tp, data);
return (0);
case TIOCEXCL:
tp->t_flags |= TF_EXCLUDE;
@@ -1750,10 +1868,11 @@
dev_t
tty_udev(struct tty *tp)
{
+
if (tp->t_dev)
- return dev2udev(tp->t_dev);
+ return (dev2udev(tp->t_dev));
else
- return NODEV;
+ return (NODEV);
}
int
@@ -1822,38 +1941,28 @@
}
int
-ttyhook_register(struct tty **rtp, struct proc *p, int fd,
- struct ttyhook *th, void *softc)
+ttyhook_register(struct tty **rtp, struct proc *p, int fd, struct ttyhook *th,
+ void *softc)
{
struct tty *tp;
struct file *fp;
-#ifdef CAPABILITIES
- struct file *fp_cap;
-#endif
struct cdev *dev;
struct cdevsw *cdp;
struct filedesc *fdp;
+ cap_rights_t rights;
int error, ref;
/* Validate the file descriptor. */
- if ((fdp = p->p_fd) == NULL)
- return (EBADF);
-
- fp = fget_unlocked(fdp, fd);
- if (fp == NULL)
- return (EBADF);
+ fdp = p->p_fd;
+ error = fget_unlocked(fdp, fd, cap_rights_init(&rights, CAP_TTYHOOK),
+ 0, &fp, NULL);
+ if (error != 0)
+ return (error);
if (fp->f_ops == &badfileops) {
error = EBADF;
goto done1;
}
-#ifdef CAPABILITIES
- fp_cap = fp;
- error = cap_funwrap(fp_cap, CAP_TTYHOOK, &fp);
- if (error)
- return (error);
-#endif
-
/*
* Make sure the vnode is bound to a character device.
* Unlocked check for the vnode type is ok there, because we
@@ -1984,7 +2093,7 @@
};
static void
-ttyconsdev_init(void *unused)
+ttyconsdev_init(void *unused __unused)
{
dev_console = make_dev_credf(MAKEDEV_ETERNAL, &ttyconsdev_cdevsw, 0,
@@ -2009,7 +2118,7 @@
#include <ddb/ddb.h>
#include <ddb/db_sym.h>
-static struct {
+static const struct {
int flag;
char val;
} ttystates[] = {
@@ -2050,9 +2159,11 @@
};
#define TTY_FLAG_BITS \
- "\20\1NOPREFIX\2INITLOCK\3CALLOUT\4OPENED_IN\5OPENED_OUT\6GONE" \
- "\7OPENCLOSE\10ASYNC\11LITERAL\12HIWAT_IN\13HIWAT_OUT\14STOPPED" \
- "\15EXCLUDE\16BYPASS\17ZOMBIE\20HOOK"
+ "\20\1NOPREFIX\2INITLOCK\3CALLOUT\4OPENED_IN" \
+ "\5OPENED_OUT\6OPENED_CONS\7GONE\10OPENCLOSE" \
+ "\11ASYNC\12LITERAL\13HIWAT_IN\14HIWAT_OUT" \
+ "\15STOPPED\16EXCLUDE\17BYPASS\20ZOMBIE" \
+ "\21HOOK\22BUSY_IN\23BUSY_OUT"
#define DB_PRINTSYM(name, addr) \
db_printf("%s " #name ": ", sep); \
@@ -2062,6 +2173,7 @@
static void
_db_show_devsw(const char *sep, const struct ttydevsw *tsw)
{
+
db_printf("%sdevsw: ", sep);
db_printsym((db_addr_t)tsw, DB_STGY_ANY);
db_printf(" (%p)\n", tsw);
@@ -2076,9 +2188,11 @@
DB_PRINTSYM(pktnotify, tsw->tsw_pktnotify);
DB_PRINTSYM(free, tsw->tsw_free);
}
+
static void
_db_show_hooks(const char *sep, const struct ttyhook *th)
{
+
db_printf("%shook: ", sep);
db_printsym((db_addr_t)th, DB_STGY_ANY);
db_printf(" (%p)\n", th);
@@ -2115,9 +2229,9 @@
}
tp = (struct tty *)addr;
- db_printf("0x%p: %s\n", tp, tty_devname(tp));
+ db_printf("%p: %s\n", tp, tty_devname(tp));
db_printf("\tmtx: %p\n", tp->t_mtx);
- db_printf("\tflags: %b\n", tp->t_flags, TTY_FLAG_BITS);
+ db_printf("\tflags: 0x%b\n", tp->t_flags, TTY_FLAG_BITS);
db_printf("\trevokecnt: %u\n", tp->t_revokecnt);
/* Buffering mechanisms. */
@@ -2184,17 +2298,13 @@
isiz = tp->t_inq.ti_nblocks * TTYINQ_DATASIZE;
osiz = tp->t_outq.to_nblocks * TTYOUTQ_DATASIZE;
- db_printf("%p %10s %5zu %4u %4u %4zu %5zu %4u %4zu %5u %5d %5d ",
- tp,
- tty_devname(tp),
- isiz,
+ db_printf("%p %10s %5zu %4u %4u %4zu %5zu %4u %4zu %5u %5d "
+ "%5d ", tp, tty_devname(tp), isiz,
tp->t_inq.ti_linestart - tp->t_inq.ti_begin,
tp->t_inq.ti_end - tp->t_inq.ti_linestart,
- isiz - tp->t_inlow,
- osiz,
+ isiz - tp->t_inlow, osiz,
tp->t_outq.to_end - tp->t_outq.to_begin,
- osiz - tp->t_outlow,
- MIN(tp->t_column, 99999),
+ osiz - tp->t_outlow, MIN(tp->t_column, 99999),
tp->t_session ? tp->t_session->s_sid : 0,
tp->t_pgrp ? tp->t_pgrp->pg_id : 0);
Modified: trunk/sys/kern/tty_compat.c
===================================================================
--- trunk/sys/kern/tty_compat.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_compat.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -30,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_compat.c 201532 2010-01-04 20:59:52Z ed $");
#include "opt_compat.h"
Modified: trunk/sys/kern/tty_info.c
===================================================================
--- trunk/sys/kern/tty_info.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_info.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1982, 1986, 1990, 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_info.c 231095 2012-02-06 18:15:46Z ed $");
#include <sys/param.h>
#include <sys/lock.h>
@@ -109,7 +110,7 @@
/*
* Fetch running stats, pctcpu usage, and interruptable flag.
- */
+ */
thread_lock(td);
runa = TD_IS_RUNNING(td) | TD_ON_RUNQ(td);
slpa = td->td_flags & TDF_SINTR;
@@ -173,7 +174,7 @@
PROC_LOCK(p2);
runb = proc_sum(p2, &estb);
PROC_UNLOCK(p2);
-
+
/*
* see if at least one of them is runnable
*/
Modified: trunk/sys/kern/tty_inq.c
===================================================================
--- trunk/sys/kern/tty_inq.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_inq.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Ed Schouten <ed at FreeBSD.org>
* All rights reserved.
@@ -28,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_inq.c 229272 2012-01-02 12:12:10Z ed $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -355,7 +356,7 @@
return (0);
while (boff < bend) {
- if (index(breakc, tib->tib_data[boff]) && !GETBIT(tib, boff)) {
+ if (strchr(breakc, tib->tib_data[boff]) && !GETBIT(tib, boff)) {
*lastc = tib->tib_data[boff];
return (boff - ti->ti_begin + 1);
}
Modified: trunk/sys/kern/tty_outq.c
===================================================================
--- trunk/sys/kern/tty_outq.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_outq.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Ed Schouten <ed at FreeBSD.org>
* All rights reserved.
@@ -28,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_outq.c 223575 2011-06-26 18:26:20Z ed $");
#include <sys/param.h>
#include <sys/kernel.h>
Modified: trunk/sys/kern/tty_pts.c
===================================================================
--- trunk/sys/kern/tty_pts.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_pts.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Ed Schouten <ed at FreeBSD.org>
* All rights reserved.
@@ -28,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_pts.c 321020 2017-07-15 17:25:40Z dchagin $");
/* Add compatibility bits for FreeBSD. */
#define PTS_COMPAT
@@ -123,7 +124,7 @@
/*
* Implement packet mode. When packet mode is turned on,
* the first byte contains a bitmask of events that
- * occured (start, stop, flush, window size, etc).
+ * occurred (start, stop, flush, window size, etc).
*/
if (psc->pts_flags & PTS_PKT && psc->pts_pkt) {
pkt = psc->pts_pkt;
@@ -269,6 +270,9 @@
int error = 0, sig;
switch (cmd) {
+ case FIODTYPE:
+ *(int *)data = D_TTY;
+ return (0);
case FIONBIO:
/* This device supports non-blocking operation. */
return (0);
@@ -599,6 +603,7 @@
.fo_close = ptsdev_close,
.fo_chmod = invfo_chmod,
.fo_chown = invfo_chown,
+ .fo_sendfile = invfo_sendfile,
.fo_flags = DFLAG_PASSABLE,
};
@@ -835,7 +840,7 @@
/* Allocate the actual pseudo-TTY. */
error = pts_alloc(FFLAGS(uap->flags & O_ACCMODE), td, fp);
if (error != 0) {
- fdclose(td->td_proc->p_fd, fp, fd, td);
+ fdclose(td, fp, fd);
fdrop(fp, td);
return (error);
}
Modified: trunk/sys/kern/tty_tty.c
===================================================================
--- trunk/sys/kern/tty_tty.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_tty.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Poul-Henning Kamp. All rights reserved.
*
@@ -24,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_tty.c 216952 2011-01-04 10:59:38Z kib $");
#include <sys/param.h>
#include <sys/systm.h>
Modified: trunk/sys/kern/tty_ttydisc.c
===================================================================
--- trunk/sys/kern/tty_ttydisc.c 2018-05-26 14:24:52 UTC (rev 9952)
+++ trunk/sys/kern/tty_ttydisc.c 2018-05-26 14:25:17 UTC (rev 9953)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Ed Schouten <ed at FreeBSD.org>
* All rights reserved.
@@ -28,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/kern/tty_ttydisc.c 242078 2012-10-25 09:05:21Z ed $");
#include <sys/param.h>
#include <sys/fcntl.h>
@@ -677,7 +678,6 @@
return ttydisc_echo_force(tp, c, quote);
}
-
static void
ttydisc_reprint_char(void *d, char c, int quote)
{
More information about the Midnightbsd-cvs
mailing list