git: 6673a5476d02 - main - cmp: Print a summary on SIGINFO.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 31 Jan 2023 00:29:29 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=6673a5476d029cd5b47b2eed27032211a14f52bd
commit 6673a5476d029cd5b47b2eed27032211a14f52bd
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-01-31 00:28:47 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-01-31 00:29:05 +0000
cmp: Print a summary on SIGINFO.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D38280
---
usr.bin/cmp/cmp.c | 14 ++++++++++++++
usr.bin/cmp/extern.h | 4 ++++
usr.bin/cmp/regular.c | 7 +++++++
usr.bin/cmp/special.c | 7 +++++++
4 files changed, 32 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..7514c01bd59a 100644
--- a/usr.bin/cmp/special.c
+++ b/usr.bin/cmp/special.c
@@ -77,6 +77,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)