From nobody Tue Jan 30 17:11:26 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 4TPWsp6hdrz59Bv4; Tue, 30 Jan 2024 17:11:26 +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 4TPWsp2vFQz4F2d; Tue, 30 Jan 2024 17:11:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706634686; 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=12mMrBwnJqOzbJMsYPBu2SrxBQMqbOfg9jI2CQgtjeo=; b=Q8m7/71A+ubhxVlCX2HAJHP8Xnoej3Ae6qf7gpfT6R0e0FeIoKbcDPzV50wF7kEhbdEcyl g9BE5o4w+gCllRpXa3OsnA3BcHTF6I9ypsP0l23PV2NWlm/6l0ylP0d45RXrHl0DnRRY45 TB66JLLXjBBrvdmJUEf5/dkX9RCmbHE9xP67ljj3oS5Tkci9cHFJ0BV3tX7x6zYbbxbIhH U4mLzj+mouSrvyCErW/aRM9iA3LABX/wWfaSBkfFfpsSv3lYKqr+dQVeBhf0UINzSQNe0F nkjEJ8eCBV1m/OUYKPHLMl9HNr3Xk60QKnpfF97ypuXKHeNolokKNjAl/AkcSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706634686; 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=12mMrBwnJqOzbJMsYPBu2SrxBQMqbOfg9jI2CQgtjeo=; b=RYZM7pfbhstsVnwX+/bzAdehwZIXL6m3RSzFk32khTDBIKMeo1QG1sKbdephpYV5igGWPw vl51cIfdAuTKhYnSaAPQ/zAt1e477BA5k3SDW/aB8S97CUmwPz77HOQIBmZiuMv64b16OB 6HqCQi0XCX1XnUHK6htnVlyUwbqGVtKiWmO46bUTSGmNn0ByRjYr6gV0w/K8X3Mr2BcQrs XZIF1/IBeKeC7RZ8/DkYGsMdkYVSq9oOaBk081KDYkOZvQYmartK3oW3c7TF7Dtvi9PZIn A5eR5ieItI2+EX1Dmk29lJm4COrBzvucdU7F4aHw6JM8cyQ+Ip4g2otXBuCmgw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706634686; a=rsa-sha256; cv=none; b=g4kMv6mzJy6aUGBBrjPhFywHCMgaw18tQHep6PzGNQqbkMzy8KDHdRUkALI0vQ40qg37pi jQpggXISOZwm9xnFDdlHyeaGn433zQ/NIWUH6iKcbnx7xmrN0whXIK2/RjjPH66sVG/HaL b4cM76S4ai4Ro+zLC2DDjxlLLqKTlo+BzZkO5X18a1t8BRHO14nrPvkrbexE3HYfIREloG kiimRS+XhofHsJUyA/10elKh5M2FIusu4Lmoke/6yihQdGloN2l3Un77hDtL0CxGkh2ptn M7+PjO72keJNRTrTrpjpJMhguYi6grg1IJshvyrSy/vddW27jhsaefUpUHUwgw== 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 4TPWsp20qxzkG3; Tue, 30 Jan 2024 17:11:26 +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 40UHBQO6093609; Tue, 30 Jan 2024 17:11:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40UHBQHr093606; Tue, 30 Jan 2024 17:11:26 GMT (envelope-from git) Date: Tue, 30 Jan 2024 17:11:26 GMT Message-Id: <202401301711.40UHBQHr093606@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: 984128ce2d5e - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 984128ce2d5eb7d3374dd4b245d443ec2f5d96b2 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=984128ce2d5eb7d3374dd4b245d443ec2f5d96b2 commit 984128ce2d5eb7d3374dd4b245d443ec2f5d96b2 Author: Kyle Evans AuthorDate: 2024-01-16 02:55:59 +0000 Commit: Kyle Evans CommitDate: 2024-01-30 17:11:10 +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 5e35c52b9038..1351560ba05a 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 16faeeb40421..74c987e55734 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -34,6 +34,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_passfd_test ATF_TESTS_C+= unix_seqpacket_test TEST_METADATA.unix_seqpacket_test+= timeout="15" @@ -77,6 +78,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()); +}