From nobody Fri Jan 12 15:44:31 2024 X-Original-To: dev-commits-src-main@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 4TBQnq2z9Nz573Gs; Fri, 12 Jan 2024 15:44:31 +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 4TBQnq1pQmz4MM8; Fri, 12 Jan 2024 15:44:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705074271; 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=az9VyCNaBOVoRjfU7rX7y3UT9QIHsKXaVjXc5LoUG00=; b=IEQVfi1EOK6+60K/AUEYL9B9ANzDY40mF/PQ1N93PkfkbLCthU0S5YABiaI7XbW1kEqXMq 2dK9D17dckDMpZb/uYJJm+Mt/d9EK9z2qydpE7hIVvL+3g2KEcvCdgHFCzk858U1gZFb80 f/WvJNMn8VbDYdZHFVF31wtJc/qkDce7FOIXpzFbhvDkm3jSe1TbJo98BhPty7Sy1riScs nIENpbR2/mD2HfkaUZmwBvFGL/ycLbFAl8sewY591fTQuXfbGqkx7SsT6SNpsDGWIfWAuu oKdx8R9QQEMiZHkhZBs0QMF2vDezDKXLDbl8z3uEk9wzMKCt3Eb45PFNfQxFxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705074271; 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=az9VyCNaBOVoRjfU7rX7y3UT9QIHsKXaVjXc5LoUG00=; b=WHzvNiuTjay7iuR0NBYVp6NfRitcCjvJrksm1vl2yZOJnokgczMSvnREy1jRzmpYhCtaIk O/LKUE1J6ksUdGmS2l1LEiXjBBG9JSNnKr+QE+wlq2LfccSf1TD9smuuzvZWNruaKQWhHu hLmVqG7D1MnsyJBx4keZJogi3U1aEYAKHEOOBD7kX4QHTSABTByMvvNgi+XV3G3XQBPFjf AKzwLH/hLBBllbULwLkcGsSiaAREgwWF6EXqvR8KAg0YeOFvA3uUs1vDABYxPKXjbD5dhX YiSozjzMztb9J8GR2AEQwE5OQUPG/3Y2kHY2ZEe1uhe1q2mYFNU7olfukW5RuA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705074271; a=rsa-sha256; cv=none; b=dMQuLDVEAE1irHtCKllPa1yEPjT+WSlTvUlv0a+2XtlQVo3vIU5QEGf/a9LDE2ATVV90kd CPeSQ4YnkPvNxmkj5taWTmm5h4gzHbbuYTNCtKakngOsDS+Z19z2CiLKJHQFsFc56AWN8i sbrzXx3ZioEXGWB0x+Jam6TOhOvUmHYrQ+Fd+9nT0BgqyRxqcHoND5ys3jQIw4RPvjhWr7 hlzlW2/MPmKi+W7f2hJLjT83uNQrfGQtXHLNNCH0uL19VaAN7ZyggZ5BdVBfq0KNW9IHRj TsMYYiEIdZbmqeLpQWF8NG6R6+TvKBL8d7MjtpYfype+MlpCoQTPJ4Bcs8IHIw== 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 4TBQnq0vqqz170p; Fri, 12 Jan 2024 15:44:31 +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 40CFiVCL076747; Fri, 12 Jan 2024 15:44:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40CFiVAQ076744; Fri, 12 Jan 2024 15:44:31 GMT (envelope-from git) Date: Fri, 12 Jan 2024 15:44:31 GMT Message-Id: <202401121544.40CFiVAQ076744@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 899837e8f574 - main - uniq: Error out if writing to the output failed. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 899837e8f5741f9a847b63d9e7c8b76ccc033ab5 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=899837e8f5741f9a847b63d9e7c8b76ccc033ab5 commit 899837e8f5741f9a847b63d9e7c8b76ccc033ab5 Author: Dag-Erling Smørgrav AuthorDate: 2024-01-12 15:40:48 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-01-12 15:44:06 +0000 uniq: Error out if writing to the output failed. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D43407 --- usr.bin/uniq/tests/uniq_test.sh | 15 +++++++++++++++ usr.bin/uniq/uniq.c | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh index 537962eb6513..804e82ce7766 100755 --- a/usr.bin/uniq/tests/uniq_test.sh +++ b/usr.bin/uniq/tests/uniq_test.sh @@ -160,6 +160,20 @@ interactive_repeated_body() { atf_check -o inline:"y\n" cat actual } +atf_test_case stdout +stdout_head() { + atf_set descr "error writing to stdout" +} +stdout_body() { + ( + trap "" PIPE + echo a | uniq 2>stderr + echo $? >result + ) | true + atf_check -o inline:"1\n" cat result + atf_check -o match:"stdout" cat stderr +} + atf_init_test_cases() { atf_add_test_case basic @@ -175,4 +189,5 @@ atf_init_test_cases() atf_add_test_case count_unique atf_add_test_case interactive atf_add_test_case interactive_repeated + atf_add_test_case stdout } diff --git a/usr.bin/uniq/uniq.c b/usr.bin/uniq/uniq.c index ef59d7339d0c..9978c4996dc7 100644 --- a/usr.bin/uniq/uniq.c +++ b/usr.bin/uniq/uniq.c @@ -84,7 +84,7 @@ main (int argc, char *argv[]) int ch, comp; size_t prevbuflen, thisbuflen, b1; char *prevline, *thisline, *p; - const char *errstr, *ifn; + const char *errstr, *ifn, *ofn; cap_rights_t rights; (void) setlocale(LC_ALL, ""); @@ -142,6 +142,7 @@ main (int argc, char *argv[]) ifp = stdin; ifn = "stdin"; ofp = stdout; + ofn = "stdout"; if (argc > 0 && strcmp(argv[0], "-") != 0) ifp = file(ifn = argv[0], "r"); cap_rights_init(&rights, CAP_FSTAT, CAP_READ); @@ -149,7 +150,7 @@ main (int argc, char *argv[]) err(1, "unable to limit rights for %s", ifn); cap_rights_init(&rights, CAP_FSTAT, CAP_WRITE); if (argc > 1) - ofp = file(argv[1], "w"); + ofp = file(ofn = argv[1], "w"); else cap_rights_set(&rights, CAP_IOCTL); if (caph_rights_limit(fileno(ofp), &rights) < 0) { @@ -240,6 +241,8 @@ main (int argc, char *argv[]) (!dflag || (cflag && repeats > 0)) && (!uflag || repeats == 0)) show(ofp, prevline); + if (fflush(ofp) != 0) + err(1, "%s", ofn); exit(0); }