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
This commit is contained in:
Goran Mekić
2024-01-11 15:35:25 -07:00
committed by Alan Somers
parent 0e1d8481f9
commit d06a00963b
3 changed files with 20 additions and 0 deletions
+1
View File
@@ -121,3 +121,4 @@ extern int exitstatus;
extern time_t now; extern time_t now;
extern int dotfd; extern int dotfd;
extern FTS *tree; extern FTS *tree;
extern volatile sig_atomic_t showinfo;
+9
View File
@@ -167,6 +167,7 @@ find_execute(PLAN *plan, char *paths[])
{ {
FTSENT *entry; FTSENT *entry;
PLAN *p; PLAN *p;
size_t counter = 0;
int e; int e;
tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL)); tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL));
@@ -208,6 +209,14 @@ find_execute(PLAN *plan, char *paths[])
continue; continue;
#endif /* FTS_W */ #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\\'\"" #define BADCH " \t\n\\'\""
if (isxargs && strpbrk(entry->fts_path, BADCH)) { if (isxargs && strpbrk(entry->fts_path, BADCH)) {
(void)fflush(stdout); (void)fflush(stdout);
+10
View File
@@ -59,8 +59,10 @@ int isxargs; /* don't permit xargs delimiting chars */
int mindepth = -1, maxdepth = -1; /* minimum and maximum depth */ int mindepth = -1, maxdepth = -1; /* minimum and maximum depth */
int regexp_flags = REG_BASIC; /* use the "basic" regexp by default*/ int regexp_flags = REG_BASIC; /* use the "basic" regexp by default*/
int exitstatus; int exitstatus;
volatile sig_atomic_t showinfo = 0;
static void usage(void) __dead2; static void usage(void) __dead2;
static void siginfo_handler(int sig __unused);
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
@@ -72,6 +74,8 @@ main(int argc, char *argv[])
(void)time(&now); /* initialize the time-of-day */ (void)time(&now); /* initialize the time-of-day */
(void)signal(SIGINFO, siginfo_handler);
p = start = argv; p = start = argv;
Hflag = Lflag = 0; Hflag = Lflag = 0;
ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
@@ -152,3 +156,9 @@ usage(void)
" find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]"); " find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]");
exit(1); exit(1);
} }
static void
siginfo_handler(int sig __unused)
{
showinfo = 1;
}