aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/wc
diff options
context:
space:
mode:
authorBryan Drewery <bdrewery@FreeBSD.org>2015-04-16 21:44:35 +0000
committerBryan Drewery <bdrewery@FreeBSD.org>2015-04-16 21:44:35 +0000
commit8ded906d2af44dc77b2355400c7b60743f3b8c84 (patch)
tree64768f86d10d3a6f01d98f591489a1569519dd1e /usr.bin/wc
parent43d4f8c4c6ba7e5c47bf8239f80a154004c5b458 (diff)
downloadsrc-8ded906d2af44dc77b2355400c7b60743f3b8c84.tar.gz
src-8ded906d2af44dc77b2355400c7b60743f3b8c84.zip
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
Notes
Notes: svn path=/head/; revision=281617
Diffstat (limited to 'usr.bin/wc')
-rw-r--r--usr.bin/wc/wc.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/usr.bin/wc/wc.c b/usr.bin/wc/wc.c
index 9d51ab2fd1c8..a6ca137d9856 100644
--- a/usr.bin/wc/wc.c
+++ b/usr.bin/wc/wc.c
@@ -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");