Mercurial > hg > aboriginal
view sources/patches/toybox-grep.patch @ 1805:bbe71b3a271d draft
Upgrade toybox and musl versions.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 04 Nov 2015 00:14:29 -0600 |
parents | 0494012aca6d |
children |
line wrap: on
line source
Toybox grep on a directory hits a uClibc bug and segfaults. This bug does not happen in glibc, musl, or bionic, so it's not worth adding a workaround upstream. diff --git a/toys/posix/grep.c b/toys/posix/grep.c index d44a92d..b9c2def 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -63,7 +63,8 @@ GLOBALS( // Show matches in one file static void do_grep(int fd, char *name) { - FILE *file = fdopen(fd, "r"); + struct stat *st = (void *)(toybuf+sizeof(regex_t)); + FILE *file = 0; long offset = 0; int lcount = 0, mcount = 0; char indelim = '\n' * !(toys.optflags&FLAG_z), @@ -71,8 +72,13 @@ static void do_grep(int fd, char *name) if (!fd) name = "(standard input)"; + if (!fstat(fd, st)) { + // grep * hits directories, skip but don't treat them as errors. + if (S_ISDIR(st->st_mode)) errno = 0; + else file = fdopen(fd, "r"); + } if (!file) { - perror_msg("%s", name); + if (errno) perror_msg("%s", name); return; }