avoid sticky problem with '-f - -f -'
This commit is contained in:
parent
9490553cb9
commit
29f901204f
56
backport-grep-avoid-sticky-problem-with-f-f.patch
Normal file
56
backport-grep-avoid-sticky-problem-with-f-f.patch
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
From ad6de316cca655cd8b0b20b3e9dd18e7e98e443a Mon Sep 17 00:00:00 2001
|
||||||
|
From: Paul Eggert <eggert@cs.ucla.edu>
|
||||||
|
Date: Sat, 21 Aug 2021 10:44:17 -0700
|
||||||
|
Subject: [PATCH 111/151] =?UTF-8?q?grep:=20avoid=20sticky=20problem=20with?=
|
||||||
|
=?UTF-8?q?=20=E2=80=98-f=20-=20-f=20-=E2=80=99?=
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
|
Inspired by bug#50129 even though this is a different bug.
|
||||||
|
* src/grep.c (main): For ‘-f -’, use clearerr (stdin) after
|
||||||
|
reading, so that ‘grep -f - -f -’ reads stdin twice even
|
||||||
|
when stdin is a tty. Also, for ‘-f FILE’, report any
|
||||||
|
I/O error when closing FILE.
|
||||||
|
---
|
||||||
|
src/grep.c | 17 +++++++++++------
|
||||||
|
1 file changed, 11 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/grep.c b/src/grep.c
|
||||||
|
index 7ba602d..c9ce65d 100644
|
||||||
|
--- a/src/grep.c
|
||||||
|
+++ b/src/grep.c
|
||||||
|
@@ -2429,7 +2429,6 @@ main (int argc, char **argv)
|
||||||
|
size_t cc;
|
||||||
|
int opt, prepended;
|
||||||
|
int prev_optind, last_recursive;
|
||||||
|
- int fread_errno;
|
||||||
|
intmax_t default_context;
|
||||||
|
FILE *fp;
|
||||||
|
exit_failure = EXIT_TROUBLE;
|
||||||
|
@@ -2600,11 +2599,17 @@ main (int argc, char **argv)
|
||||||
|
if (cc == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
- fread_errno = errno;
|
||||||
|
- if (ferror (fp))
|
||||||
|
- die (EXIT_TROUBLE, fread_errno, "%s", optarg);
|
||||||
|
- if (fp != stdin)
|
||||||
|
- fclose (fp);
|
||||||
|
+ int err = errno;
|
||||||
|
+ if (!ferror (fp))
|
||||||
|
+ {
|
||||||
|
+ err = 0;
|
||||||
|
+ if (fp == stdin)
|
||||||
|
+ clearerr (fp);
|
||||||
|
+ else if (fclose (fp) != 0)
|
||||||
|
+ err = errno;
|
||||||
|
+ }
|
||||||
|
+ if (err)
|
||||||
|
+ die (EXIT_TROUBLE, err, "%s", optarg);
|
||||||
|
/* Append final newline if file ended in non-newline. */
|
||||||
|
if (oldcc != keycc && keys[keycc - 1] != '\n')
|
||||||
|
keys[keycc++] = '\n';
|
||||||
|
--
|
||||||
|
1.8.3.1
|
||||||
|
|
||||||
10
grep.spec
10
grep.spec
@ -1,11 +1,13 @@
|
|||||||
Name: grep
|
Name: grep
|
||||||
Version: 3.4
|
Version: 3.4
|
||||||
Release: 1
|
Release: 2
|
||||||
Summary: A string search utility
|
Summary: A string search utility
|
||||||
License: GPLv3+
|
License: GPLv3+
|
||||||
URL: http://www.gnu.org/software/grep/
|
URL: http://www.gnu.org/software/grep/
|
||||||
Source0: https://ftp.gnu.org/gnu/grep/grep-%{version}.tar.xz
|
Source0: https://ftp.gnu.org/gnu/grep/grep-%{version}.tar.xz
|
||||||
|
|
||||||
|
Patch1: backport-grep-avoid-sticky-problem-with-f-f.patch
|
||||||
|
|
||||||
BuildRequires: gcc git pcre-devel >= 3.9-10 texinfo gettext
|
BuildRequires: gcc git pcre-devel >= 3.9-10 texinfo gettext
|
||||||
Provides: /bin/egrep /bin/fgrep /bin/grep bundled(gnulib)
|
Provides: /bin/egrep /bin/fgrep /bin/grep bundled(gnulib)
|
||||||
|
|
||||||
@ -44,6 +46,12 @@ make check
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Feb 8 2022 yangzhuangzhuang<yangzhuangzhuang1@h-partners.com> - 3.4-2
|
||||||
|
- Type:bugfix
|
||||||
|
- ID:NA
|
||||||
|
- SUG:NA
|
||||||
|
- DESC:avoid sticky problem with '-f - -f -'
|
||||||
|
|
||||||
* Wed Dec 15 2021 yangzhuangzhuang<yangzhuangzhuang1@huawei.com> - 3.4-1
|
* Wed Dec 15 2021 yangzhuangzhuang<yangzhuangzhuang1@huawei.com> - 3.4-1
|
||||||
- Type:bugfix
|
- Type:bugfix
|
||||||
- ID:NA
|
- ID:NA
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user