From 54117b169fba3ed04e30b467d0d209ef398a9c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 31 Jan 2023 01:28:47 +0100 Subject: cmp: Print a summary on SIGINFO. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38280 (cherry picked from commit 6673a5476d029cd5b47b2eed27032211a14f52bd) cmp: Increase buffer size for non-mmap case. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: rpokala Differential Revision: https://reviews.freebsd.org/D38281 (cherry picked from commit 134841a7f3e5516a83732d40a4d42268c901a492) --- usr.bin/cmp/cmp.c | 14 ++++++++++++++ usr.bin/cmp/extern.h | 4 ++++ usr.bin/cmp/regular.c | 7 +++++++ usr.bin/cmp/special.c | 9 +++++++++ 4 files changed, 34 insertions(+) diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c index 83ea7ae7eee0..82f34803fc22 100644 --- a/usr.bin/cmp/cmp.c +++ b/usr.bin/cmp/cmp.c @@ -75,6 +75,17 @@ static const struct option long_opts[] = {NULL, no_argument, NULL, 0} }; +#ifdef SIGINFO +volatile sig_atomic_t info; + +static void +siginfo(int signo) +{ + + info = signo; +} +#endif + static void usage(void); static bool @@ -240,6 +251,9 @@ main(int argc, char *argv[]) } } +#ifdef SIGINFO + (void)signal(SIGINFO, siginfo); +#endif if (special) c_special(fd1, file1, skip1, fd2, file2, skip2, limit); else { diff --git a/usr.bin/cmp/extern.h b/usr.bin/cmp/extern.h index d98daf424995..60fd15ba0939 100644 --- a/usr.bin/cmp/extern.h +++ b/usr.bin/cmp/extern.h @@ -46,3 +46,7 @@ void diffmsg(const char *, const char *, off_t, off_t, int, int); void eofmsg(const char *); extern bool bflag, lflag, sflag, xflag, zflag; + +#ifdef SIGINFO +extern volatile sig_atomic_t info; +#endif diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c index d270aeeac396..182a303f70ed 100644 --- a/usr.bin/cmp/regular.c +++ b/usr.bin/cmp/regular.c @@ -120,6 +120,13 @@ c_regular(int fd1, const char *file1, off_t skip1, off_t len1, p2 = m2 + (skip2 - off2); for (byte = line = 1; length--; ++byte) { +#ifdef SIGINFO + if (info) { + (void)fprintf(stderr, "%s %s char %zu line %zu\n", + file1, file2, (size_t)byte, (size_t)line); + info = 0; + } +#endif if ((ch = *p1) != *p2) { if (xflag) { dfound = 1; diff --git a/usr.bin/cmp/special.c b/usr.bin/cmp/special.c index c206a317c0ef..1342f2a86270 100644 --- a/usr.bin/cmp/special.c +++ b/usr.bin/cmp/special.c @@ -65,8 +65,10 @@ c_special(int fd1, const char *file1, off_t skip1, if ((fp1 = fdopen(fd1, "r")) == NULL) err(ERR_EXIT, "%s", file1); + (void)setvbuf(fp1, NULL, _IOFBF, 65536); if ((fp2 = fdopen(fd2, "r")) == NULL) err(ERR_EXIT, "%s", file2); + (void)setvbuf(fp2, NULL, _IOFBF, 65536); dfound = 0; while (skip1--) @@ -77,6 +79,13 @@ c_special(int fd1, const char *file1, off_t skip1, goto eof; for (byte = line = 1; limit == 0 || byte <= limit; ++byte) { +#ifdef SIGINFO + if (info) { + (void)fprintf(stderr, "%s %s char %zu line %zu\n", + file1, file2, (size_t)byte, (size_t)line); + info = 0; + } +#endif ch1 = getc(fp1); ch2 = getc(fp2); if (ch1 == EOF || ch2 == EOF) -- cgit v1.2.3