From owner-svn-src-head@freebsd.org Fri Sep 1 22:37:50 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 67D95E0BA67; Fri, 1 Sep 2017 22:37:50 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3577666E62; Fri, 1 Sep 2017 22:37:50 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v81MbnD6049855; Fri, 1 Sep 2017 22:37:49 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v81Mbnp3049853; Fri, 1 Sep 2017 22:37:49 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201709012237.v81Mbnp3049853@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Fri, 1 Sep 2017 22:37:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323123 - in head/usr.bin/tail: . tests X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: in head/usr.bin/tail: . tests X-SVN-Commit-Revision: 323123 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Sep 2017 22:37:50 -0000 Author: cem Date: Fri Sep 1 22:37:49 2017 New Revision: 323123 URL: https://svnweb.freebsd.org/changeset/base/323123 Log: tail(1): Do not print bogus errno string In the case where write(2) does not return -1, it does not initialize errno. This can happen when a broken pipe causes a short write. I attempted to adapt the submitted test case to ATF but could not figure out how to make the test run in the ATF environment. So the aborted test is left disabled, in case someone would like to run it manually or fix it. PR: 221976 Submitted by: (earlier version) Sponsored by: Dell EMC Isilon Modified: head/usr.bin/tail/extern.h head/usr.bin/tail/tests/tail_test.sh Modified: head/usr.bin/tail/extern.h ============================================================================== --- head/usr.bin/tail/extern.h Fri Sep 1 22:04:45 2017 (r323122) +++ head/usr.bin/tail/extern.h Fri Sep 1 22:37:49 2017 (r323123) @@ -32,9 +32,15 @@ */ #define WR(p, size) do { \ - if (write(STDOUT_FILENO, p, size) != (ssize_t)size) \ - oerr(); \ - } while(0) + ssize_t res; \ + res = write(STDOUT_FILENO, p, size); \ + if (res != (ssize_t)size) { \ + if (res == -1) \ + oerr(); \ + else \ + errx(1, "stdout"); \ + } \ +} while (0) #define TAILMAPLEN (4<<20) Modified: head/usr.bin/tail/tests/tail_test.sh ============================================================================== --- head/usr.bin/tail/tests/tail_test.sh Fri Sep 1 22:04:45 2017 (r323122) +++ head/usr.bin/tail/tests/tail_test.sh Fri Sep 1 22:37:49 2017 (r323123) @@ -215,7 +215,20 @@ longfile_rn2500_body() atf_check cmp expectfile outpipe } +atf_test_case broken_pipe +broken_pipe_head() +{ + atf_set "descr" "Do not print bogus errno based output on short writes" +} +broken_pipe_body() +{ + atf_expect_fail "Can't seem to get testcase to work in test environment. Reproduces easily in interactive shell." + seq -f '%128g' 1 1000 > ints + atf_check -s exit:1 -o ignore -e "inline:tail: stdout" tail -n 856 ints | awk '{ exit }' +} + + atf_init_test_cases() { atf_add_test_case empty_r @@ -230,4 +243,5 @@ atf_init_test_cases() atf_add_test_case longfile_rc135782 atf_add_test_case longfile_rc145782_longlines atf_add_test_case longfile_rn2500 + #atf_add_test_case broken_pipe }