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

close for piped open sets $! to the wrong value #1150

Closed
p5pRT opened this issue Feb 7, 2000 · 6 comments
Closed

close for piped open sets $! to the wrong value #1150

p5pRT opened this issue Feb 7, 2000 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 7, 2000

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

Searchable as RT2113$

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2000

From @mjdominus

Created by @mjdominus

This program runs /bin/false, a standard unix command, on a piped
open, then closes the filehandle. /bin/false is the program which
exits immediately with exit status 1. According to the manual​:

  If the file handle came from a piped open C<close()> will
  additionally return FALSE if one of the other system calls
  involved fails or if the program exits with non-zero status.
  (If the only problem was that the program exited non-zero
  C<$!> will be set to C<0>.)

  [perlfunc/close]

Since /bin/false exited with non-zero status, $! should be set to 0.
However, it is instead set to the empty string.

  #!/usr/bin/perl
  open FH, "/bin/false |" or die "fork​: $!";
  print ">> $_" while <FH>;
  my $rc = close FH;
  my $errstr = defined($!) ? $! : "undefined";
  $rc = defined($rc) ? $rc : "undefined";
  print "close rc​: ($rc); \$!​: ($errstr); \$?​: ($?)\n";

The output is​:

  close rc​: (); $!​: (); $?​: (256)

If there is any version of Perl that has ever set $! to 0, I cannot
find it. Versions up through 5.003 set $! to `Illegal seek' (which I
guess is probably system-dependent) and versions 5.004 and later show
the behavior above.

 

Perl Info


Site configuration information for perl 5.00503:

Configured by mjd at Sun Jan 23 14:15:22 EST 2000.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.12, archname=i586-linux
    uname='linux plover 2.2.12 #10 mon nov 1 17:02:09 est 1999 i586 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.90.29 980515 (egcs-1.0.3 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib
    libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.6, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/lib/perl5/5.00503/i586-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i586-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/mjd
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/lib:/usr/lib:/usr/X11R6/lib
    LOGDIR (unset)
    PATH=/home/mjd/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/sbin:/usr/sbin:/usr/local/bin/X11:/usr/local/bin/mh:/data/mysql/bin:/home/mjd/TPI/bin:/usr/local/mysql/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2000

From [Unknown Contact. See original ticket]

mjd@​plover.com writes​:

Since /bin/false exited with non-zero status, $! should be set to 0.
However, it is instead set to the empty string.

Do you remember that $! is double-headed? It has both numeric and
string values...

Ilya

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2000

From @mjdominus

mjd@​plover.com writes​:

Since /bin/false exited with non-zero status, $! should be set to 0.
However, it is instead set to the empty string.

Do you remember that $! is double-headed? It has both numeric and
string values...

Maybe the documentation is at fault, then. I don't see why the
current behavior is not simply described by

  If the only problem was that the program exited non-zero $!
  will be set to the empty string.

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2000

From [Unknown Contact. See original ticket]

On Mon, Feb 07, 2000 at 04​:19​:54PM -0500, Mark-Jason Dominus wrote​:

Do you remember that $! is double-headed? It has both numeric and
string values...

Maybe the documentation is at fault, then. I don't see why the
current behavior is not simply described by

If the only problem was that the program exited non\-zero $\!
will be set to the empty string\.

Because the value of $! *is not a string*.

Ilya

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2000

From @mjdominus

Because the value of $! *is not a string*.

If it were a string, how would the behvaior be different in this case?

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2000

From [Unknown Contact. See original ticket]

Maybe the documentation is at fault, then. I don't see why the
current behavior is not simply described by

If the only problem was that the program exited non\-zero $\!
will be set to the empty string\.

Because the value of $! *is not a string*.

Wrong. Back into the Sophist's hole with you. Just
looking for crap to pick at today, eh?

It can be a string.
It can be also a number.

And these are magically rather than canonically connected.

So what.

--tom

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