git: d06a00963b7f - main - find: add SIGINFO handler

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Thu, 11 Jan 2024 23:37:48 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=d06a00963b7f724b6fdd7d7cdcbed57c534196a9

commit d06a00963b7f724b6fdd7d7cdcbed57c534196a9
Author:     Goran Mekić <meka@tilda.center>
AuthorDate: 2024-01-11 22:35:25 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2024-01-11 23:37:14 +0000

    find: add SIGINFO handler
    
    Print number of files processed and path currently being processed on
    SIGINFO.
    
    Reviewed by:    des, asomers
    Sponsored by:   Axcient
    MFC after:      2 weeks
    Differential Revision: https://reviews.freebsd.org/D43380
---
 usr.bin/find/extern.h |  1 +
 usr.bin/find/find.c   |  9 +++++++++
 usr.bin/find/main.c   | 10 ++++++++++
 3 files changed, 20 insertions(+)

diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index c84ca8953e50..a1bd5e6d16a5 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -121,3 +121,4 @@ extern int exitstatus;
 extern time_t now;
 extern int dotfd;
 extern FTS *tree;
+extern volatile sig_atomic_t showinfo;
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index 54b4fdd679e4..aec04536071a 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -167,6 +167,7 @@ find_execute(PLAN *plan, char *paths[])
 {
 	FTSENT *entry;
 	PLAN *p;
+	size_t counter = 0;
 	int e;
 
 	tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL));
@@ -208,6 +209,14 @@ find_execute(PLAN *plan, char *paths[])
 			continue;
 #endif /* FTS_W */
 		}
+
+		if (showinfo) {
+			fprintf(stderr, "Scanning: %s/%s\n", entry->fts_path, entry->fts_name);
+			fprintf(stderr, "Scanned: %lu\n\n", counter);
+			showinfo = 0;
+		}
+		++counter;
+
 #define	BADCH	" \t\n\\'\""
 		if (isxargs && strpbrk(entry->fts_path, BADCH)) {
 			(void)fflush(stdout);
diff --git a/usr.bin/find/main.c b/usr.bin/find/main.c
index 746bd91d80b7..0738da4071c8 100644
--- a/usr.bin/find/main.c
+++ b/usr.bin/find/main.c
@@ -59,8 +59,10 @@ int isxargs;			/* don't permit xargs delimiting chars */
 int mindepth = -1, maxdepth = -1; /* minimum and maximum depth */
 int regexp_flags = REG_BASIC;	/* use the "basic" regexp by default*/
 int exitstatus;
+volatile sig_atomic_t showinfo = 0;
 
 static void usage(void) __dead2;
+static void siginfo_handler(int sig __unused);
 
 int
 main(int argc, char *argv[])
@@ -72,6 +74,8 @@ main(int argc, char *argv[])
 
 	(void)time(&now);	/* initialize the time-of-day */
 
+	(void)signal(SIGINFO, siginfo_handler);
+
 	p = start = argv;
 	Hflag = Lflag = 0;
 	ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
@@ -152,3 +156,9 @@ usage(void)
 "       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]");
 	exit(1);
 }
+
+static void
+siginfo_handler(int sig __unused)
+{
+	showinfo = 1;
+}