Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src Pull up following revision(s) (requested by kamil in tick...



details:   https://anonhg.NetBSD.org/src/rev/ff0995d3858d
branches:  netbsd-8
changeset: 449284:ff0995d3858d
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Mar 01 18:59:58 2019 +0000

description:
Pull up following revision(s) (requested by kamil in ticket #1201):

        tests/kernel/kqueue/read/t_ttypty.c: revision 1.3
        sys/kern/tty_pty.c: revision 1.145

Fix reporting EOF via kevent and add a test case

Fix the kernel pty driver to report closed slave via master's kevent
EVFILT_READ.  This behavior matches the behavior for pipes, is
consistent with how FreeBSD implements it and is relied upon by LLDB's
main loop implementation.

Includes feedback by kre and kamil (from tech-kern), commit approved
by kamil.

diffstat:

 sys/kern/tty_pty.c                  |   8 ++++-
 tests/kernel/kqueue/read/t_ttypty.c |  47 +++++++++++++++++++++++++++++++++---
 2 files changed, 49 insertions(+), 6 deletions(-)

diffs (106 lines):

diff -r f2510803c3f4 -r ff0995d3858d sys/kern/tty_pty.c
--- a/sys/kern/tty_pty.c        Fri Mar 01 17:41:05 2019 +0000
+++ b/sys/kern/tty_pty.c        Fri Mar 01 18:59:58 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tty_pty.c,v 1.142 2015/08/20 09:45:45 christos Exp $   */
+/*     $NetBSD: tty_pty.c,v 1.142.10.1 2019/03/01 18:59:58 martin Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.142 2015/08/20 09:45:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.142.10.1 2019/03/01 18:59:58 martin Exp $");
 
 #include "opt_ptm.h"
 
@@ -938,6 +938,10 @@
                    ((pti->pt_flags & PF_UCNTL) && pti->pt_ucntl))
                        kn->kn_data++;
        }
+       if (!ISSET(tp->t_state, TS_CARR_ON)) {
+               kn->kn_flags |= EV_EOF;
+               canread = 1;
+       }
 
        if ((hint & NOTE_SUBMIT) == 0) {
                mutex_spin_exit(&tty_lock);
diff -r f2510803c3f4 -r ff0995d3858d tests/kernel/kqueue/read/t_ttypty.c
--- a/tests/kernel/kqueue/read/t_ttypty.c       Fri Mar 01 17:41:05 2019 +0000
+++ b/tests/kernel/kqueue/read/t_ttypty.c       Fri Mar 01 18:59:58 2019 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */
+/* $NetBSD: t_ttypty.c,v 1.2.6.1 2019/03/01 18:59:58 martin Exp $ */
 
 /*-
- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2002, 2008, 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,11 +30,12 @@
  */
 
 #include <sys/cdefs.h>
-__COPYRIGHT("@(#) Copyright (c) 2008\
+__COPYRIGHT("@(#) Copyright (c) 2008, 2019\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_ttypty.c,v 1.2.6.1 2019/03/01 18:59:58 martin Exp $");
 
 #include <sys/event.h>
+#include <sys/time.h>
 #include <sys/wait.h>
 
 #include <poll.h>
@@ -135,10 +136,48 @@
        h_check(false);
 }
 
+ATF_TC(closed_slave);
+ATF_TC_HEAD(closed_slave, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+               "Checks EVFILT_READ reporting for slave tty being closed");
+}
+ATF_TC_BODY(closed_slave, tc)
+{
+       char slavetty[1024];
+       struct kevent event[1];
+       int amaster, aslave;
+       int kq, n;
+       struct timespec timeout = {5, 0};
+
+       RL(openpty(&amaster, &aslave, slavetty, NULL, NULL));
+
+       (void)printf("tty: openpty master %d slave %d tty '%s'\n",
+               amaster, aslave, slavetty);
+
+       RL(kq = kqueue());
+
+       EV_SET(&event[0], amaster, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0);
+       RL(kevent(kq, event, 1, NULL, 0, NULL));
+
+       RL(close(aslave));
+
+       RL(n = kevent(kq, NULL, 0, event, 1, &timeout));
+
+       (void)printf("kevent num %d filt %d flags: %#x, fflags: %#x, "
+           "data: %" PRId64 "\n", n, event[0].filter, event[0].flags,
+           event[0].fflags, event[0].data);
+
+       ATF_REQUIRE_EQ(n, 1);
+       ATF_REQUIRE_EQ(event[0].filter, EVFILT_READ);
+       ATF_REQUIRE_EQ(event[0].flags & EV_EOF, EV_EOF);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, master);
        ATF_TP_ADD_TC(tp, slave);
+       ATF_TP_ADD_TC(tp, closed_slave);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index