From nobody Tue Jan 30 17:11:30 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 4TPWst3MfVz59C38; Tue, 30 Jan 2024 17:11:30 +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 4TPWst29Y1z4F7v; Tue, 30 Jan 2024 17:11:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706634690; 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=aW9huxDQzJgDQ7O8xkwVXG/xIjYYWRjCsobt0RbtypE=; b=qNp2M+QCun6IRRrJRq9SWh/BuXFOEXckMMHSHcMYA9yH2ZzHr9a/AjQcJQHlDf0cAM6a08 YRUZw3Zz98fEfL3udDD6Xhpc+xrt61tt2hHsM7gKSh6AgwmzbvQKE0xQNRWpMjX0Eo5QxF xP4zYk1X93xtuViZFATKm8YzO9pW3hybyD5M2hAcAnyxjCMDPeMLy4DtZHH+qo/bKNN7YK kDZNTkM6N627PeF3a1HQ3MweKF/NG0yfGITnBfeKWds8liJRK3grl6pirPKL9Jk5/MVKbv Zl3axGaHqq3MxOMPpTnRecWSWqf+GjorNrPLN2BEXvM3aF1+ztV14bS3wgtZQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706634690; 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=aW9huxDQzJgDQ7O8xkwVXG/xIjYYWRjCsobt0RbtypE=; b=QP7b8MtcTAVDOuSF8wUV17oPxKU9UCoAIPPKhrtmp3KQLn3lqixgwjo1N5HobueGk58lwC YpjVe77a5UV8CFEEDVPaTgxsfHM8yVWjM/vnupxmmVqoK97GVMasCVxFeVALjm8Q0fUJvB xt3KW1vRvWaIZlYcCaBasOrplanjQS2SMCGrNNWN/UoURq226WG5JYxI2vqHQzz9nTQsET ylmNxd4IvYmoxJnPzPNddC9Ms+OcbUsk+KROFAFmD0SZxrgZmoWUVV8LpfzAmTADv0fijo uskVKH3ILptBuBERzrpIwNdys19HdIO8PZ5qhdxEZB0Be+i9GudZrQDnrJNW3w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706634690; a=rsa-sha256; cv=none; b=JdeXGDBa4dHAqb1tnD2wfuWBwfftYnEoXEovhGVvqmjtEHNITm4fj4Rqr0OFI9mNgl+g7H aOVaVHvl1ocavu81ioISCCuiXG1CvyylCBpfnY5l4/WQ0AWHcEuNOreYa0mhingueNpDo9 qKaw9JSUFNbM6zvnCwFyerz0DLfVabUa9eCmQCXwVZdlVKDKKPagL+ycdqvtOFqE51+h8m tG0+Lj1g+tk7nZzVHFGBwgKMMqQf8TRIRPVTLXG2sEQERZYWucl2JVx0iJWdiskWEHtU/S R9kllh6pfWDKJR7gMfs7dCUy5BFrdsWLcqXdsJVwRl3HqTdRzKxDlGvddYTcXw== 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 4TPWst1GZfzklx; Tue, 30 Jan 2024 17:11:30 +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 40UHBUNS093895; Tue, 30 Jan 2024 17:11:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40UHBUPF093893; Tue, 30 Jan 2024 17:11:30 GMT (envelope-from git) Date: Tue, 30 Jan 2024 17:11:30 GMT Message-Id: <202401301711.40UHBUPF093893@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: aebaa32c3108 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: aebaa32c3108e99cc28d9aef7229ed4fe7da18ca Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=aebaa32c3108e99cc28d9aef7229ed4fe7da18ca commit aebaa32c3108e99cc28d9aef7229ed4fe7da18ca Author: Kyle Evans AuthorDate: 2024-01-16 02:55:59 +0000 Commit: Kyle Evans CommitDate: 2024-01-30 17:11:24 +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 (cherry picked from commit 30189156d325fbcc9d1997d791daedc9fa3bed20) --- 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 e449d9deeed1..b95be12d9665 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -38,6 +38,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" @@ -86,6 +87,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()); +}