From: girst Date: Fri, 28 Jul 2017 01:27:56 +0000 (+0200) Subject: some more bugfixes, some found X-Git-Url: https://git.gir.st/forkaftergrep.git/commitdiff_plain/05257d9b12f57769fe3fae8eeff6e54761c183fb some more bugfixes, some found if grep exits with an error, fag thinks, a match was found. simulate by setting grep's arguments to "-GE" (conflicting regex types) in the code (setting both from the cli won't trigger, as only the last one will be passed thru to grep) --- diff --git a/fag.1 b/fag.1 index 843af5b..3dd77d2 100644 --- a/fag.1 +++ b/fag.1 @@ -69,6 +69,8 @@ or in case the chid process exits prematurely, its exit code is inherited. Notab .IR SIGNAL needs to be given as an integer; mnemonic should be supported in the future. .PP +if grep exits with a code > 0, fag should terminate with grep's exit code and an error message. instead, fag exits as if a match was found. +.PP Sometimes, stdin behaves strange after the program terminates. .SS Reporting Bugs Please report bugs and patches to the issue tracker at https://github.com/girst/forkaftergrep/. diff --git a/fag.c b/fag.c index 725722a..bf497b3 100644 --- a/fag.c +++ b/fag.c @@ -1,5 +1,5 @@ /* forkaftergrep (C) 2017 Tobias Girstmair, GPLv3 */ -//TODO: EX_UNAVAILABLE is wrongly used three times +//TODO: if grep exits with an error, fag thinks a match was found #define _XOPEN_SOURCE 500 #define _DEFAULT_SOURCE @@ -41,7 +41,8 @@ int main (int argc, char** argv) { "\t-t N\ttimeout after N seconds\n" "\t-k [M]\tsend signal M to child after timeout (default: 15/SIGTERM)\n" "\t-e\tgrep on stderr instead of stdout\n" - "\t-V\tbe verbose; print PROGRAM's stdout/stderr to stderr\n", argv[0]); + "\t-V\tbe verbose; print PROGRAM's stdout/stderr to stderr\n" + "\t-[EFGPiwxyU]\t grep options\n", argv[0]); return EX_OK; case 'v': fprintf (stderr, VERTEXT); @@ -49,7 +50,7 @@ int main (int argc, char** argv) { /* `grep' options (Note: missing `-e:', `-f:') */ case 'E': optg.regex = extended_regexp; break; case 'F': optg.regex = fixed_strings ; break; - case 'G': optg.regex = basic_regexp ; break; /* default */ + case 'G': optg.regex = basic_regexp ; break; /* grep default */ case 'P': optg.regex = perl_regexp ; break; case 'i': /* fall thru */ case 'y': optg.ignore_case = 1; break; @@ -170,7 +171,7 @@ int fork_after_grep (struct opt opts, struct grepopt optg) { execlp ("grep", "grep", grep_options, opts.pattern, NULL); fprintf (stderr, "exec error (grep): %s", strerror (errno)); - _exit (EX_UNAVAILABLE); + _exit (EX_SOFTWARE); } else { close (grep_pipefd[0]); for (;;) { @@ -208,6 +209,7 @@ int fork_after_grep (struct opt opts, struct grepopt optg) { write(grep_pipefd[1], buf, nbytes); } + // TODO: exits with `0' even if `grep' exits with code > 0 ! if (waitpid (grep_cpid, &grep_status, WNOHANG) > 0 && WIFEXITED (grep_status)) { close (grep_pipefd[1]);