From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 26 11:14:07 2015 Received: (at submit) by debbugs.gnu.org; 26 Jun 2015 15:14:07 +0000 Received: from localhost ([127.0.0.1]:58310 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8VKQ-00030R-4a for submit@debbugs.gnu.org; Fri, 26 Jun 2015 11:14:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53743) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8QCu-0002JW-Mi for submit@debbugs.gnu.org; Fri, 26 Jun 2015 05:46:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8QCo-0008HO-0a for submit@debbugs.gnu.org; Fri, 26 Jun 2015 05:45:55 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:58243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8QCn-0008HJ-Tx for submit@debbugs.gnu.org; Fri, 26 Jun 2015 05:45:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8QCm-0007nx-VV for bug-grep@gnu.org; Fri, 26 Jun 2015 05:45:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8QCg-0008Dn-Fl for bug-grep@gnu.org; Fri, 26 Jun 2015 05:45:52 -0400 Received: from dd25110.kasserver.com ([85.13.144.97]:46096) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8QCg-0008C5-1B for bug-grep@gnu.org; Fri, 26 Jun 2015 05:45:46 -0400 Received: from bilbo.auenland (ipb2180a88.dynamic.kabel-deutschland.de [178.24.10.136]) by dd25110.kasserver.com (Postfix) with ESMTPSA id 98EBEEC04C5 for ; Fri, 26 Jun 2015 11:40:31 +0200 (CEST) Received: from [192.168.0.119] (elessar.fritz.box [192.168.0.119]) by bilbo.auenland (Postfix) with ESMTP id 28F03170EE7 for ; Fri, 26 Jun 2015 11:40:30 +0200 (CEST) To: bug-grep@gnu.org From: Uwe Koloska X-Enigmail-Draft-Status: N1110 Subject: [BUG] hang at fifo despite of '-D skip' Message-ID: <558D1E0D.8090204@koloro.de> Date: Fri, 26 Jun 2015 11:40:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 26 Jun 2015 11:14:03 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hello, 'grep -D skip' hangs when examining a FIFO. This is a regression. It has been working since 2.5.2 (commit 5c7194f9e739082dc14f75769f2c19a39bb6cf84). Debian 6.0.10 has 2.6.3 and there it's working, too. But 2.12 in debian 7.8 has the problem. Don't know exactly when it changed. The help (and manual) states: -D, --devices=ACTION how to handle devices, FIFOs and sockets; ACTION is 'read' or 'skip' >From this I expect, that grep will skip a FIFO and not block while trying to handle it. You can test for this error with this commands: -8<----------------------------------------------------- mkfifo myfifo grep -D skip foo myfifo & PID=$! sleep 1 kill $PID 2>/dev/null && echo fail || echo ok -8<----------------------------------------------------- and here is the same idea as test for the test-suite: #+FILE: tests/skip-fifo -8<----------------------------------------------------- #!/bin/sh # grep must ignore a fifo when started with -D skip . "${srcdir=.}/init.sh"; path_prepend_ ../src mkfifo myfifo grep -D skip foo myfifo & PID=$! # just to make sure sleep 1 kill $PID && fail=1 # the other way round grep foo myfifo & PID=$! # just to make sure sleep 1 kill $PID || fail=1 Exit $fail -8<----------------------------------------------------- Best regards Uwe Koloska From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 26 19:51:05 2015 Received: (at 20902-done) by debbugs.gnu.org; 26 Jun 2015 23:51:05 +0000 Received: from localhost ([127.0.0.1]:58525 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8dOh-0002en-91 for submit@debbugs.gnu.org; Fri, 26 Jun 2015 19:51:04 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35249) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8dOd-0002eF-8q for 20902-done@debbugs.gnu.org; Fri, 26 Jun 2015 19:51:00 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5F86B160852; Fri, 26 Jun 2015 16:50:53 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hFH7NDRih3oR; Fri, 26 Jun 2015 16:50:52 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7F31A160853; Fri, 26 Jun 2015 16:50:52 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tKGjXWTj3nEe; Fri, 26 Jun 2015 16:50:52 -0700 (PDT) Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5DE0C160821; Fri, 26 Jun 2015 16:50:52 -0700 (PDT) Message-ID: <558DE55C.2040805@cs.ucla.edu> Date: Fri, 26 Jun 2015 16:50:52 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Uwe Koloska Subject: Re: [BUG] hang at fifo despite of '-D skip' Content-Type: multipart/mixed; boundary="------------050702060308040200090409" X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: 20902-done Cc: 20902-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.4 (-) This is a multi-part message in MIME format. --------------050702060308040200090409 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for reporting this bug. I installed the attached into the grep master on savannah, and it (or something like it) should appear in the next release. --------------050702060308040200090409 Content-Type: text/x-diff; name="0001-grep-don-t-hang-on-command-line-fifo-if-D-skip.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-grep-don-t-hang-on-command-line-fifo-if-D-skip.patch" >From bd6a91f0e891eaec4602b610426901d56b8aa3d7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 26 Jun 2015 16:44:50 -0700 Subject: [PATCH] grep: don't hang on command-line fifo if -D skip * NEWS: Document this. * src/grep.c (skip_devices): New function, with code taken from grepdirent. (grepdirent): Use it. Avoid an unnecessary initialization. (grepfile): If skipping devices, open files with O_NONBLOCK. Throw in O_NOCTTY while we're at it. (grepdesc): Skip devices here, too. Not only does this fix the bug, it fixes an unlikely race condition if some other process renames a device between fstatat and openat. * tests/skip-device: Add a test for this bug. --- NEWS | 3 +++ src/grep.c | 21 +++++++++++++++++---- tests/skip-device | 5 +++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index ae8f38f..bbbe893 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,9 @@ GNU grep NEWS -*- outline -*- When the JIT stack is exhausted, grep -P now grows the stack rather than reporting an internal PCRE error. + 'grep -D skip PATTERN FILE' no longer hangs if FILE is a fifo. + [bug introduced in grep-2.12] + * Noteworthy changes in release 2.21 (2014-11-23) [stable] diff --git a/src/grep.c b/src/grep.c index 6f43284..d1581e3 100644 --- a/src/grep.c +++ b/src/grep.c @@ -433,6 +433,13 @@ is_device_mode (mode_t m) return S_ISCHR (m) || S_ISBLK (m) || S_ISSOCK (m) || S_ISFIFO (m); } +static bool +skip_devices (bool command_line) +{ + return (devices == SKIP_DEVICES + || (devices == READ_COMMAND_LINE_DEVICES && !command_line)); +} + /* Return if ST->st_size is defined. Assume the file is not a symbolic link. */ static bool @@ -1466,7 +1473,6 @@ grepdirent (FTS *fts, FTSENT *ent, bool command_line) { bool follow; int dirdesc; - struct stat *st = ent->fts_statp; command_line &= ent->fts_level == FTS_ROOTLEVEL; if (ent->fts_info == FTS_DP) @@ -1515,9 +1521,9 @@ grepdirent (FTS *fts, FTSENT *ent, bool command_line) case FTS_DEFAULT: case FTS_NSOK: - if (devices == SKIP_DEVICES - || (devices == READ_COMMAND_LINE_DEVICES && !command_line)) + if (skip_devices (command_line)) { + struct stat *st = ent->fts_statp; struct stat st1; if (! st->st_mode) { @@ -1572,7 +1578,10 @@ open_symlink_nofollow_error (int err) static bool grepfile (int dirdesc, char const *name, bool follow, bool command_line) { - int desc = openat_safer (dirdesc, name, O_RDONLY | (follow ? 0 : O_NOFOLLOW)); + int oflag = (O_RDONLY | O_NOCTTY + | (follow ? 0 : O_NOFOLLOW) + | (skip_devices (command_line) ? O_NONBLOCK : 0)); + int desc = openat_safer (dirdesc, name, oflag); if (desc < 0) { if (follow || ! open_symlink_nofollow_error (errno)) @@ -1601,6 +1610,10 @@ grepdesc (int desc, bool command_line) goto closeout; } + if (desc != STDIN_FILENO && skip_devices (command_line) + && is_device_mode (st.st_mode)) + goto closeout; + if (desc != STDIN_FILENO && command_line && skipped_file (filename, true, S_ISDIR (st.st_mode) != 0)) goto closeout; diff --git a/tests/skip-device b/tests/skip-device index 32663fe..e73bad3 100755 --- a/tests/skip-device +++ b/tests/skip-device @@ -8,4 +8,9 @@ echo foo | grep -D skip foo - || fail=1 echo foo | grep --devices=skip foo || fail=1 +require_timeout_ +mkfifo myfifo || framework_failure_ +timeout 2s grep -D skip foo myfifo +test $? -eq 1 || fail=1 + Exit $fail -- 2.1.0 --------------050702060308040200090409-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 27 13:47:17 2015 Received: (at 20902) by debbugs.gnu.org; 27 Jun 2015 17:47:17 +0000 Received: from localhost ([127.0.0.1]:59367 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8uCC-0003f3-DF for submit@debbugs.gnu.org; Sat, 27 Jun 2015 13:47:16 -0400 Received: from mail-yk0-f173.google.com ([209.85.160.173]:34353) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8uCA-0003em-Lt; Sat, 27 Jun 2015 13:47:15 -0400 Received: by ykfy125 with SMTP id y125so84089271ykf.1; Sat, 27 Jun 2015 10:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=g+oapi4lERN56x6jHd6V9/JcMUu07vixVL9uBJJxYCs=; b=EZJDd3MB07hLttDjtfXDuaSRY3qk4rlNT/v127GRyTj4jzh6UQbqeO5+Dy0SpzgRaG wrylwC3WjlLbxk1gtF1IaELqEjb76dRloxKMkgxg4g297HFmSsasqDDaodEd9m+8MqQS mSrFCgcO/II2sAvjZN8/u00naywuJ1ej9Qhu43WdNW0tS/w+MAthli23Ol72tZJUVfzA yYDOPb0w+ZyeGdmZHwv/x3nORGGZPmvjqzj1Ax7802n0DMvf/iQGwjztJSoy03iKZJfF w3NCCnq+KBu+XhW7kD2S/vIoj4p5tyB5N3nekLHKpIu6ckBlTJFMD8y7Zee1znh7y0VF nbyA== X-Received: by 10.170.50.19 with SMTP id 19mr9226328yks.61.1435427229009; Sat, 27 Jun 2015 10:47:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.201.66 with HTTP; Sat, 27 Jun 2015 10:46:49 -0700 (PDT) In-Reply-To: <558DE55C.2040805@cs.ucla.edu> References: <558D1E0D.8090204@koloro.de> <558DE55C.2040805@cs.ucla.edu> From: Jim Meyering Date: Sat, 27 Jun 2015 10:46:49 -0700 X-Google-Sender-Auth: FqHbEKFJ8jRjMH_V0FDVMppBD1E Message-ID: Subject: Re: bug#20902: [BUG] hang at fifo despite of '-D skip' To: 20902@debbugs.gnu.org, Paul Eggert , Uwe Koloska Content-Type: text/plain; charset=UTF-8 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 20902 Cc: 20902-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On Fri, Jun 26, 2015 at 4:50 PM, Paul Eggert wrote: > Thanks for reporting this bug. I installed the attached into the grep > master on savannah, and it (or something like it) should appear in the next > release. Nice! Thank you both. From unknown Thu Jun 19 14:05:09 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 26 Jul 2015 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator