Skip to content
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

readline returns EBADF at eof in 5.10.0 #9507

Closed
p5pRT opened this issue Oct 2, 2008 · 6 comments
Closed

readline returns EBADF at eof in 5.10.0 #9507

p5pRT opened this issue Oct 2, 2008 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 2, 2008

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

Searchable as RT59550$

@p5pRT
Copy link
Author

p5pRT commented Oct 2, 2008

From Mark.Martinec@ijs.si

This is a bug report for perl from Mark.Martinec@​ijs.si,
generated with the help of perlbug 1.36 running under perl 5.10.0.


The readline() function (or a diamond I/O operator <>) returns
a EBADF (Bad file descriptor) as its errno status on end-of-file
when PERLIO is set to "stdio" (which unfortunately is a default
setting in some Linux distributions).

The situation worsened with 5.10.0 (compared to 5.8.8)​:

$ echo "test" | PERLIO="stdio" perl5.8.8 -e \
  'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​: $!"'
test

$ echo "test" | PERLIO="stdio" perl5.10.0 -e \
  'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​: $!"'
test
Err​: Bad file descriptor at -e line 1, <> line 1.

This used to be an issue only on some Linux distributions
and not on FreeBSD. Now with 5.10.0 it happens here too.
The problem only occurs with PERLIO="stdio", not with an
unset PERLIO or with PERLIO="perlio".

The bug lures application programmers to ignore I/O status,
which is a bad programming practice and can lead to
hard-to-diagnose secondary application failures.
This is causing grief in at least two projects currently.
It would be really nice to get the status reporting right.

Btw, it is a probably related to bug #39060 (regarding non-NL
terminated last line), although missing last NL adds it own
quirk and perhaps still merits its own bug entry.
Now even with PERLIO="perlio" (or unset)​:

# line terminated with a NL
$ echo "test" | perl5.10.0 -e \
  'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​:$!"'
test

# line not terminated with a NL
$ echo -n "test" | perl5.10.0 -e \
  'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​:$!"'
Err​:Bad file descriptor at -e line 1, <> line 1.
test



Flags​:
  category=core
  severity=medium


Site configuration information for perl 5.10.0​:

Configured by mark at Fri Sep 26 14​:12​:03 UTC 2008.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration​:
  Platform​:
  osname=freebsd, osvers=7.0-release-p1, archname=amd64-freebsd
  uname='freebsd neli-virtual.ijs.si 7.0-release-p1 freebsd 7.0-release-p1 #0​: sun jun 1 03​:02​:30 cest 2008
lesi@​neli.ijs.si​:usrobjusrsrcsysneli amd64 '
  config_args='-ds -e'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include',
  optimize='-O',
  cppflags='-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include'
  ccversion='', gccversion='4.2.1 20070719 [FreeBSD]', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags ='-Wl,-E -L/usr/local/lib'
  libpth=/usr/lib /usr/local/lib
  libs=-lm -lcrypt -lutil -lc
  perllibs=-lm -lcrypt -lutil -lc
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
  cccdlflags='-DPIC -fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl 5.10.0​:
  /usr/local/lib/perl5/5.10.0/amd64-freebsd
  /usr/local/lib/perl5/5.10.0
  /usr/local/lib/perl5/site_perl/5.10.0/amd64-freebsd
  /usr/local/lib/perl5/site_perl/5.10.0
  /usr/local/lib/perl5/site_perl/5.6.2.OFF
  /usr/local/lib/perl5/site_perl
  .


Environment for perl 5.10.0​:
  HOME=/root
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/local/zenoss/bin​:/usr/local/bin​:/usr/local/sbin​:/bin​:/sbin​:/usr/bin​:/usr/sbin
  PERL_BADLANG (unset)
  SHELL=/usr/local/bin/bash

@p5pRT
Copy link
Author

p5pRT commented May 28, 2009

From @nwc10

Dave notes​:

appears to be a regression since 5.8.8

@p5pRT
Copy link
Author

p5pRT commented May 28, 2009

@nwc10 - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 28, 2009

From p5p@spam.wizbit.be

On Thu Oct 02 03​:10​:45 2008, mmartinec wrote​:

This is a bug report for perl from Mark.Martinec@​ijs.si,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
The readline() function (or a diamond I/O operator <>) returns
a EBADF (Bad file descriptor) as its errno status on end-of-file
when PERLIO is set to "stdio" (which unfortunately is a default
setting in some Linux distributions).

The situation worsened with 5.10.0 (compared to 5.8.8)​:

$ echo "test" | PERLIO="stdio" perl5.8.8 -e \
'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​: $!"'
test

$ echo "test" | PERLIO="stdio" perl5.10.0 -e \
'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​: $!"'
test
Err​: Bad file descriptor at -e line 1, <> line 1.

This used to be an issue only on some Linux distributions
and not on FreeBSD. Now with 5.10.0 it happens here too.
The problem only occurs with PERLIO="stdio", not with an
unset PERLIO or with PERLIO="perlio".

The bug lures application programmers to ignore I/O status,
which is a bad programming practice and can lead to
hard-to-diagnose secondary application failures.
This is causing grief in at least two projects currently.
It would be really nice to get the status reporting right.

Btw, it is a probably related to bug #39060 (regarding non-NL
terminated last line), although missing last NL adds it own
quirk and perhaps still merits its own bug entry.
Now even with PERLIO="perlio" (or unset)​:

# line terminated with a NL
$ echo "test" | perl5.10.0 -e \
'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​:$!"'
test

# line not terminated with a NL
$ echo -n "test" | perl5.10.0 -e \
'for($!=0; &lt;&gt;; $!=0){print}; $!==0 or die "Err​:$!"'
Err​:Bad file descriptor at -e line 1, <> line 1.
test

-----------------------------------------------------------------

For me this happens with perl-5.8.1+. (on linux)

Binary search with PERLIO=stdio​:

----Program----
#!/usr/bin/perl

system( qq#echo "test" | PERLIO="stdio" $^X -e 'for(\$!=0; <>;
\$!=0){print}; \$!==0 or die "Err​: \$!"'#);

----Output of .../ptWpY1t/perl-5.8.0@​19461/bin/perl----
test

----EOF ($?='0')----
----Output of .../pP1BToL/perl-5.8.0@​19462/bin/perl----
Err​: Invalid argument at -e line 1, <> line 1.
test

----EOF ($?='0')----
Need a perl between 19461 and 19462

http​://public.activestate.com/cgi-bin/perlbrowse/p/19462
Change 19462 by jhi@​kosh on 2003/05/09 18​:53​:27

  Try to comprehensively have a plan B if a PerlIO
  layer doesn't have a particular function.
  (1) If there's a corresponding PerlIOBase, call it.
  (2) If not having the function is 'harmless', be silently happy.
  (Currently only Flush is in this category.)
  (3) Otherwise set errno and return failure.

A binary search with PERLIO=perlio and without a newline​:
----Program----
#!/usr/bin/perl

system( qq#echo -n "test" | PERLIO="perlio" $^X -e 'for(\$!=0; <>;
\$!=0){print}; \$!==0 or die "Err​: \$!"'#);

----Output of .../ptWpY1t/perl-5.8.0@​19461/bin/perl----
test
----EOF ($?='0')----
----Output of .../pP1BToL/perl-5.8.0@​19462/bin/perl----
Err​: Invalid argument at -e line 1, <> line 1.
test
----EOF ($?='0')----
Need a perl between 19461 and 19462

Best regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2009

From @rgs

Solved by d7dfc38

@p5pRT
Copy link
Author

p5pRT commented Jun 8, 2009

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

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