Here's an adaptation of a similar change in FreeBSD.

 - todd

Index: usr.bin/grep/grep.c
===================================================================
RCS file: /home/cvs/openbsd/src/usr.bin/grep/grep.c,v
retrieving revision 1.44
diff -u -r1.44 grep.c
--- usr.bin/grep/grep.c 8 Jul 2011 01:20:24 -0000       1.44
+++ usr.bin/grep/grep.c 27 Dec 2012 20:31:47 -0000
@@ -94,6 +94,7 @@
 /* Housekeeping */
 int     first;         /* flag whether or not this is our first match */
 int     tail;          /* lines left to print */
+int     file_err;      /* file reading error */
 
 struct patfile {
        const char              *pf_file;
@@ -497,5 +498,5 @@
                for (c = 0; argc--; ++argv)
                        c += procfile(*argv);
 
-       exit(!c);
+       exit(c ? (file_err ? (qflag ? 0 : 2) : 0) : (file_err ? 2 : 1));
 }
Index: usr.bin/grep/grep.h
===================================================================
RCS file: /home/cvs/openbsd/src/usr.bin/grep/grep.h,v
retrieving revision 1.17
diff -u -r1.17 grep.h
--- usr.bin/grep/grep.h 8 Jul 2011 01:20:24 -0000       1.17
+++ usr.bin/grep/grep.h 27 Dec 2012 20:29:52 -0000
@@ -69,7 +69,7 @@
                 vflag, wflag, xflag;
 extern int      binbehave;
 
-extern int      first, matchall, patterns, tail;
+extern int      first, matchall, patterns, tail, file_err;
 extern char    **pattern;
 extern fastgrep_t *fg_pattern;
 extern regex_t *r_pattern;
Index: usr.bin/grep/util.c
===================================================================
RCS file: /home/cvs/openbsd/src/usr.bin/grep/util.c,v
retrieving revision 1.44
diff -u -r1.44 util.c
--- usr.bin/grep/util.c 12 Dec 2012 11:12:24 -0000      1.44
+++ usr.bin/grep/util.c 27 Dec 2012 20:31:57 -0000
@@ -72,7 +72,9 @@
                case FTS_DNR:
                        break;
                case FTS_ERR:
-                       errx(2, "%s: %s", p->fts_path, strerror(p->fts_errno));
+                       file_err = 1;
+                       if(!sflag)
+                               warnx("%s: %s", p->fts_path, 
strerror(p->fts_errno));
                        break;
                case FTS_DP:
                        break;
@@ -101,6 +103,7 @@
                f = grep_open(fn, "r");
        }
        if (f == NULL) {
+               file_err = 1;
                if (!sflag)
                        warn("%s", fn);
                return 0;

Reply via email to