GNU bug report logs - #16444
grep -r fails with "Bad file descriptor" for mingw-w64

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: grep; Severity: minor; Reported by: "Stephan T. Lavavej" <stl@HIDDEN>; Keywords: moreinfo; merged with #19777; dated Tue, 14 Jan 2014 16:54:03 UTC; Maintainer for grep is bug-grep@HIDDEN.
Merged 16444 19777. Request was from Paul Eggert <eggert@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 16444 <at> debbugs.gnu.org:


Received: (at 16444) by debbugs.gnu.org; 12 Mar 2015 06:15:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 12 02:15:21 2015
Received: from localhost ([127.0.0.1]:43352 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YVwOv-0002Vb-0y
	for submit <at> debbugs.gnu.org; Thu, 12 Mar 2015 02:15:21 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:33243)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <eggert@HIDDEN>) id 1YVwOt-0002VP-EO
 for 16444 <at> debbugs.gnu.org; Thu, 12 Mar 2015 02:15:19 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
 by smtp.cs.ucla.edu (Postfix) with ESMTP id 9A2FFA60018;
 Wed, 11 Mar 2015 23:15:13 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
 by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id F9g14+3bQbXX; Wed, 11 Mar 2015 23:15:12 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
 [100.32.155.148])
 by smtp.cs.ucla.edu (Postfix) with ESMTPSA id CD16C39E801A;
 Wed, 11 Mar 2015 23:15:12 -0700 (PDT)
Message-ID: <55012EF0.8030900@HIDDEN>
Date: Wed, 11 Mar 2015 23:15:12 -0700
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
To: Norihiro Tanaka <noritnk@HIDDEN>, 
 David Grayson <davidegrayson@HIDDEN>
Subject: Re: bug#16444: bug #16444: grep -r fails with "Bad file descriptor"
 for mingw-w64
References: <000901cf1137$dfe87260$9fb95720$@nuwen.net>	<CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
 <20150311230621.8706.27F6AC2D@HIDDEN>
In-Reply-To: <20150311230621.8706.27F6AC2D@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 16444
Cc: 16444 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

Norihiro Tanaka wrote:
> MinGW always returns ST_INO = 0, which is POSIX incompatible.

Yes, this is a known deficiency in MinGW that is documented in Gnulib, here:

http://www.gnu.org/software/gnulib/manual/html_node/sys_002fstat_002eh.html

(search for "st_ino").

When we discovered this deficiency years ago, we decided that it'd be too much 
of a pain to work around it then.  Please see the thread starting here:

http://lists.gnu.org/archive/html/bug-gnulib/2009-09/msg00252.html

in which a patch was installed that tries to work around some of the MinGW 
deficiency; unfortunately the patch broke a lot of things and was backed out. 
I'm not optimistic about a fix this time either.

The deficiency should be fixed in MinGW, so that functions like 'stat' behave as 
programs expect.  In the meantime, I suggest not using recursive grep in MinGW.




Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.

Message received at 16444 <at> debbugs.gnu.org:


Received: (at 16444) by debbugs.gnu.org; 12 Mar 2015 05:47:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Mar 12 01:47:07 2015
Received: from localhost ([127.0.0.1]:43336 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YVvxb-0001ov-7D
	for submit <at> debbugs.gnu.org; Thu, 12 Mar 2015 01:47:07 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:60589)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <eggert@HIDDEN>) id 1YVvxY-0001oI-Ai
 for 16444 <at> debbugs.gnu.org; Thu, 12 Mar 2015 01:47:05 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
 by smtp.cs.ucla.edu (Postfix) with ESMTP id E1584A60018;
 Wed, 11 Mar 2015 22:46:57 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
 by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id GXMmLtNo6lse; Wed, 11 Mar 2015 22:46:57 -0700 (PDT)
Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net
 [100.32.155.148])
 by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 3CA1639E801A;
 Wed, 11 Mar 2015 22:46:57 -0700 (PDT)
Message-ID: <55012850.7000400@HIDDEN>
Date: Wed, 11 Mar 2015 22:46:56 -0700
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version: 1.0
To: David Grayson <davidegrayson@HIDDEN>, 16444 <at> debbugs.gnu.org
Subject: Re: bug#16444: bug #16444: grep -r fails with "Bad file descriptor"
 for mingw-w64
References: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
 <CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
In-Reply-To: <CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
Content-Type: multipart/mixed; boundary="------------080400000108090100000505"
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 16444
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

This is a multi-part message in MIME format.
--------------080400000108090100000505
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

David Grayson wrote:
> We can call that Bug C.  If a grep
> maintainer is interested in fixing Bug C, they should improve the logic at
> this line in grepdirent in grep.c:
>
>    filename = ent->fts_path + filename_prefix_len;

Thanks for reporting this bug.  I installed the attached patch for that.

--------------080400000108090100000505
Content-Type: text/x-patch;
 name="0001-grep-output-.-file-name-in-diagnostic.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0001-grep-output-.-file-name-in-diagnostic.patch"

From 61903c057376190f386430131342de8170e3c25a Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@HIDDEN>
Date: Wed, 11 Mar 2015 22:44:36 -0700
Subject: [PATCH] grep: output "." file name in diagnostic

This is bug C as reported by David Grayson in:
http://bugs.gnu.org/16444#18
This bug occurs only in obscure circumstances, and I didn't see
how to write a reasonable test case for it.
* src/grep.c (filename_prefix_len): Remove, replacing with ...
(omit_dot_slash): New static var.  All uses of the former replaced
with uses of the latter.
(grepdirent): Don't add 2 if the filename is just ".".
---
 src/grep.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index f720a8a..81b8716 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -384,7 +384,8 @@ static char const *matcher;
 /* For error messages. */
 /* The input file name, or (if standard input) "-" or a --label argument.  */
 static char const *filename;
-static size_t filename_prefix_len;
+/* Omit leading "./" from file names in diagnostics.  */
+static bool omit_dot_slash;
 static bool errseen;
 static bool write_error_seen;
 
@@ -640,7 +641,7 @@ skipped_file (char const *name, bool command_line, bool is_dir)
 {
   return (is_dir
           ? (directories == SKIP_DIRECTORIES
-             || (! (command_line && filename_prefix_len != 0)
+             || (! (command_line && omit_dot_slash)
                  && excluded_directory_patterns
                  && excluded_file_name (excluded_directory_patterns, name)))
           : (excluded_patterns
@@ -1483,7 +1484,9 @@ grepdirent (FTS *fts, FTSENT *ent, bool command_line)
       return true;
     }
 
-  filename = ent->fts_path + filename_prefix_len;
+  filename = ent->fts_path;
+  if (omit_dot_slash && filename[1])
+    filename += 2;
   follow = (fts->fts_options & FTS_LOGICAL
             || (fts->fts_options & FTS_COMFOLLOW && command_line));
 
@@ -2595,8 +2598,7 @@ main (int argc, char **argv)
     }
   else if (directories == RECURSE_DIRECTORIES && prepended < last_recursive)
     {
-      /* Grep through ".", omitting leading "./" from diagnostics.  */
-      filename_prefix_len = 2;
+      omit_dot_slash = true;
       ok = grep_command_line_arg (".");
     }
   else
-- 
2.1.0


--------------080400000108090100000505--




Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Mar 2015 00:36:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 11 20:36:32 2015
Received: from localhost ([127.0.0.1]:43275 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YVr71-0002Ui-Ir
	for submit <at> debbugs.gnu.org; Wed, 11 Mar 2015 20:36:32 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39640)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <pj@HIDDEN>) id 1YVquB-00029l-Qm
 for submit <at> debbugs.gnu.org; Wed, 11 Mar 2015 20:23:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pj@HIDDEN>) id 1YVqu5-0005O4-K1
 for submit <at> debbugs.gnu.org; Wed, 11 Mar 2015 20:23:10 -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_20,T_DKIM_INVALID
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:49139)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <pj@HIDDEN>)
 id 1YVqu5-0005O0-Gj
 for submit <at> debbugs.gnu.org; Wed, 11 Mar 2015 20:23:09 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41356)
 by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <pj@HIDDEN>)
 id 1YVqu4-0000j5-E8
 for bug-grep@HIDDEN; Wed, 11 Mar 2015 20:23:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pj@HIDDEN>) id 1YVqu0-0005Mc-Ct
 for bug-grep@HIDDEN; Wed, 11 Mar 2015 20:23:08 -0400
Received: from out2-smtp.messagingengine.com ([66.111.4.26]:44423)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <pj@HIDDEN>)
 id 1YVqu0-0005ML-4u
 for bug-grep@HIDDEN; Wed, 11 Mar 2015 20:23:04 -0400
Received: from compute2.internal (compute2.nyi.internal [10.202.2.42])
 by mailout.nyi.internal (Postfix) with ESMTP id 9B01520561
 for <bug-grep@HIDDEN>; Wed, 11 Mar 2015 20:23:01 -0400 (EDT)
Received: from web4 ([10.202.2.214])
 by compute2.internal (MEProxy); Wed, 11 Mar 2015 20:23:03 -0400
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=
 messagingengine.com; h=message-id:x-sasl-enc:from:to
 :mime-version:content-transfer-encoding:content-type:in-reply-to
 :references:subject:date; s=smtpout; bh=1+cLUCdqhAyH3/3OhMUwf1GF
 5Cg=; b=M6y7m7IR3RcLUwhQLeqhGjnhiwVnY21wv4/JIJhOLZUUG4ACmGkh5c/L
 OhZhAlpORrH+2GFV8PXtLdiU1rFNo+rM4woWU98RdrhiSGVyz5t3oCcdl2GNfetb
 2a3ad/6nZtlA3qL4se71yMlSIR6sSlyBmjBk+hwXbI8ZqkFR4RE=
Received: by web4.nyi.internal (Postfix, from userid 99)
 id 2782511AC95; Wed, 11 Mar 2015 20:23:03 -0400 (EDT)
Message-Id: <1426119783.1970360.239158349.0C90F3D4@HIDDEN>
X-Sasl-Enc: X3mwYDO1qa17q3kBHosCpVVKKGsE4jARhlkKsZhk3RUZ 1426119783
From: Paul Jackson <pj@HIDDEN>
To: bug-grep@HIDDEN
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
X-Mailer: MessagingEngine.com Webmail Interface - ajax-07699171
In-Reply-To: <20150311230621.8706.27F6AC2D@HIDDEN>
References: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
 <CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
 <20150311230621.8706.27F6AC2D@HIDDEN>
Subject: Re: bug#16444: bug #16444: grep -r fails with "Bad file descriptor"
 for mingw-w64
Date: Wed, 11 Mar 2015 19:23:03 -0500
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
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: -4.3 (----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Wed, 11 Mar 2015 20:36:30 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.3 (----)


Norihiro Tanaka wrote:
>> So if we compare the file path instead of st_ino, the bug may be fixed.

Or perhaps compare st_ino if it's non-zero, else compare path.

# define IS_SPECIAL_MinGW_Case(a) ((a).st_.ino == 0)

# define SAME_INODE(a, b)    \
    (IS_SPECIAL_MinGW_Case(a) ? \
            paths_compare_equal((a), (b)) : \
            (a).st_ino == (b).st_ino ) \
     && (a).st_dev == (b).st_dev)

Inode number compare works well when supported, and has different semantics
(such as in handling of hard links) in some cases, which semantics should not be
changed, in my view.  MinGW needs to be "quarantined" in this circumstance,
which is what the test for a non-zero inode would (apparently, from what you say)
accomplish.

In other words, our special handling for MinGW should not alter how we handle
everyone else.

-- 
                Paul Jackson
                pj@HIDDEN




Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.

Message received at 16444 <at> debbugs.gnu.org:


Received: (at 16444) by debbugs.gnu.org; 11 Mar 2015 14:06:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 11 10:06:35 2015
Received: from localhost ([127.0.0.1]:42872 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YVhHP-0007tn-3d
	for submit <at> debbugs.gnu.org; Wed, 11 Mar 2015 10:06:35 -0400
Received: from mailgw05.kcn.ne.jp ([61.86.7.212]:53876)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <noritnk@HIDDEN>) id 1YVhHL-0007tV-Km
 for 16444 <at> debbugs.gnu.org; Wed, 11 Mar 2015 10:06:32 -0400
Received: from mxs01-s (mailgw1.kcn.ne.jp [61.86.15.233])
 by mailgw05.kcn.ne.jp (Postfix) with ESMTP id 82B6867D92
 for <16444 <at> debbugs.gnu.org>; Wed, 11 Mar 2015 23:06:24 +0900 (JST)
X-matriXscan-loop-detect: 0c59066b83c709af55c29205a8dcc32494d65c85
Received: from mail09.kcn.ne.jp ([61.86.6.188]) by mxs01-s with ESMTP;
 Wed, 11 Mar 2015 23:06:21 +0900 (JST)
Received: from [10.120.1.74] (i118-21-128-66.s30.a048.ap.plala.or.jp
 [118.21.128.66])
 by mail09.kcn.ne.jp (Postfix) with ESMTPA id 81FB61BD0097;
 Wed, 11 Mar 2015 23:06:21 +0900 (JST)
Date: Wed, 11 Mar 2015 23:06:22 +0900
From: Norihiro Tanaka <noritnk@HIDDEN>
To: David Grayson <davidegrayson@HIDDEN>
Subject: Re: bug #16444: grep -r fails with "Bad file descriptor" for mingw-w64
In-Reply-To: <CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
References: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
 <CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
Message-Id: <20150311230621.8706.27F6AC2D@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Becky! ver. 2.65.07 [ja]
X-matriXscan-CTCmd-AV: Clean
X-matriXscan-Action: Approve
X-matriXscan: Uncategorized
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 16444
Cc: 16444 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

On Tue, 10 Mar 2015 22:20:28 -0700
David Grayson <davidegrayson@HIDDEN> wrote:

> Hello.
> 
> I am encountering this bug too.  I would like to compile grep 2.21 for
> Windows using mingw-w64 and Git Bash.  But the grep that I end up compiling
> exhibits several bugs related to recursive operation.  To reproduce the
> bugs, I made a directory called "testdir" with two empty directories named
> "a" and "b" inside it.  I used "cd" to go into the testdir.
> 
> Here is a shell session showing bug A:
> 
>   $ ../src/grep.exe a -r
>   c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: 9: Bad file
> descriptor
> 
> Here is a shell session showing bug B:
> 
>   $ ../src/grep.exe a -R
>   c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: warning: a:
> recursive directory loop
>   c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: warning: b:
> recursive directory loop

SAME_INODE macro defined in same-inode.h to be used by fts.c is as
following.

#  define SAME_INODE(a, b)    \
    ((a).st_ino == (b).st_ino \
     && (a).st_dev == (b).st_dev)

However, MinGW always returns ST_INO = 0, which is POSIX imcompatible.
I see that it leads to the result that all directories is same.

So if we compare the file path instead of st_ino, the bug may be fixed.





Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.

Message received at 16444 <at> debbugs.gnu.org:


Received: (at 16444) by debbugs.gnu.org; 11 Mar 2015 06:44:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 11 02:44:32 2015
Received: from localhost ([127.0.0.1]:42187 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YVaNb-00030b-Ch
	for submit <at> debbugs.gnu.org; Wed, 11 Mar 2015 02:44:32 -0400
Received: from mail-ie0-f173.google.com ([209.85.223.173]:35051)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <elavid@HIDDEN>) id 1YVZ4M-0000rM-EM
 for 16444 <at> debbugs.gnu.org; Wed, 11 Mar 2015 01:20:35 -0400
Received: by ieclw3 with SMTP id lw3so4343523iec.2
 for <16444 <at> debbugs.gnu.org>; Tue, 10 Mar 2015 22:20:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=mime-version:sender:date:message-id:subject:from:to:content-type;
 bh=xRVPmZfP5Fmzmiu55tiQC/ZRdEP9KGcifTkPXuY+lFo=;
 b=N6UDr4W6Cj3sXtPu70Vgf8oZv+epgytbAERstEfzBMA40K3PuMdVofb0dXSkAcQ+Jh
 GrKr9tJvHO+aR+p09+o+tx7ZXyj0YVMFhFwncUGAtuXD4wWZFl1FuYkS/ZM/78elMs7+
 +hLJ5JSZvQ1AR+WYyYNpEEr1g3stDI7+c2/d+hm+td7qU6oxEJPl1PE+z5ckblVNARe8
 86x+yIxnI3/zx+wKFc+N5jw8rHJEI3p5a+y92Gt1al1TwGGZFxNYcyfWeW4qXjU5H/91
 tl04dF/RRuQx8tUJ2dwoHnvL+ChGKkparlNDomumsT08nspOrZuK504WZOkbWldz01Ua
 IyYw==
MIME-Version: 1.0
X-Received: by 10.50.66.235 with SMTP id i11mr63045708igt.40.1426051228658;
 Tue, 10 Mar 2015 22:20:28 -0700 (PDT)
Received: by 10.107.130.231 with HTTP; Tue, 10 Mar 2015 22:20:28 -0700 (PDT)
Date: Tue, 10 Mar 2015 22:20:28 -0700
X-Google-Sender-Auth: t1BVG0tIJFUJnTlp3hOePL06xcI
Message-ID: <CAJ127VwCYeoZ4+EJ8mf1ZhDp=zDaNuXTuPE4mVt-cd0JFRaOFA@HIDDEN>
Subject: bug #16444: grep -r fails with "Bad file descriptor" for mingw-w64
From: David Grayson <davidegrayson@HIDDEN>
To: 16444 <at> debbugs.gnu.org
Content-Type: multipart/alternative; boundary=047d7bd6be0aea72d60510fc6c10
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 16444
X-Mailman-Approved-At: Wed, 11 Mar 2015 02:44:30 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

--047d7bd6be0aea72d60510fc6c10
Content-Type: text/plain; charset=UTF-8

Hello.

I am encountering this bug too.  I would like to compile grep 2.21 for
Windows using mingw-w64 and Git Bash.  But the grep that I end up compiling
exhibits several bugs related to recursive operation.  To reproduce the
bugs, I made a directory called "testdir" with two empty directories named
"a" and "b" inside it.  I used "cd" to go into the testdir.

Here is a shell session showing bug A:

  $ ../src/grep.exe a -r
  c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: 9: Bad file
descriptor

Here is a shell session showing bug B:

  $ ../src/grep.exe a -R
  c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: warning: a:
recursive directory loop
  c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: warning: b:
recursive directory loop

Bug A is more important because it prevents grep from printing the desired
output, so I am focussing on it first.  I think I have narrowed it down
enough to determine that it is actually a bug in the fts implementation
from gnulib, or in one of its dependencies (like mingw-w64 of msvcrt.dll).
If I put this small block of code at the top of main, it causes the same
error:

  { // tmphax
    program_name = "silly";
    filename = "emptydir";

    char *fts_arg[2];
    fts_arg[0] = (char *)filename;
    fts_arg[1] = NULL;
    int fts_opts = FTS_CWDFD | FTS_NOSTAT | FTS_TIGHT_CYCLE_CHECK
      | FTS_COMFOLLOW | FTS_PHYSICAL;
    FTS *fts = fts_open(fts_arg, fts_opts, NULL);
    printf("fts_open returned %p\n", fts);

    FTSENT *ent;
    ent = fts_read(fts);
    ent = fts_read(fts);
    printf("  fts_path=   %s\n", ent->fts_path);
    printf("  fts_accpath=%s\n", ent->fts_accpath);
    printf("  fts_name=   %s\n", ent->fts_name);
    if(ent->fts_info == FTS_ERR)
    {
      printf("  fts_info=   FTS_ERR\n");
      suppressible_error(filename, ent->fts_errno);
    }
    return 36;
  }

Note that "emptydir" is a directory inside the CWD that is empty.  The
output from that block of code is:

  fts_open returned 008222B0
    fts_path=   emptydir
    fts_accpath=emptydir
    fts_name=   emptydir
    fts_info=   FTS_ERR
  silly: emptydir: Bad file descriptor

I noticed that the Git repository for gnulib has some recent bug fixes for
the fts implementation, so I tried copying the fts* files from gnulib
commit 0f4fa16 into grep's lib directory, but that did not make any
difference.  My next step will probably be to take grep out of the picture
and report this as a bug to the gnulib team (or find an existing bug
report, like the one mentioned earlier in this thread).

Note that for Bug A, grep doesn't print "9" as the filename in the error
message every time.  It seems to be printing a random character that is
different each time, because grep is reading beyond the bounds of a string
and probably doing undefined behavior!  We can call that Bug C.  If a grep
maintainer is interested in fixing Bug C, they should improve the logic at
this line in grepdirent in grep.c:

  filename = ent->fts_path + filename_prefix_len;

If you run "grep a -r" then it seems that fts_path can be ".", while
filename_prefix_len is 2.  So it is really bad to execute the line above in
that case, because filename will be set to point past the end of the string
and then later used when printing error messages.

I hope this was helpful.

--David Grayson

--047d7bd6be0aea72d60510fc6c10
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello.<br><br>I am encountering this bug too.=C2=A0 I woul=
d like to compile grep 2.21 for Windows using mingw-w64 and Git Bash.=C2=A0=
 But the grep that I end up compiling exhibits several bugs related to recu=
rsive operation.=C2=A0 To reproduce the bugs, I made a directory called &qu=
ot;testdir&quot; with two empty directories named &quot;a&quot; and &quot;b=
&quot; inside it.=C2=A0 I used &quot;cd&quot; to go into the testdir.<br><b=
r>Here is a shell session showing bug A:<br><br>=C2=A0 $ ../src/grep.exe a =
-r<br>=C2=A0 c:\Users\David\Documents\grep\grep-2.21\src\grep.exe: 9: Bad f=
ile descriptor<br><br>Here is a shell session showing bug B:<br><br>=C2=A0 =
$ ../src/grep.exe a -R<br>=C2=A0 c:\Users\David\Documents\grep\grep-2.21\sr=
c\grep.exe: warning: a: recursive directory loop<br>=C2=A0 c:\Users\David\D=
ocuments\grep\grep-2.21\src\grep.exe: warning: b: recursive directory loop<=
br><br>Bug A is more important because it prevents grep from printing the d=
esired output, so I am focussing on it first.=C2=A0 I think I have narrowed=
 it down enough to determine that it is actually a bug in the fts implement=
ation from gnulib, or in one of its dependencies (like mingw-w64 of msvcrt.=
dll).=C2=A0 If I put this small block of code at the top of main, it causes=
 the same error:<br><br>=C2=A0 { // tmphax<br>=C2=A0 =C2=A0 program_name =
=3D &quot;silly&quot;;<br>=C2=A0 =C2=A0 filename =3D &quot;emptydir&quot;;<=
br><br>=C2=A0 =C2=A0 char *fts_arg[2];<br>=C2=A0 =C2=A0 fts_arg[0] =3D (cha=
r *)filename;<br>=C2=A0 =C2=A0 fts_arg[1] =3D NULL;<br>=C2=A0 =C2=A0 int ft=
s_opts =3D FTS_CWDFD | FTS_NOSTAT | FTS_TIGHT_CYCLE_CHECK<br>=C2=A0 =C2=A0 =
=C2=A0 | FTS_COMFOLLOW | FTS_PHYSICAL;<br>=C2=A0 =C2=A0 FTS *fts =3D fts_op=
en(fts_arg, fts_opts, NULL);<br>=C2=A0 =C2=A0 printf(&quot;fts_open returne=
d %p\n&quot;, fts);<br><br>=C2=A0 =C2=A0 FTSENT *ent;<br>=C2=A0 =C2=A0 ent =
=3D fts_read(fts);<br>=C2=A0 =C2=A0 ent =3D fts_read(fts);<br>=C2=A0 =C2=A0=
 printf(&quot; =C2=A0fts_path=3D =C2=A0 %s\n&quot;, ent-&gt;fts_path);<br>=
=C2=A0 =C2=A0 printf(&quot; =C2=A0fts_accpath=3D%s\n&quot;, ent-&gt;fts_acc=
path);<br>=C2=A0 =C2=A0 printf(&quot; =C2=A0fts_name=3D =C2=A0 %s\n&quot;, =
ent-&gt;fts_name);<br>=C2=A0 =C2=A0 if(ent-&gt;fts_info =3D=3D FTS_ERR)<br>=
=C2=A0 =C2=A0 {<br>=C2=A0 =C2=A0 =C2=A0 printf(&quot; =C2=A0fts_info=3D =C2=
=A0 FTS_ERR\n&quot;);<br>=C2=A0 =C2=A0 =C2=A0 suppressible_error(filename, =
ent-&gt;fts_errno);<br>=C2=A0 =C2=A0 }<br>=C2=A0 =C2=A0 return 36;<br>=C2=
=A0 }<br><br>Note that &quot;emptydir&quot; is a directory inside the CWD t=
hat is empty.=C2=A0 The output from that block of code is:<br><br>=C2=A0 ft=
s_open returned 008222B0<br>=C2=A0 =C2=A0 fts_path=3D =C2=A0 emptydir<br>=
=C2=A0 =C2=A0 fts_accpath=3Demptydir<br>=C2=A0 =C2=A0 fts_name=3D =C2=A0 em=
ptydir<br>=C2=A0 =C2=A0 fts_info=3D =C2=A0 FTS_ERR<br>=C2=A0 silly: emptydi=
r: Bad file descriptor<br>=C2=A0 <br>I noticed that the Git repository for =
gnulib has some recent bug fixes for the fts implementation, so I tried cop=
ying the fts* files from gnulib commit 0f4fa16 into grep&#39;s lib director=
y, but that did not make any difference.=C2=A0 My next step will probably b=
e to take grep out of the picture and report this as a bug to the gnulib te=
am (or find an existing bug report, like the one mentioned earlier in this =
thread).<br><br>Note that for Bug A, grep doesn&#39;t print &quot;9&quot; a=
s the filename in the error message every time.=C2=A0 It seems to be printi=
ng a random character that is different each time, because grep is reading =
beyond the bounds of a string and probably doing undefined behavior!=C2=A0 =
We can call that Bug C.=C2=A0 If a grep maintainer is interested in fixing =
Bug C, they should improve the logic at this line in grepdirent in grep.c:<=
br><br>=C2=A0 filename =3D ent-&gt;fts_path + filename_prefix_len;<br><br>I=
f you run &quot;grep a -r&quot; then it seems that fts_path can be &quot;.&=
quot;, while filename_prefix_len is 2.=C2=A0 So it is really bad to execute=
 the line above in that case, because filename will be set to point past th=
e end of the string and then later used when printing error messages.<br><b=
r>I hope this was helpful.<br><br>--David Grayson</div>

--047d7bd6be0aea72d60510fc6c10--




Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.
Severity set to 'minor' from 'normal' Request was from Paul Eggert <eggert@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Added tag(s) moreinfo. Request was from Paul Eggert <eggert@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 16444 <at> debbugs.gnu.org:


Received: (at 16444) by debbugs.gnu.org; 15 Jan 2014 04:26:52 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 14 23:26:52 2014
Received: from localhost ([127.0.0.1]:50851 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1W3I43-0000od-L5
	for submit <at> debbugs.gnu.org; Tue, 14 Jan 2014 23:26:52 -0500
Received: from mail-pd0-f171.google.com ([209.85.192.171]:50939)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <stl@HIDDEN>) id 1W3I40-0000oT-AQ
 for 16444 <at> debbugs.gnu.org; Tue, 14 Jan 2014 23:26:49 -0500
Received: by mail-pd0-f171.google.com with SMTP id x10so578495pdj.30
 for <16444 <at> debbugs.gnu.org>; Tue, 14 Jan 2014 20:26:47 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:references:in-reply-to:subject:date
 :message-id:mime-version:content-type:content-transfer-encoding
 :thread-index:content-language;
 bh=alVm3H/p13A06s/qB/PEwyaLMNAoUR4YjdrUlbi2uGU=;
 b=azbBDGIgNTCIR/HoLT47zIjA1dyVqPif3lJftoyJqkL7ZhmK8hLY8gLnAi39ssblZ6
 xEkrOqkMMJekH2ANFvSq9wuX/GsLNX5UQT55MSVWy/DwTGPXYhsYEMK+D8pRCxHkkD4n
 3eHA6ITOuIFbmaHomq3NqoSIDx715aC50p3Uhhd9wJtJSrVoaAxkpQQFJMKcR8dxccpo
 mlk+AU074CaPn0PVZqnjyp1u/qRikJDz8J/l9Dgx4MTZDN078tbzrvexoiLExeqqVFBV
 HtO/wYSuvBfm+155Vfh1Ef2zBPpCgds0ucJu+CoIr9DhMAsJWwxk1TQH5/fCLfG9bqPU
 gSCQ==
X-Gm-Message-State: ALoCoQnK6xnL9OUxbsgNd4Quod84fk7gLgQz5oCCRB834vUULL87ngFH02vx4n34vUB0xpjQF8tI
X-Received: by 10.67.14.162 with SMTP id fh2mr3617pad.120.1389760007105;
 Tue, 14 Jan 2014 20:26:47 -0800 (PST)
Received: from Helios ([50.46.144.96])
 by mx.google.com with ESMTPSA id bz4sm4880381pbb.12.2014.01.14.20.26.45
 for <multiple recipients>
 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 14 Jan 2014 20:26:46 -0800 (PST)
From: "Stephan T. Lavavej" <stl@HIDDEN>
To: "'Paul Eggert'" <eggert@HIDDEN>,
	<16444 <at> debbugs.gnu.org>
References: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
 <52D56D43.4030000@HIDDEN>
In-Reply-To: <52D56D43.4030000@HIDDEN>
Subject: RE: bug#16444: grep -r fails with "Bad file descriptor" for mingw-w64
Date: Tue, 14 Jan 2014 20:26:42 -0800
Message-ID: <000301cf11a9$fe93d480$fbbb7d80$@nuwen.net>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Outlook 14.0
Thread-Index: AQFsLQb3KgOTLYX+tzfY/eR49O8MEgKa/HZnmzYfSrA=
Content-Language: en-us
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 16444
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

I've spent hours debugging this - it is definitely mingw/mingw-w64 =
specific. I don't really understand what's going on, but it appears that =
this is the same issue as =
http://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00370.html . I =
see that you committed =
http://lists.gnu.org/archive/html/bug-gnulib/2010-09/msg00230.html a =
while ago, but there are still uses of dirfd which always returns -1 for =
mingw.

Figuring out how to make this work is far beyond my area of expertise =
(if this involved crazy C++ templates I'd be right at home).

I know mingw is a second-class citizen, but if you or someone else who =
understands what gnulib is doing here could investigate, that would be =
wonderful for everyone on Windows who uses grep.

Thanks,
STL

-----Original Message-----
From: Paul Eggert [mailto:eggert@HIDDEN]=20
Sent: Tuesday, January 14, 2014 9:01 AM
To: Stephan T. Lavavej; 16444 <at> debbugs.gnu.org
Subject: Re: bug#16444: grep -r fails with "Bad file descriptor" for =
mingw-w64

Stephan T. Lavavej wrote:
> I don't believe
> this is specific to mingw-w64.

Quite possibly it's specific to mingw, though.

Mingw is low priority for us,
but if someone like you with the motivation
and experience can come up with a patch
(ideally a patch to mingw), that might be nice.





Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.

Message received at 16444 <at> debbugs.gnu.org:


Received: (at 16444) by debbugs.gnu.org; 14 Jan 2014 17:00:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 14 12:00:58 2014
Received: from localhost ([127.0.0.1]:50531 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1W37MG-00050l-RH
	for submit <at> debbugs.gnu.org; Tue, 14 Jan 2014 12:00:57 -0500
Received: from smtp.cs.ucla.edu ([131.179.128.62]:51096)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <eggert@HIDDEN>) id 1W37MD-0004wh-K1
 for 16444 <at> debbugs.gnu.org; Tue, 14 Jan 2014 12:00:54 -0500
Received: from localhost (localhost.localdomain [127.0.0.1])
 by smtp.cs.ucla.edu (Postfix) with ESMTP id 7EEC339E8015;
 Tue, 14 Jan 2014 09:00:52 -0800 (PST)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
 by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id eepih+134sve; Tue, 14 Jan 2014 09:00:52 -0800 (PST)
Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net
 [108.0.233.62])
 by smtp.cs.ucla.edu (Postfix) with ESMTPSA id EEE5139E8011;
 Tue, 14 Jan 2014 09:00:51 -0800 (PST)
Message-ID: <52D56D43.4030000@HIDDEN>
Date: Tue, 14 Jan 2014 09:00:51 -0800
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version: 1.0
To: "Stephan T. Lavavej" <stl@HIDDEN>, 16444 <at> debbugs.gnu.org
Subject: Re: bug#16444: grep -r fails with "Bad file descriptor" for mingw-w64
References: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
In-Reply-To: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.4 (--)
X-Debbugs-Envelope-To: 16444
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)

Stephan T. Lavavej wrote:
> I don't believe
> this is specific to mingw-w64.

Quite possibly it's specific to mingw, though.

Mingw is low priority for us,
but if someone like you with the motivation
and experience can come up with a patch
(ideally a patch to mingw), that might be nice.




Information forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 14 Jan 2014 16:53:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 14 11:53:30 2014
Received: from localhost ([127.0.0.1]:50511 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1W37F3-0003mg-0B
	for submit <at> debbugs.gnu.org; Tue, 14 Jan 2014 11:53:29 -0500
Received: from eggs.gnu.org ([208.118.235.92]:40955)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <stl@HIDDEN>) id 1W35Jh-00005a-Br
 for submit <at> debbugs.gnu.org; Tue, 14 Jan 2014 09:50:10 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <stl@HIDDEN>) id 1W35Jb-0000FX-Ch
 for submit <at> debbugs.gnu.org; Tue, 14 Jan 2014 09:50:09 -0500
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]:37454)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <stl@HIDDEN>) id 1W35Jb-0000FF-9Y
 for submit <at> debbugs.gnu.org; Tue, 14 Jan 2014 09:50:03 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42609)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <stl@HIDDEN>) id 1W35JV-0006XG-Vz
 for bug-grep@HIDDEN; Tue, 14 Jan 2014 09:50:03 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <stl@HIDDEN>) id 1W35JQ-00006X-Uj
 for bug-grep@HIDDEN; Tue, 14 Jan 2014 09:49:57 -0500
Received: from mail-pb0-f50.google.com ([209.85.160.50]:45984)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <stl@HIDDEN>) id 1W35JQ-00006P-Oe
 for bug-grep@HIDDEN; Tue, 14 Jan 2014 09:49:52 -0500
Received: by mail-pb0-f50.google.com with SMTP id rq2so684832pbb.37
 for <bug-grep@HIDDEN>; Tue, 14 Jan 2014 06:49:51 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version
 :content-type:content-transfer-encoding:thread-index
 :content-language;
 bh=K7SahqUxdZ+VkYVZ3S7B1mmg/4COnkW2oQkzkJKVxno=;
 b=bLej9fANA+2NKUizXCUoHuYI22VeN4UyPVHaSpfZJSj51Injn/wVmLlpoE/EoWO8h5
 0wZGh4UdXHc4F7IlewHyV7VZdrZgjffiVXHnaVo1XjnaiFjq5IzRClxCM8N5S0BXzudp
 Zhw3kfGysAuTIEYn8TGXDoVn7QGicP3yNtwJkl6q3N0xaJc0qbjYTgmo7ZYKExi5CnsT
 wkcUMBCvg1pUeJ4OyWO/W8zTu8zT5Lt8qStKnsmymEAya9LJ8GWiQj6xmawBVlinQfw2
 fDi3Hj7u3UkzCjgyAsuuvmR28v6o/v3/RYD9W1OpgZCwyA1/8wSJa/dFKf/UJxbc3X2s
 sILA==
X-Gm-Message-State: ALoCoQnMlwJTGq8r11hWfdStsULOj6W1GggNy2pAnZcmHSAuuwmWjAyj7lSY0hRo0J3TjP/BJhkk
X-Received: by 10.66.182.199 with SMTP id eg7mr2094870pac.135.1389710991153;
 Tue, 14 Jan 2014 06:49:51 -0800 (PST)
Received: from Helios ([50.46.144.96])
 by mx.google.com with ESMTPSA id ns7sm1670630pbc.32.2014.01.14.06.49.50
 for <bug-grep@HIDDEN>
 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 14 Jan 2014 06:49:50 -0800 (PST)
From: "Stephan T. Lavavej" <stl@HIDDEN>
To: <bug-grep@HIDDEN>
Subject: grep -r fails with "Bad file descriptor" for mingw-w64
Date: Tue, 14 Jan 2014 06:49:48 -0800
Message-ID: <000901cf1137$dfe87260$9fb95720$@nuwen.net>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Outlook 14.0
Thread-Index: Ac8RNmS9vpMcTQa5R7iIRip/xqnPtA==
Content-Language: en-us
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
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: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Tue, 14 Jan 2014 11:53:28 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

Hi,

I'm building grep 2.16 with mingw-w64, and it works (with color!) for
grepping individual files, but not recursively:

C:\Temp\gcc>build\src\grep --version
build\src\grep (GNU grep) 2.16
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see
<http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

C:\Temp\gcc>dir /s /b somedir
C:\Temp\gcc\somedir\somefile.txt

C:\Temp\gcc>type somedir\somefile.txt
one
two
three

C:\Temp\gcc>build\src\grep -r two somedir
build\src\grep: somedir: Bad file descriptor

My installer-free build environment is available from
http://nuwen.net/mingw.html ; if necessary, I can provide exact instructions
to replicate my build (but I'm just running configure and make without any
extra options or local patches).

I've observed this since grep 2.11, also with mingw.org, so I don't believe
this is specific to mingw-w64.

Thanks,
STL





Acknowledgement sent to "Stephan T. Lavavej" <stl@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-grep@HIDDEN. Full text available.
Report forwarded to bug-grep@HIDDEN:
bug#16444; Package grep. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.