aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-06-14 11:23:01 -0500
committerRob Landley <rob@landley.net>2017-06-14 11:23:01 -0500
commitf19b20f57e5354bcae72f0348bd9e503af79f073 (patch)
treee172c4c1888b40a366a40cfaddce8ecf97d2660e
parente59d2e49efd187bc8f0e67f1e9fb018903ce6e0a (diff)
downloadtoybox-f19b20f57e5354bcae72f0348bd9e503af79f073.tar.gz
Grep exits with 2 for errors, which can happen at any time ( > /dev/full).
-rw-r--r--toys/posix/grep.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index c0506845..d1452cec 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -73,6 +73,7 @@ GLOBALS(
struct arg_list *S;
char indelim, outdelim;
+ int found;
)
// Emit line with various potential prefixes and delimiter
@@ -194,8 +195,11 @@ static void do_grep(int fd, char *name)
bars = 0;
}
mmatch++;
- toys.exitval = 0;
- if (toys.optflags & FLAG_q) xexit();
+ TT.found = 1;
+ if (toys.optflags & FLAG_q) {
+ toys.exitval = 0;
+ xexit();
+ }
if (toys.optflags & FLAG_l) {
xprintf("%s%c", name, TT.outdelim);
free(line);
@@ -361,6 +365,9 @@ void grep_main(void)
{
char **ss = toys.optargs;
+ // Grep exits with 2 for errors
+ toys.exitval = 2;
+
if (!TT.a) TT.a = TT.c;
if (!TT.b) TT.b = TT.c;
@@ -382,7 +389,6 @@ void grep_main(void)
if (!(toys.optflags & FLAG_h) && toys.optc>1) toys.optflags |= FLAG_H;
- toys.exitval = 1;
if (toys.optflags & FLAG_s) {
close(2);
xopen_stdio("/dev/null", O_RDWR);
@@ -395,4 +401,5 @@ void grep_main(void)
else dirtree_read(*ss, do_grep_r);
}
} else loopfiles_rw(ss, O_RDONLY|WARN_ONLY, 0, do_grep);
+ toys.exitval = !TT.found;
}