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

bug with die under linux #682

Closed
p5pRT opened this issue Oct 5, 1999 · 6 comments
Closed

bug with die under linux #682

p5pRT opened this issue Oct 5, 1999 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 5, 1999

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

Searchable as RT1572$

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From courtois@pasteur.fr

  It looks there's a bug with die under linux. It can be evidenced with the following
code​:

#!/usr/bin/perl

# save STDERR and redirect to /dev/null
open OLDSTDERR, ">&STDERR" or die "STDERR dup failed​: $!";
close STDERR;
open STDERR, ">/dev/null" or die "STDERR redirect failed​: $!";

# restore previous state

close STDERR;
open STDERR, ">&OLDSTDERR" or die "STDERR restoration failed​: $!";
close OLDSTDERR;

print STDERR "this is printed correctly\n";

die "this message is not printed under linux\n";

  The bug is that the die message is not displayed.

  The bug appears on every perl 5.00X on linux. It was tested with the out of the box perl
from Slackware,Debian 2.1, redhat, suse, and mandrake , and also on a perl 5.005_03 and
5.004_04 which I compiled on my debian 2.1 box. It seems to work with every other flavours
of unix.

  However the message is displayed correctly if both "close STDERR;" instructions are
removed. (if they are removed, I've been told the dup doesn't work under NT)

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From [Unknown Contact. See original ticket]

  Hi,

  It looks there's a bug with die under linux. It can be evidenced with the following
code​:

#!/usr/bin/perl

# save STDERR and redirect to /dev/null
open OLDSTDERR, ">&STDERR" or die "STDERR dup failed​: $!";
close STDERR;
open STDERR, ">/dev/null" or die "STDERR redirect failed​: $!";

# restore previous state

close STDERR;
open STDERR, ">&OLDSTDERR" or die "STDERR restoration failed​: $!";
close OLDSTDERR;

print STDERR "this is printed correctly\n";

die "this message is not printed under linux\n";

  The bug is that the die message is not displayed.

  The bug appears on every perl 5.00X on linux. It was tested with the out of the box perl
from Slackware,Debian 2.1, redhat, suse, and mandrake , and also on a perl 5.005_03 and
5.004_04 which I compiled on my debian 2.1 box. It seems to work with every other flavours
of unix.

  However the message is displayed correctly if both "close STDERR;" instructions are
removed. (if they are removed, I've been told the dup doesn't work under NT)

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From @gsar

On 05 Oct 1999 14​:07​:25 -0000, we-will-never-know-who wrote​:

It looks there's a bug with die under linux. It can be evidenced with the following
code​:

#!/usr/bin/perl

# save STDERR and redirect to /dev/null
open OLDSTDERR, ">&STDERR" or die "STDERR dup failed​: $!";
close STDERR;
open STDERR, ">/dev/null" or die "STDERR redirect failed​: $!";

# restore previous state

close STDERR;
open STDERR, ">&OLDSTDERR" or die "STDERR restoration failed​: $!";
close OLDSTDERR;

print STDERR "this is printed correctly\n";

die "this message is not printed under linux\n";

The bug is that the die message is not displayed.

The bug appears on every perl 5.00X on linux. It was tested with the out of the box pe
rl
from Slackware,Debian 2.1, redhat, suse, and mandrake , and also on a perl 5.005_03 and
5.004_04 which I compiled on my debian 2.1 box. It seems to work with every other flavou
rs
of unix.

However the message is displayed correctly if both "close STDERR;" instructions are
removed. (if they are removed, I've been told the dup doesn't work under NT)

This appears to be a peculiarity of libc/glibc on Linux.

I'm sure if I'd go so far as to call it a bug in libc, though. FWIW,
here's a simple test case​:

  #include <stdio.h>

  int
  main(int argc, char **argv)
  {
  FILE *oldstderr, *newstderr;
  printf("stderr=%d\n", fileno(stderr));

  oldstderr = fdopen(dup(fileno(stderr)), "w");
  printf("oldstderr=%d\n", fileno(oldstderr));
  fclose(stderr);

  newstderr = fdopen(dup(fileno(oldstderr)), "w");
  printf("newstderr=%d\n", fileno(newstderr));
  printf("stderr=%d\n", fileno(stderr));
  fclose(oldstderr);

  fprintf(stderr, "works\n");
  return 0;
  }

On a stock Debian Linux 2.1 system (with glib-2.0.7 I think), it prints​:

  stderr=2
  oldstderr=3
  newstderr=2
  stderr=-1

On Solaris 2.6 (and a few other platforms), it prints​:

  stderr=2
  oldstderr=3
  newstderr=2
  stderr=2
  works

Perl itself has been fixed to not rely on the behavior above. See​:
ftp​://ftp.linux.activestate.com/pub/staff/gsar/APC/5.005_62/diffs/5302.gz

Sarathy
gsar@​activestate.com

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 1999

From @gsar

On Tue, 05 Oct 1999 20​:01​:39 PDT, Gurusamy Sarathy wrote​:

I'm sure if I'd go so far as to call it a bug in libc, though. [...]
  ^
  ^
  *not*

Sarathy
gsar@​activestate.com

@p5pRT
Copy link
Author

p5pRT commented Oct 10, 1999

From [Unknown Contact. See original ticket]

Gurusamy Sarathy <gsar@​activestate.com> writes​:

This appears to be a peculiarity of libc/glibc on Linux.

I'm sure if I'd go so far as to call it a bug in libc, though. FWIW,
here's a simple test case​:

This is definitely no bug. Rather, other systems are borken if they
allow writing to a stream which previously was closed.

--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com `------------------------

@p5pRT
Copy link
Author

p5pRT commented Oct 11, 1999

From @schwern

Guru Sarathy was said to have uddered​:

Perl itself has been fixed to not rely on the behavior above. See​:
ftp​://ftp.linux.activestate.com/pub/staff/gsar/APC/5.005_62/diffs/5302.gz

Did you mean 4302.gz?

PS I confirm the glibc2 issue with glib-2.1.2 (Debian Linux Potato)

--

Michael G Schwern schwern@​pobox.com
  http​://www.pobox.com/~schwern
  /(?​:(?​:(1)[.-]?)?\(?(\d{3})\)?[.-]?)?(\d{3})[.-]?(\d{4})(x\d+)?/i

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