tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Why no SIGINFO?



Today I realized for a very large recursive rm that it would be nice
to show where we are in the tree so far as well. So, I whipped up some
similar code to that in cp. if anyone would like it, here is the patch
for rm that adds siginfo support to print the current location in the
tree.

Index: rm.c
===================================================================
RCS file: /cvsroot/src/bin/rm/rm.c,v
retrieving revision 1.50
diff -u -r1.50 rm.c
--- rm.c        29 Aug 2011 14:48:46 -0000      1.50
+++ rm.c        20 Jan 2012 20:27:02 -0000
@@ -54,15 +54,18 @@
 #include <grp.h>
 #include <locale.h>
 #include <pwd.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>

 static int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag;
+static sig_atomic_t pinfo;

 static int     check(char *, char *, struct stat *);
 static void    checkdot(char **);
+static void progress(int);
 static void    rm_file(char **);
 static int     rm_overwrite(char *, struct stat *);
 static void    rm_tree(char **);
@@ -131,6 +134,9 @@
                usage();
        }

+       pinfo = 0;
+       (void)signal(SIGINFO, progress);
+
        checkdot(argv);

        if (*argv) {
@@ -252,8 +258,10 @@
                if (rval != 0) {
                        warn("%s", p->fts_path);
                        eval = 1;
-               } else if (vflag)
+               } else if (vflag || pinfo) {
+                       pinfo = 0;
                        (void)printf("%s\n", p->fts_path);
+               }
        }
        if (errno)
                err(1, "fts_read");
@@ -579,3 +587,10 @@
        exit(1);
        /* NOTREACHED */
 }
+
+static void
+progress(int sig __unused)
+{
+       
+       pinfo++;
+}


Home | Main Index | Thread Index | Old Index