Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/find The SIGINFO changes made the sigprocmask syscal...



details:   https://anonhg.NetBSD.org/src/rev/e4b92fb6bb93
branches:  trunk
changeset: 760118:e4b92fb6bb93
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Dec 27 16:09:46 2010 +0000

description:
The SIGINFO changes made the sigprocmask syscalls dominate all the rest:
- Don't bother dealing with signal masks if we are not connected to a tty.
- Compute the blocking mask only once.
- Only do the block-unblock game only when we are going to do something
  (execute, print a warning, etc.)

diffstat:

 usr.bin/find/find.c |  48 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 33 insertions(+), 15 deletions(-)

diffs (125 lines):

diff -r daa69116517c -r e4b92fb6bb93 usr.bin/find/find.c
--- a/usr.bin/find/find.c       Mon Dec 27 15:56:50 2010 +0000
+++ b/usr.bin/find/find.c       Mon Dec 27 16:09:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: find.c,v 1.25 2007/09/25 04:10:12 lukem Exp $  */
+/*     $NetBSD: find.c,v 1.26 2010/12/27 16:09:46 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)find.c       8.5 (Berkeley) 8/5/94";
 #else
-__RCSID("$NetBSD: find.c,v 1.25 2007/09/25 04:10:12 lukem Exp $");
+__RCSID("$NetBSD: find.c,v 1.26 2010/12/27 16:09:46 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -51,14 +51,13 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
 
 #include "find.h"
 
 static int ftscompare(const FTSENT **, const FTSENT **);
 
-static void sig_lock(sigset_t *);
-static void sig_unlock(const sigset_t *);
-
 /*
  * find_formplan --
  *     process the command line and create a "plan" corresponding to the
@@ -154,20 +153,33 @@
        return (strcoll((*e1)->fts_name, (*e2)->fts_name));
 }
 
-static void
+static sigset_t ss;
+static bool notty;
+
+static __inline void
+sig_init(void)
+{
+       notty = !(isatty(STDIN_FILENO) || isatty(STDOUT_FILENO) ||
+           isatty(STDERR_FILENO));
+       if (notty)
+               return;
+       sigemptyset(&ss);
+       sigaddset(&ss, SIGINFO); /* block SIGINFO */
+}
+
+static __inline void
 sig_lock(sigset_t *s)
 {
-       sigset_t new;
-
-       sigemptyset(&new);
-       sigaddset(&new, SIGINFO); /* block SIGINFO */
-       sigprocmask(SIG_BLOCK, &new, s);
+       if (notty)
+               return;
+       sigprocmask(SIG_BLOCK, &ss, s);
 }
 
-static void
+static __inline void
 sig_unlock(const sigset_t *s)
 {
-
+       if (notty)
+               return;
        sigprocmask(SIG_SETMASK, s, NULL);
 }
 
@@ -191,9 +203,9 @@
        if (!(tree = fts_open(paths, ftsoptions, issort ? ftscompare : NULL)))
                err(1, "ftsopen");
 
+       sig_init();
        sig_lock(&s);
-       for (rval = 0; cval && (g_entry = fts_read(tree)) != NULL; sig_lock(&s)) {
-               sig_unlock(&s);
+       for (rval = 0; cval && (g_entry = fts_read(tree)) != NULL;) {
                switch (g_entry->fts_info) {
                case FTS_D:
                        if (isdepth)
@@ -206,17 +218,21 @@
                case FTS_DNR:
                case FTS_ERR:
                case FTS_NS:
+                       sig_unlock(&s);
                        (void)fflush(stdout);
                        warnx("%s: %s",
                            g_entry->fts_path, strerror(g_entry->fts_errno));
                        rval = 1;
+                       sig_lock(&s);
                        continue;
                }
 #define        BADCH   " \t\n\\'\""
                if (isxargs && strpbrk(g_entry->fts_path, BADCH)) {
+                       sig_unlock(&s);
                        (void)fflush(stdout);
                        warnx("%s: illegal path", g_entry->fts_path);
                        rval = 1;
+                       sig_lock(&s);
                        continue;
                }
 
@@ -225,11 +241,13 @@
                 * false or all have been executed.  This is where we do all
                 * the work specified by the user on the command line.
                 */
+               sig_unlock(&s);
                for (p = plan; p && (p->eval)(p, g_entry); p = p->next)
                        if (p->type == N_EXIT) {
                                rval = p->exit_val;
                                cval = 0;
                        }
+               sig_lock(&s);
        }
 
        sig_unlock(&s);



Home | Main Index | Thread Index | Old Index