Module Name:    src
Committed By:   christos
Date:           Mon Dec 27 16:09:46 UTC 2010

Modified Files:
        src/usr.bin/find: find.c

Log Message:
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.)


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/find/find.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/find/find.c
diff -u src/usr.bin/find/find.c:1.25 src/usr.bin/find/find.c:1.26
--- src/usr.bin/find/find.c:1.25	Tue Sep 25 00:10:12 2007
+++ src/usr.bin/find/find.c	Mon Dec 27 11:09:46 2010
@@ -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
-sig_lock(sigset_t *s)
+static sigset_t ss;
+static bool notty;
+
+static __inline void
+sig_init(void)
 {
-	sigset_t new;
+	notty = !(isatty(STDIN_FILENO) || isatty(STDOUT_FILENO) ||
+	    isatty(STDERR_FILENO));
+	if (notty)
+		return;
+	sigemptyset(&ss);
+	sigaddset(&ss, SIGINFO); /* block SIGINFO */
+}
 
-	sigemptyset(&new);
-	sigaddset(&new, SIGINFO); /* block SIGINFO */
-	sigprocmask(SIG_BLOCK, &new, s);
+static __inline void
+sig_lock(sigset_t *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);

Reply via email to