summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2012-12-29 01:32:44 +0000
committermillert <millert@openbsd.org>2012-12-29 01:32:44 +0000
commit20351096944346ffc3fb8d9fe1b200f956470cd2 (patch)
tree692cee0bc3c143a18f0dc97bcf873b73656aa95a
parentAllow the relayd regression tests to run the relayd on a different (diff)
downloadwireguard-openbsd-20351096944346ffc3fb8d9fe1b200f956470cd2.tar.xz
wireguard-openbsd-20351096944346ffc3fb8d9fe1b200f956470cd2.zip
Fix exit status when there is an error reading a file.
Reported by Jeramey Crawford, fix adapted from FreeBSD. OK guenther@
-rw-r--r--usr.bin/grep/grep.c5
-rw-r--r--usr.bin/grep/grep.h4
-rw-r--r--usr.bin/grep/util.c7
3 files changed, 10 insertions, 6 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index eb467d7e352..c3ce3bb4a0d 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.44 2011/07/08 01:20:24 tedu Exp $ */
+/* $OpenBSD: grep.c,v 1.45 2012/12/29 01:32:44 millert Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -94,6 +94,7 @@ enum {
/* 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 @@ main(int argc, char *argv[])
for (c = 0; argc--; ++argv)
c += procfile(*argv);
- exit(!c);
+ exit(c ? (file_err ? (qflag ? 0 : 2) : 0) : (file_err ? 2 : 1));
}
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index 3cb3a6b9f60..435dd3b6046 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.h,v 1.17 2011/07/08 01:20:24 tedu Exp $ */
+/* $OpenBSD: grep.h,v 1.18 2012/12/29 01:32:44 millert Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -69,7 +69,7 @@ extern int Aflag, Bflag, Eflag, Fflag, Gflag, Hflag, Lflag,
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;
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 75bbf124c76..5efd10327b8 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.44 2012/12/12 11:12:24 millert Exp $ */
+/* $OpenBSD: util.c,v 1.45 2012/12/29 01:32:44 millert Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -72,7 +72,9 @@ grep_tree(char **argv)
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 @@ procfile(char *fn)
f = grep_open(fn, "r");
}
if (f == NULL) {
+ file_err = 1;
if (!sflag)
warn("%s", fn);
return 0;