Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Apr 2015 21:44:36 +0000 (UTC)
From:      Bryan Drewery <bdrewery@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r281617 - head/usr.bin/wc
Message-ID:  <201504162144.t3GLiati002248@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504162144.t3GLiati002248>