From owner-svn-src-head@FreeBSD.ORG Thu Apr 16 21:44:36 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 51F12C3B; Thu, 16 Apr 2015 21:44:36 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 3D5E91B21; Thu, 16 Apr 2015 21:44:36 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t3GLia6V002249; Thu, 16 Apr 2015 21:44:36 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t3GLiati002248; Thu, 16 Apr 2015 21:44:36 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201504162144.t3GLiati002248@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Thu, 16 Apr 2015 21:44:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281617 - head/usr.bin/wc X-SVN-Group: head 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.20 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: Thu, 16 Apr 2015 21:44:36 -0000 Author: bdrewery Date: Thu Apr 16 21:44:35 2015 New Revision: 281617 URL: https://svnweb.freebsd.org/changeset/base/281617 Log: Fix SIGINFO race causing final results to be lost to stderr. If a SIGINFO comes in after the file is read then the 'siginfo' flag is set to 1 and the next call to show_cnt() (at exit) would print the data to stderr rather than the expected stdout. This was found with spamming Poudriere with SIGINFO which caused a 'wc -l' execution to return no data rather than an expected number. MFC after: 2 weeks Modified: head/usr.bin/wc/wc.c Modified: head/usr.bin/wc/wc.c ============================================================================== --- head/usr.bin/wc/wc.c Thu Apr 16 20:53:15 2015 (r281616) +++ head/usr.bin/wc/wc.c Thu Apr 16 21:44:35 2015 (r281617) @@ -76,6 +76,14 @@ siginfo_handler(int sig __unused) siginfo = 1; } +static void +reset_siginfo(void) +{ + + signal(SIGINFO, SIG_DFL); + siginfo = 0; +} + int main(int argc, char *argv[]) { @@ -229,6 +237,7 @@ cnt(const char *file) } else tmpll++; } + reset_siginfo(); tlinect += linect; if (dochar) tcharct += charct; @@ -251,6 +260,7 @@ cnt(const char *file) return (1); } if (S_ISREG(sb.st_mode)) { + reset_siginfo(); charct = sb.st_size; show_cnt(file, linect, wordct, charct, llct); tcharct += charct; @@ -311,6 +321,7 @@ word: gotsp = 1; } } } + reset_siginfo(); if (domulti && MB_CUR_MAX > 1) if (mbrtowc(NULL, NULL, 0, &mbs) == (size_t)-1 && !warned) xo_warn("%s", file != NULL ? file : "stdin");