Skip to content

<FH> producing "Bad file descriptor" #7834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
p5pRT opened this issue Mar 12, 2005 · 10 comments
Closed

<FH> producing "Bad file descriptor" #7834

p5pRT opened this issue Mar 12, 2005 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 12, 2005

Migrated from rt.perl.org#34412 (status was 'resolved')

Searchable as RT34412$

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2005

From [email protected]

Created by [email protected]

BAD​:
"vanilla Perl-5.8.6" or "Fedora Core 3 perl-5.8.5-9"​:
$ echo a >/tmp/a;perl -e 'open FH,"/tmp/a" or die;$!=undef();my $line=&lt;FH&gt;;print "$!​:$line\n";'
Bad file descriptor​:a

GOOD​:
"Red Hat 7.2 Perl-5.6.1" or other old Perls​:
$ echo a >/tmp/a;perl -e 'open FH,"/tmp/a" or die;$!=undef();my $line=&lt;FH&gt;;print "$!​:$line\n";'
:a

Last CPAN "File​::Grep" is several years failing "make test" due to it.
Error will not happend if $/ ne "\n";

Thanks for the great tool; looking for 6.

Perl Info

Flags:
    category=core
    severity=medium

This perlbug was built using Perl v5.8.5 in the Red Hat build system.
It is being executed now by Perl v5.8.5 - Tue Oct 12 12:44:18 EDT 2004.

Site configuration information for perl v5.8.5:

Configured by Red Hat, Inc. at Tue Oct 12 12:44:18 EDT 2004.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
  Platform:
    osname=linux, osvers=2.4.21-14.elsmp, archname=i386-linux-thread-multi
    uname='linux tweety.build.redhat.com 2.4.21-14.elsmp #1 smp wed apr 14 18:55:47 edt 2004 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -m32 -march=i386 -mtune=pentium4 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -m32 -march=i386 -mtune=pentium4',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.2 20041006 (Red Hat 3.4.2-5)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.3.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.3'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.5:
    /home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl/5.8.5
    /home/lace/lib/perl5/site_perl/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl
    /home/lace/lib/perl5/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/5.8.5
    /home/lace/lib/perl5/i386-linux-thread-multi
    /home/lace/lib/perl5
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/i386-linux-thread-multi
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/i386-linux-thread-multi
    /usr/lib/perl5
    /home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl/5.8.5
    /home/lace/lib/perl5/site_perl/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl
    /home/lace/lib/perl5/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/5.8.5
    /home/lace/lib/perl5/i386-linux-thread-multi
    /home/lace/lib/perl5
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/i386-linux-thread-multi
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/i386-linux-thread-multi
    /usr/lib/perl5
    /home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl/5.8.5
    /home/lace/lib/perl5/site_perl/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl
    /home/lace/lib/perl5/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/5.8.5
    /home/lace/lib/perl5/i386-linux-thread-multi
    /home/lace/lib/perl5
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/i386-linux-thread-multi
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/i386-linux-thread-multi
    /usr/lib/perl5
    /home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl/5.8.5
    /home/lace/lib/perl5/site_perl/i386-linux-thread-multi
    /home/lace/lib/perl5/site_perl
    /home/lace/lib/perl5/5.8.5/i386-linux-thread-multi
    /home/lace/lib/perl5/5.8.5
    /home/lace/lib/perl5/i386-linux-thread-multi
    /home/lace/lib/perl5
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/i386-linux-thread-multi
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/i386-linux-thread-multi
    /usr/lib/perl5
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/5.8.4
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl/5.8.2
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.5
    /usr/lib/perl5/vendor_perl/5.8.4
    /usr/lib/perl5/vendor_perl/5.8.3
    /usr/lib/perl5/vendor_perl/5.8.2
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    .


Environment for perl v5.8.5:
    HOME=/home/lace
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH=/home/lace/lib:/opt/sfw/lib:/home/lace/lib:/opt/sfw/lib:/home/lace/lib:/opt/sfw/lib:/home/lace/lib:/opt/sfw/lib
    LOGDIR (unset)
    PATH=/home/lace/bin:/usr/local/bin:/opt/sfw/bin:/usr/sbin:/sbin:/usr/dist/exe:/opt/SUNWspro/bin:/home/lace/bin:/usr/local/bin:/opt/sfw/bin:/usr/sbin:/sbin:/usr/dist/exe:/opt/SUNWspro/bin:/home/lace/bin:/usr/local/bin:/opt/sfw/bin:/usr/sbin:/sbin:/usr/dist/exe:/opt/SUNWspro/bin:/home/lace/bin:/usr/local/bin:/opt/sfw/bin:/usr/sbin:/sbin:/usr/dist/exe:/opt/SUNWspro/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin
    PERLLIB=/home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl/5.8.5:/home/lace/lib/perl5/site_perl/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl:/home/lace/lib/perl5/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/5.8.5:/home/lace/lib/perl5/i386-linux-thread-multi:/home/lace/lib/perl5:/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/site_perl/5.8.5:/usr/lib/perl5/site_perl/i386-linux-thread-multi:/usr/lib/perl5/site_perl:/usr/lib/perl5/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/5.8.5:/usr/lib/perl5/i386-linux-thread-multi:/usr/lib/perl5:/home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl/5.8.5:/home/lace/lib/perl5/site_perl/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl:/home/lace/lib/perl5/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/5.8.5:/home/lace/lib/perl5/i386-linux-thread-multi:/home/lace/lib/perl5:/usr/lib/perl5/site_perl/5.8.5/i386-linux!
 -thread-multi:/usr/lib/perl5/site_perl/5.8.5:/usr/lib/perl5/site_perl/i386-linux-thread-multi:/usr/lib/perl5/site_perl:/usr/lib/perl5/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/5.8.5:/usr/lib/perl5/i386-linux-thread-multi:/usr/lib/perl5:/home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl/5.8.5:/home/lace/lib/perl5/site_perl/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl:/home/lace/lib/perl5/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/5.8.5:/home/lace/lib/perl5/i386-linux-thread-multi:/home/lace/lib/perl5:/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/site_perl/5.8.5:/usr/lib/perl5/site_perl/i386-linux-thread-multi:/usr/lib/perl5/site_perl:/usr/lib/perl5/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/5.8.5:/usr/lib/perl5/i386-linux-thread-multi:/usr/lib/perl5:/home/lace/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/home/lace/lib/perl5/site_perl/5.8.5:/home/lace/lib/perl5/site_perl/i386-linux-t!
 hread-multi:/home/lace/lib/perl5/site_perl:/home/lace/lib/perl!
 5/5.8.5/
i386-linux-thread-multi:/home/lace/lib/perl5/5.8.5:/home/lace/lib/perl5/i386-linux-thread-multi:/home/lace/lib/perl5:/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/site_perl/5.8.5:/usr/lib/perl5/site_perl/i386-linux-thread-multi:/usr/lib/perl5/site_perl:/usr/lib/perl5/5.8.5/i386-linux-thread-multi:/usr/lib/perl5/5.8.5:/usr/lib/perl5/i386-linux-thread-multi:/usr/lib/perl5
    PERL_BADLANG (unset)
    PERL_MM_OPT=PERL=/home/lace/bin/perlilib PREFIX=/home/lace
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2005

From [email protected]

In article <rt-3.0.11-34412-108744.6.00529762057072@​perl.org>,
  "lace@​jankratochvil.net (via RT)" <perlbug-followup@​perl.org> writes​:

BAD​:
"vanilla Perl-5.8.6" or "Fedora Core 3 perl-5.8.5-9"​:
$ echo a >/tmp/a;perl -e 'open FH,"/tmp/a" or die;$!=undef();my $line=&lt;FH&gt;;print "$!​:$line\n";'
Bad file descriptor​:a

Not a bug really. $! is only meaningful immediately after a system or library
call *failed*. Succesful calls are in principle allowed to change $!
any way they like.

Having said that there doesn't seem to be a good reason for $! to
get set here though. But tracking the base cause down would be mainly for
curiosity.

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 12, 2005

From [email protected]

Hi Ton,

On Sat, 12 Mar 2005 18​:19​:33 +0100, (Ton Hospel) via RT wrote​:
...

Not a bug really. $! is only meaningful immediately after a system or library
call *failed*. Succesful calls are in principle allowed to change $!
any way they like.

OK, fully understood. In fact I am really a moron as I write code aware of it.

Going to fix File​::Grep.

Thanks,
Lace

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2005

@rgs - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Mar 14, 2005
@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2005

From [email protected]

On Mar 12, Ton Hospel said​:

In article <rt-3.0.11-34412-108744.6.00529762057072@​perl.org>,
"lace@​jankratochvil.net (via RT)" <perlbug-followup@​perl.org> writes​:

BAD​:
"vanilla Perl-5.8.6" or "Fedora Core 3 perl-5.8.5-9"​:
$ echo a >/tmp/a;perl -e 'open FH,"/tmp/a" or die;$!=undef();my $line=&lt;FH&gt;;print "$!​:$line\n";'
Bad file descriptor​:a

Not a bug really. $! is only meaningful immediately after a system or library
call *failed*. Succesful calls are in principle allowed to change $!
any way they like.

Having said that there doesn't seem to be a good reason for $! to
get set here though. But tracking the base cause down would be mainly for
curiosity.

I contacted the author of the module in question. After looking at his
code, he has​:

  eval { $line = <$fh> };
  if ($! || $@​) { ... }

I told him he should local()ize $! and $@​ before doing the eval { }.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http​://japhy.perlmonk.org/ % have long ago been overpaid?
http​://www.perlmonks.org/ % -- Meister Eckhart

@p5pRT
Copy link
Author

p5pRT commented Mar 15, 2005

From [email protected]

Hi,

On Mon, 14 Mar 2005 16​:47​:01 +0100, japhy@​perlmonk.org via RT wrote​:
...

I contacted the author of the module in question. After looking at his
code, he has​:

eval { $line = <$fh> };
if ($! || $@​) { ... }

I told him he should local()ize $! and $@​ before doing the eval { }.

I think local() is not enough - still the successful <$fh> would set $! and
the 'if ($! || $@​)' below would falsely follow the fail code path.

Anyway I already sent him the [attached] patch. He has not replied, though.
Please forward it to the appropriate person to make it to CPAN.
I already had such problems in the past with unresponsible buggy CPAN module
authors. :-?

Thanks,
Lace

@p5pRT
Copy link
Author

p5pRT commented Mar 15, 2005

From [email protected]

Hi,

please apply the patch to fix File​::Grep functionality (with failing "make
test") with recent Perls such as 5.8.5 or 5.8.6.

Regards,
Lace

@p5pRT
Copy link
Author

p5pRT commented Mar 15, 2005

From [email protected]

File-Grep-0.01-Grep.pm-failfail.patch
--- File-Grep-0.01/Grep.pm-orig	2002-01-26 03:32:57.000000000 +0100
+++ File-Grep-0.01/Grep.pm	2005-03-12 18:46:09.052150615 +0100
@@ -57,13 +57,13 @@
       $openfile = 0;
     }
     my $line;
-    eval { $line = <$fh> };
-    if ( $! || $@ ) {
-      if ( $@ ) {
-	!$SILENT and carp "Cannot use file '$file' for fgrep: $@";
-      } else {
-	!$SILENT and carp "Cannot use file '$file' for fgrep: $!";
-      }
+    # Be aware $! may be modified in any way if <$fh> does not fail.
+    my $err;
+    eval { defined($line = <$fh>) or $err = "$!"; };
+    # $@ is more important than $!
+    $err = $@ if $@;
+    if ( $err ) {
+      !$SILENT and carp "Cannot use file '$file' for fgrep: $err";
       last;
     } else {
       while ( defined( $line ) ) {

@p5pRT
Copy link
Author

p5pRT commented Mar 15, 2005

From @nwc10

On Mon, Mar 14, 2005 at 08​:25​:34PM +0100, Jan Kratochvil wrote​:

Anyway I already sent him the [attached] patch. He has not replied, though.
Please forward it to the appropriate person to make it to CPAN.
I already had such problems in the past with unresponsible buggy CPAN module
authors. :-?

You've already forwarded it to the appropriate person - the author.
CPAN is just an archive - it can't force authors to be responsive, even
when people send them well formatted code.

There's a section of the CPAN FAQ which is probably relevant

  "How do I go about maintaining a module when the author is unresponsive?"
  http​://www.cpan.org/misc/cpan-faq.html#How_maintain_module

Nicholas Clark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant