From nobody Sat Nov 15 00:27:47 2025 X-Original-To: dev-commits-src-branches@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 4d7ZbR3RZ4z6Ggvb; Sat, 15 Nov 2025 00:27:47 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d7ZbR2qVmz3mrb; Sat, 15 Nov 2025 00:27:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763166467; 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=dU35kqq40h2p8aPKFAf6rfOd8hM0iiKfGOFyF4fqN60=; b=uvddlkJDih+6/i0chdW7r6qMFjBPqWW9jU+211V2HCfw8XllAVBtjqU3hM8Il25KE845PL 4ad5Bpq4W9+zt5EFoIq5tHauGZsHqZTuIm9XnzVS5dZmlJ1pMPao9adZKJ7GmouPZWeUIZ narViIHYC+qK+n2v9ahpJmyaCwiTZ8k20t9hIs1UkWoUwLnR64eeTxHN7ufCy6gqljeO7s IiYYcXS9hkUFCQOPZfrExHq+CwpURP2Ohc29hBM/R2Lngj8DfDJonuaXlRtlMtel0HnD/3 QE45r5JP+6/YjpEvoXnCzqlCHZOa/Lza3O+1jzYhUkrGw0k0ZZGOln8On/XNZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763166467; 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=dU35kqq40h2p8aPKFAf6rfOd8hM0iiKfGOFyF4fqN60=; b=GNh7IuPOv67qm95NpfeOEDfHSRjf/cUqCdZrYM0CfoSzJXLVn4iE50phSRyAw4pTk2yJ23 hD8/RpYu6f3mrbfQu+IP2ZACyWrwKlvp9MOIa2Gq2D6k8H+a+P5pyKx9gOsRvBGyM5MbLJ i9a5mZrvNzpnNlgG52V6qYejXxuzrKFSYQs8rpW75ceyTFFYDecqCExc7FDN8pddfUowEF ZtNdFgR92CVSLgP/ijufFFXzRgLu7H8vSgnGGHFC+GoNOVRQCi0ad7hBFMOlaD8LKJtpWU Ii/Wgwg9F8Tj+Ss9i6PMBBlZw/06H4BvO6LqJDi9JcemYyM9mFS62PTR+lmPVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763166467; a=rsa-sha256; cv=none; b=B56ibH/Q6HGLHcB8PLgBsPWLxxluy/KCiANI+gg333nY2WEk0tGdEIBLDkL9phWyHfXpO8 haDV7QcIbagsF6DFW2lTUCy4UIq2Pon5tEZ2ndclCIl8QMpN97Ak/mvmNh15rGBL6jHMZh aMVb1xu3kW+TTbbgKPoo+xW/yNcmw5Iy3U28uNLhhObKUcLbHzFgd9j48V3VlKJ0Lp73PY zHhqGAhE3UGJ/7YRo1Pi0acy6dCD3JGcxGcEqpnl+/jxizHO16c+Kz5+35IFqpZhWRgWEk ZvR5hpiTolrrjCu1Z5nja+WY3sY9bvii3g7I8N+MZpd3qZeb7NDJFyhl8zfJ8w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4d7ZbR259vzDLd; Sat, 15 Nov 2025 00:27:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5AF0Rlqx066224; Sat, 15 Nov 2025 00:27:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5AF0RlAT066221; Sat, 15 Nov 2025 00:27:47 GMT (envelope-from git) Date: Sat, 15 Nov 2025 00:27:47 GMT Message-Id: <202511150027.5AF0RlAT066221@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: 1d678ba57569 - stable/15 - lam: fix using stdin more than once List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/15 X-Git-Reftype: branch X-Git-Commit: 1d678ba5756978240140beb5c1ebd38bb778ed66 Auto-Submitted: auto-generated The branch stable/15 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=1d678ba5756978240140beb5c1ebd38bb778ed66 commit 1d678ba5756978240140beb5c1ebd38bb778ed66 Author: Kyle Evans AuthorDate: 2025-11-14 14:36:20 +0000 Commit: Kyle Evans CommitDate: 2025-11-15 00:27:09 +0000 lam: fix using stdin more than once Historically, lam(1) closes stdin once we've hit EOF the first time, which would stop it from doing anything else on subsequent gatherline() calls with another openfile. However, this doesn't seem to be strictly necessary- the EOF flag on FILEs is quite sticky, so we can assume that a subsequent fgetc(stdin) will flag EOF properly. This 'fixes' the below-referenced commit in the sense that it surfaced this problem as a fatal error, but the issue was pre-existing. If we do `lam - -`, then one gatherline() will fclose(stdin) and set `ip->eof` for *that* openfile, while the next one will then observe that STDIN_FILENO has been closed and turn it into an EBADF. Add a few tests that were easy to snipe while I'm here, but I haven't aimed for anything close to exhaustive because I think re@ would prefer this fix go in sooner rather than later to land in 15.0. Minor style adjustment for the previous commit while we're here. Reported by: cperciva Discussed with: jrtc27 Reviewed by: des, jlduran Fixes: 4472fd66d006 ("lam: fail on I/O errors") Sponsored by: Klara, Inc. (cherry picked from commit 6a9452c8378a1aa767708ad2d235f847c880a21c) --- etc/mtree/BSD.tests.dist | 2 ++ usr.bin/lam/Makefile | 5 ++++ usr.bin/lam/lam.c | 5 +--- usr.bin/lam/tests/Makefile | 5 ++++ usr.bin/lam/tests/lam_test.sh | 59 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 520b41c8b88f..41151d35e518 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1163,6 +1163,8 @@ .. jot .. + lam + .. lastcomm .. limits diff --git a/usr.bin/lam/Makefile b/usr.bin/lam/Makefile index e47ea0a98eaa..faad910f2202 100644 --- a/usr.bin/lam/Makefile +++ b/usr.bin/lam/Makefile @@ -1,3 +1,8 @@ +.include + PROG= lam +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/usr.bin/lam/lam.c b/usr.bin/lam/lam.c index 2194ae7ab596..c1221ca92d0e 100644 --- a/usr.bin/lam/lam.c +++ b/usr.bin/lam/lam.c @@ -213,11 +213,8 @@ gatherline(struct openfile *ip) *p = '\0'; if (c == EOF) { ip->eof = 1; - if (ferror(ip->fp)) { + if (ferror(ip->fp)) err(EX_IOERR, NULL); - } - if (ip->fp == stdin) - fclose(stdin); morefiles--; return (pad(ip)); } diff --git a/usr.bin/lam/tests/Makefile b/usr.bin/lam/tests/Makefile new file mode 100644 index 000000000000..8d41af5e6e09 --- /dev/null +++ b/usr.bin/lam/tests/Makefile @@ -0,0 +1,5 @@ +PACKAGE= tests + +ATF_TESTS_SH= lam_test + +.include diff --git a/usr.bin/lam/tests/lam_test.sh b/usr.bin/lam/tests/lam_test.sh new file mode 100755 index 000000000000..bf3998a42d11 --- /dev/null +++ b/usr.bin/lam/tests/lam_test.sh @@ -0,0 +1,59 @@ +# +# Copyright (c) 2025 Klara, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause +# + +atf_test_case basic +basic_head() +{ + atf_set "descr" "Test basic lam(1) functionality" +} +basic_body() +{ + printf '1\n2\n3\n' > a + printf '4\n5\n6\n' > b + + atf_check -o inline:"14\n25\n36\n" lam a b +} + +atf_test_case sep +sep_head() +{ + atf_set "descr" "Test lam(1) -s and -S options" +} +sep_body() +{ + printf "1\n" > a + printf "0\n" > b + + atf_check -o inline:"x1x0\n" lam -S x a b + atf_check -o inline:"1x0\n" lam a -S x b + atf_check -o inline:"x10\n" lam -S x a -s '' b + + atf_check -o inline:"x10\n" lam -s x a b + atf_check -o inline:"x1y0\n" lam -s x a -s y b + atf_check -o inline:"1x0\n" lam a -s x b +} + +atf_test_case stdin +stdin_head() +{ + atf_set "descr" "Test lam(1) using stdin" +} +stdin_body() +{ + printf '1\n2\n3\n4\n' > a + + atf_check -o inline:"11\n22\n33\n44\n" lam a - < a + atf_check -o inline:"11\n22\n33\n44\n" lam - a < a + + atf_check -o inline:"12\n34\n" lam - - < a +} + +atf_init_test_cases() +{ + atf_add_test_case basic + atf_add_test_case sep + atf_add_test_case stdin +}