git: 20ac2dc15f03 - stable/13 - find: add SIGINFO handler
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 13 Jun 2024 18:30:24 UTC
The branch stable/13 has been updated by asomers:
URL: https://cgit.FreeBSD.org/src/commit/?id=20ac2dc15f03c885a7d9b8f5bc1facd3074c40a8
commit 20ac2dc15f03c885a7d9b8f5bc1facd3074c40a8
Author: Goran Mekić <meka@tilda.center>
AuthorDate: 2024-01-11 22:35:25 +0000
Commit: Alan Somers <asomers@FreeBSD.org>
CommitDate: 2024-06-13 18:29:45 +0000
find: add SIGINFO handler
Print number of files processed and path currently being processed on
SIGINFO.
Reviewed by: des, asomers
Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D43380
(cherry picked from commit d06a00963b7f724b6fdd7d7cdcbed57c534196a9)
---
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 3436f8cf07bf..323b9bfdfb93 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -126,3 +126,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 3bff4982b4b6..57225e8fa23f 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -172,6 +172,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));
@@ -213,6 +214,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 9ed1d1d4e29b..295e0f966362 100644
--- a/usr.bin/find/main.c
+++ b/usr.bin/find/main.c
@@ -68,8 +68,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);
+static void siginfo_handler(int sig __unused);
int
main(int argc, char *argv[])
@@ -81,6 +83,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;
@@ -161,3 +165,9 @@ usage(void)
" find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]");
exit(1);
}
+
+static void
+siginfo_handler(int sig __unused)
+{
+ showinfo = 1;
+}