From nobody Tue Jan 16 02:56:28 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TDYYm5Mb3z56SRC; Tue, 16 Jan 2024 02:56:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TDYYm3J5kz4fJS; Tue, 16 Jan 2024 02:56:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705373788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Yd0oG4XORcZGVF0UDzNwrRSud2Rg0xRIZM6Ckj4yUNU=; b=ibyUpwAtL7qBmuTqhnkRigW+6tYhpB+icSsM8oi5noRmtqq+gCfzz6xBCtvsX5I/XZ4sJY nhEES22X0TlMW4gB4SE0t3tIcSJJdb61sKZEeLCpbEPgsVqT3HNsVuOrjY+kGmMu8tIZyF IXW+OXDFfkk6qx9ZWgaqfc2YUkJKpMREoI3bf4DqF8nqIygFt1SHj0QB3VxHziOG5X0Vw7 Xj1BNqMNKLfB28UN6LftYCYn7+8ZQ5jf6/WvxCwBzfDB9PF4VZyKLGFhJAke5u2fJd0EPV oDMEbXkI/3+RNbjofLSuV4yx/rCxUL054PzY66IKFeNchwS5BYDh2+/VWQ+CXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705373788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Yd0oG4XORcZGVF0UDzNwrRSud2Rg0xRIZM6Ckj4yUNU=; b=JBEIYN4jtME7HJ4+tvSd93D2udFNJoHqERkBsLu5FkQxOZ2GDEQasdPRXidXY0cku5SgtR 3m6v26M8Nzos7ffIa98iyxre3/snEwdboOlDZZ/E7+LF+ncZSpePtavBMGnBtl4Uvs5qC2 JKlvGVSXhoY5CFGNHvoPD6AFXvCOh2Ar19IPcUE7nMG/Cv4ga2NQtl0L+vTZsb38L1yX3I 6onj1kqkLaP4qT97j2PSh7uFuiFWdP/bEBLbdA9wNDn8fMnuoqXhYkC36OHxANh/YS/Jsi taP8607wuQOEGCUCl8xtpIEzHLTO68kk1xhlWKznFTwSUYj3MplLTdM4LqGc4Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705373788; a=rsa-sha256; cv=none; b=bcqjxvCGM3TejKVq6Us7tYLvL4f74b/0+mJQKM+eGGA3DDBTtH0mGMdEyMN6Firg1c3Xrq FmQrysvUnPQwbU9uA6BbaiXwgOJ2e3H6sFOTDFaMPtI3BzinTeQByiYk95nqpoo8+oeZ3a pIXpwHT4602hnSJJIVl1k+yIzoK1ogThvym3Uit00Cgc9SsLBVggu3XgIBsutyforTEEgN L4haPXUxYhXIZVaQrgmHpUvhZwg8ZqtASzrx0yD+knd2V3gFkb1eMQPnp2wA7wx9yn8FMz bJu3x87cgn6d5XlL7TpzoV58pMdzXjIb/k0DZmAtfx0gYn8hzqQamcS2RdDduQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TDYYm21ZczMxk; Tue, 16 Jan 2024 02:56:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40G2uS3q071608; Tue, 16 Jan 2024 02:56:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40G2uSXl071605; Tue, 16 Jan 2024 02:56:28 GMT (envelope-from git) Date: Tue, 16 Jan 2024 02:56:28 GMT Message-Id: <202401160256.40G2uSXl071605@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 30189156d325 - main - kern: pts: do not special case closed slave side List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 30189156d325fbcc9d1997d791daedc9fa3bed20 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=30189156d325fbcc9d1997d791daedc9fa3bed20 commit 30189156d325fbcc9d1997d791daedc9fa3bed20 Author: Kyle Evans AuthorDate: 2024-01-16 02:55:59 +0000 Commit: Kyle Evans CommitDate: 2024-01-16 02:55:59 +0000 kern: pts: do not special case closed slave side This would previously return 1 if the slave side of the pts was closed to force an application to read() from it and observe the EOF, but it's not clear why and this is inconsistent both with how we handle devices with similar mechanics (like pipes) and also with other kernels, such as OpenBSD/NetBSD and Linux. PR: 239604 Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43457 --- sys/kern/tty_pts.c | 7 +----- tests/sys/kern/Makefile | 3 +++ tests/sys/kern/tty_pts.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/sys/kern/tty_pts.c b/sys/kern/tty_pts.c index f79c9cc3e979..31122d422a28 100644 --- a/sys/kern/tty_pts.c +++ b/sys/kern/tty_pts.c @@ -271,12 +271,7 @@ ptsdev_ioctl(struct file *fp, u_long cmd, void *data, return (0); case FIONREAD: tty_lock(tp); - if (psc->pts_flags & PTS_FINISHED) { - /* Force read() to be called. */ - *(int *)data = 1; - } else { - *(int *)data = ttydisc_getc_poll(tp); - } + *(int *)data = ttydisc_getc_poll(tp); tty_unlock(tp); return (0); case FIODGNAME: diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 143c13297585..7b5d87ff30ac 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -40,6 +40,7 @@ ATF_TESTS_C+= subr_physmem_test PLAIN_TESTS_C+= subr_unit_test ATF_TESTS_C+= sysctl_kern_proc ATF_TESTS_C+= sys_getrandom +ATF_TESTS_C+= tty_pts ATF_TESTS_C+= unix_dgram ATF_TESTS_C+= unix_passfd_dgram TEST_METADATA.unix_passfd_dgram+= is_exclusive="true" @@ -89,6 +90,8 @@ NETBSD_ATF_TESTS_C+= sysv_test CFLAGS.mqueue_test+= -I${SRCTOP}/tests LIBADD.mqueue_test+= rt +LIBADD.tty_pts+= atf_c util + ATF_TESTS_C+= libkern_crc32 SRCS.libkern_crc32+= libkern_crc32.c .PATH: ${SRCTOP}/sys/libkern diff --git a/tests/sys/kern/tty_pts.c b/tests/sys/kern/tty_pts.c new file mode 100644 index 000000000000..241cb085a5a7 --- /dev/null +++ b/tests/sys/kern/tty_pts.c @@ -0,0 +1,64 @@ +/*- + * Copyright (c) 2024 Kyle Evans + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +#include + +#include +#include + +/* Just a little more concise. */ +#define newpty(masterp, slavep) openpty((masterp), (slavep), NULL, NULL, NULL) + +ATF_TC_WITHOUT_HEAD(fionread); +ATF_TC_BODY(fionread, tc) +{ + char rbuf[32]; + char buf[] = "Hello"; + int master, slave; + int bytes; + + ATF_REQUIRE_EQ(0, newpty(&master, &slave)); + + /* Should be empty to begin with. */ + ATF_REQUIRE_EQ(0, ioctl(master, FIONREAD, &bytes)); + ATF_REQUIRE_EQ(0, bytes); + + ATF_REQUIRE_EQ(sizeof(buf) - 1, write(slave, buf, sizeof(buf) - 1)); + ATF_REQUIRE_EQ(0, ioctl(master, FIONREAD, &bytes)); + ATF_REQUIRE_EQ(sizeof(buf) - 1, bytes); + + /* Drain what we have available, should result in 0 bytes again. */ + ATF_REQUIRE_EQ(sizeof(buf) - 1, read(master, rbuf, sizeof(rbuf))); + ATF_REQUIRE_EQ(0, ioctl(master, FIONREAD, &bytes)); + ATF_REQUIRE_EQ(0, bytes); + + /* + * Write once more, then close the slave side with data still in the + * buffer. + */ + ATF_REQUIRE_EQ(sizeof(buf) - 1, write(slave, buf, sizeof(buf) - 1)); + ATF_REQUIRE_EQ(0, ioctl(master, FIONREAD, &bytes)); + ATF_REQUIRE_EQ(sizeof(buf) - 1, bytes); + + ATF_REQUIRE_EQ(0, close(slave)); + + /* + * The tty's output queue is discarded upon close, so we shouldn't have + * anything else to read(). + */ + ATF_REQUIRE_EQ(0, ioctl(master, FIONREAD, &bytes)); + ATF_REQUIRE_EQ(0, bytes); + ATF_REQUIRE_EQ(0, read(master, rbuf, sizeof(rbuf))); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, fionread); + return (atf_no_error()); +}