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

chmod() doesn't populate a local()ed $! #14073

Closed
p5pRT opened this issue Sep 4, 2014 · 12 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Sep 4, 2014

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

Searchable as RT122703$

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @FGasper

Created by @FGasper

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close $fh; local ($!); my $ok = chmod( 0111, $fh ); print "ok? [$ok] err? [$!/$^E]"'

The above breaks on every Perl version that I've tried​: 5.14.4/Linux, 5.18.2/Mac, and 5.20.0/Mac.

If you take out the "local ($!);", then it populates $! as you'd expect.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.14.4:

Configured by cPanel at Thu Jul 10 15:51:11 CDT 2014.

Summary of my perl5 (revision 5 version 14 subversion 4) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-358.23.2.el6.i686, archname=i386-linux-64int
    uname='linux rpmb-32-centos-6 2.6.32-358.23.2.el6.i686 #1 smp wed oct 16 17:21:31 utc 2013 i686 i686 i386 gnulinux '
    config_args='-des -Dusedevel -Darchname=i386-linux-64int -Dcc=/usr/bin/gcc -Dcpp=/usr/bin/cpp -DDEBUGGING=none -Doptimize=-Os -Dusemymalloc=n -Duseshrplib -Duselargefiles=yes -Duseposix=true -Dhint=recommended -Duseperlio=yes -Dccflags=-I/usr/local/cpanel/3rdparty/perl/514/include -L/usr/local/cpanel/3rdparty/perl/514/lib -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib -DAPPLLIB_EXP="/usr/local/cpanel" -Dcppflags=-I/usr/local/cpanel/3rdparty/perl/514/include -L/usr/local/cpanel/3rdparty/perl/514/lib -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib -Dldflags=-Wl,-rpath -Wl,/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/lib -Dprefix=/usr/local/cpanel/3rdparty/perl/514 -Dsiteprefix=/opt/cpanel/perl5/514 -Dsitebin=/opt/cpanel/perl5/514/bin -Dsitelib=/opt/cpanel/perl5/514/site_lib -Dusevendorprefix=true -Dvendorbin=/usr/local/cpanel/3rdparty/perl/514/bin -Dvendorprefix=/usr/local/cpanel/3rdparty/perl/514/lib/perl5 -Dvendorlib=/usr/local/cpanel/3rdparty/perl/514/lib/perl5/cpanel_lib -Dprivlib=/usr/local/cpanel/3rdparty/perl/514/lib/perl5/5.14.4 -Dman1dir=none -Dman3dir=none -Dscriptdir=/usr/local/cpanel/3rdparty/perl/514/bin -Dscriptdirexp=/usr/local/cpanel/3rdparty/perl/514/bin -Dsiteman1dir=none -Dsiteman3dir=none -Dinstallman1dir=none -Dversiononly=no -Dinstallusrbinperl=no -Dcf_by=cPanel -Dmyhostname=localhost -Dperladmin=root@localhost -Dcf_email=support@cpanel.net -Di_dbm=/usr/local/cpanel/3rdparty/include -Di_gdbm=/usr/local/cpanel/3rdparty/include -Di_ndbm=/usr/local/cpanel/3rdparty/include -Ud_dosuid -Uuserelocatableinc -Umad -Uusethreads -Uusemultiplicity -Uusesocks -Uuselongdouble -Ui_db -Aldflags=-L/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/lib -L/usr/lib -L/lib -lgdbm -Dlocincpth=/usr/local/cpanel/3rdparty/perl/514/include /usr/local/cpanel/3rdparty/include /usr/local/include  -Duse64bitint -Uuse64bitall -Acflags=-fPIC -DPIC -m32 -I/usr/local/cpanel/3rdparty/perl/514/include -I/usr/local/cpanel/3rdparty/include -Dlibpth=/usr/local/cpanel/3rdparty/perl/514/lib /usr/local/cpanel/3rdparty/lib /usr/local/lib /lib /usr/lib '
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='/usr/bin/gcc', ccflags ='-I/usr/local/cpanel/3rdparty/perl/514/include -L/usr/local/cpanel/3rdparty/perl/514/lib -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib -DAPPLLIB_EXP="/usr/local/cpanel" -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-Os',
    cppflags='-I/usr/local/cpanel/3rdparty/perl/514/include -L/usr/local/cpanel/3rdparty/perl/514/lib -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib -I/usr/local/cpanel/3rdparty/perl/514/include -L/usr/local/cpanel/3rdparty/perl/514/lib -I/usr/local/cpanel/3rdparty/include -L/usr/local/cpanel/3rdparty/lib -DAPPLLIB_EXP="/usr/local/cpanel" -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.7 20120313 (Red Hat 4.4.7-3)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='/usr/bin/gcc', ldflags ='-Wl,-rpath -Wl,/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/lib -L/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/lib -L/usr/lib -L/lib -lgdbm -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.12.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.12'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/local/cpanel/3rdparty/perl/514/lib/perl5/5.14.4/i386-linux-64int/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -Os -L/usr/local/cpanel/3rdparty/perl/514/lib -L/usr/local/cpanel/3rdparty/lib -L/usr/lib -L/lib -L/usr/local/lib -fstack-protector'

Locally applied patches:
    cPanel patches
    cPanel INC path changes
    Disabled some unstable tests on a kvm build server
    Cherry pick of 49498ca from p5p (RT 113514)
    Remove improper use of each() in B::walksymtable (5cc8528c90)


@INC for perl 5.14.4:
    /usr/local/cpanel
    /usr/local/cpanel
    /usr/local/cpanel/3rdparty/perl/514/lib/perl5/cpanel_lib/i386-linux-64int
    /usr/local/cpanel/3rdparty/perl/514/lib/perl5/cpanel_lib
    /usr/local/cpanel/3rdparty/perl/514/lib/perl5/5.14.4/i386-linux-64int
    /usr/local/cpanel/3rdparty/perl/514/lib/perl5/5.14.4
    /opt/cpanel/perl5/514/site_lib/i386-linux-64int
    /opt/cpanel/perl5/514/site_lib
    .


Environment for perl 5.14.4:
    HOME=/root
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/root/.opt/bin:/usr/local/cpanel/3rdparty/perl/514/bin:/usr/local/cpanel/3rdparty/bin:/usr/local/cpanel/3rdparty/node/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    PERL5LIB=/usr/local/cpanel
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @FGasper

chown() appears to have a similar problem.

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close
$fh; local ($!); my $ok = chown( 99, 99, $fh ); print "ok? [$ok] err?
[$!/$^E]"'

On 9/4/14 12​:50 PM, perlbug-followup@​perl.org wrote​:

Greetings,

This message has been automatically generated in response to the
creation of a perl bug report regarding​:
"chmod() doesn't populate a local()ed $!".

There is no need to reply to this message right now. Your ticket has been
assigned an ID of [perl #122703].

You can view your ticket at
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122703

Within the next 24 to 72 hours, your message will be posted to the Perl 5 Porters mailing list. Please be patient!

Please include the string​:

\[perl \#122703\]

in the subject line of all future correspondence about this issue. To do so,
you may reply to this message (please delete unnecessary quotes and text.)

Thank you,
perlbug-followup@​perl.org

-------------------------------------------------------------------------
X-Antiabuse​: This header was added to track abuse, please include it with any abuse report
X-Antiabuse​: Primary Hostname - felipe.dev.cpanel.net
X-Antiabuse​: Original Domain - perl.org
X-Antiabuse​: Originator/Caller UID/GID - [0 0] / [47 12]
X-Antiabuse​: Sender Address Domain - felipegasper.com
X-Get-Message-Sender-Via​: felipe.dev.cpanel.net​: sender_ident via received_protocol == local​: root/only user confirmed/virtual account not confirmed
Message-ID​: <5.14.4_13768_1409852466@​felipe.dev.cpanel.net>
From​: felipe@​felipegasper.com
Return-Path​: <felipe@​felipegasper.com>
Delivered-To​: rt-perl5@​rt.perl.org
Delivered-To​: perlbug@​perl.org
X-Spam-Check-BY​: la.mx.develooper.com
From felipe@​felipegasper.com Thu Sep 04 17​:50​:06 2014
X-Virus-Checked​: Checked
Subject​: chmod() doesn't populate a local()ed $!
To​: perlbug@​perl.org
X-Spam-Status​: No, hits=-5.2 required=8.0 tests=BAYES_00,PERLBUG_CONF,SPF_SOFTFAIL,URIBL_BLOCKED
Date​: Thu, 04 Sep 2014 12​:43​:13 -0500
Received​: (qmail 25993 invoked by uid 225); 4 Sep 2014 17​:50​:06 -0000
Received​: (qmail 25981 invoked by alias); 4 Sep 2014 17​:50​:01 -0000
Received​: from ng1.cptxoffice.net (HELO felipe.dev.cpanel.net) (208.74.121.102) by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Thu, 04 Sep 2014 10​:49​:58 -0700
Received​: from root by felipe.dev.cpanel.net with local (Exim 4.82) (envelope-from <felipe@​felipegasper.com>) id 1XPb3x-0003dN-6Z for perlbug@​perl.org; Thu, 04 Sep 2014 12​:43​:13 -0500
Reply-To​: felipe@​felipegasper.com
X-RT-Original-Encoding​: ascii
content-type​: text/plain; charset="utf-8"
X-RT-Interface​: Email

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @Leont

On Thu, Sep 4, 2014 at 7​:50 PM, felipe@​felipegasper.com <
perlbug-followup@​perl.org> wrote​:

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close $fh;
local ($!); my $ok = chmod( 0111, $fh ); print "ok? [$ok] err? [$!/$^E]"'

The above breaks on every Perl version that I've tried​: 5.14.4/Linux,
5.18.2/Mac, and 5.20.0/Mac.

If you take out the "local ($!);", then it populates $! as you'd expect.

The presence of «local $!» will prevent the previous value (from
tempfile()) from being visible, but the real issue here is that you're
trying to chmod a filehandle you've just closed. This is not a bug.

Leon

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

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

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @FGasper

On 9/4/14 3​:18 PM, Leon Timmermans via RT wrote​:

On Thu, Sep 4, 2014 at 7​:50 PM, felipe@​felipegasper.com <
perlbug-followup@​perl.org> wrote​:

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close $fh;
local ($!); my $ok = chmod( 0111, $fh ); print "ok? [$ok] err? [$!/$^E]"'

The above breaks on every Perl version that I've tried​: 5.14.4/Linux,
5.18.2/Mac, and 5.20.0/Mac.

If you take out the "local ($!);", then it populates $! as you'd expect.

The presence of «local $!» will prevent the previous value (from
tempfile()) from being visible, but the real issue here is that you're
trying to chmod a filehandle you've just closed. This is not a bug.

Compare this to how print behaves​:

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close
$fh; local ($!); my $ok = print {$fh} 123; print "ok? [$ok] err? [$!/$^E]"'

ok? [] err? [Bad file descriptor/Bad file descriptor]

The documented behavior is that chown() and chmod() populate $! whenever
there is an error. Perl is not implementing that behavior; by
definition, this seems to be a bug.

-FG

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @csjewell

He's trying to GENERATE an error in order to show that the local($!)
makes the expected value of $! disappear.

So yes, it is a bug.

On Thu, Sep 4, 2014, at 14​:17, Leon Timmermans wrote​:

On Thu, Sep 4, 2014 at 7​:50 PM, felipe@​felipegasper.com <
perlbug-followup@​perl.org> wrote​:

The above breaks on every Perl version that I've tried​: 5.14.4/Linux,
5.18.2/Mac, and 5.20.0/Mac.

If you take out the "local ($!);", then it populates $! as you'd expect.

The presence of «local $!» will prevent the previous value (from
tempfile()) from being visible, but the real issue here is that you're
trying to chmod a filehandle you've just closed. This is not a bug.

Leon
--
Curtis Jewell
csjewell@​cpan.org http​://csjewell.dreamwidth.org/
perl@​curtisjewell.name http​://www.curtisjewell.name/
"Your random numbers are not that random" -- perl-5.10.1.tar.gz/util.c

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @Leont

On Thu, Sep 4, 2014 at 10​:50 PM, Felipe Gasper <felipe@​felipegasper.com>
wrote​:

Compare this to how print behaves​:

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close $fh;
local ($!); my $ok = print {$fh} 123; print "ok? [$ok] err? [$!/$^E]"'

ok? [] err? [Bad file descriptor/Bad file descriptor]

The documented behavior is that chown() and chmod() populate $! whenever
there is an error. Perl is not implementing that behavior; by definition,
this seems to be a bug.

Notice hor

$ perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close $fh;
$! = 0; my $ok = chmod( 0111, $fh ); print "ok? [$ok] err? [$!/$^E]"'

gives exactly the same result. The only conclusion that can be made here is
that $! isn't being written to in the first place. This has nothing to do
with localization.

Yes, it does not set $! if $fh is a closed filehandle (because it doesn't
do any syscall). This is probably a bug, the attached patch fixes this.

Leon

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 4, 2014

From @Leont

0001-Set-when-chmod-ing-a-closed-filehandle.patch
From db6a4e3750b3eb75b40b7856183e5dedaa89d409 Mon Sep 17 00:00:00 2001
From: Leon Timmermans <fawaka@gmail.com>
Date: Thu, 4 Sep 2014 23:00:05 +0200
Subject: [PATCH] Set $! when chmod()ing a closed filehandle

---
 doio.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doio.c b/doio.c
index a631eeb..3e013d0 100644
--- a/doio.c
+++ b/doio.c
@@ -1759,6 +1759,7 @@ Perl_apply(pTHX_ I32 type, SV **mark, SV **sp)
 #endif
            }
            else {
+           SETERRNO(EBADF,RMS_IFI);
            tot--;
            }
        }
@@ -1799,6 +1800,7 @@ Perl_apply(pTHX_ I32 type, SV **mark, SV **sp)
 #endif
            }
            else {
+           SETERRNO(EBADF,RMS_IFI);
            tot--;
            }
        }
-- 
2.1.0-222-g4315447

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Sep 5, 2014

From @Abigail

On Thu, Sep 04, 2014 at 10​:50​:10AM -0700, felipe@​felipegasper.com wrote​:

# New Ticket Created by felipe@​felipegasper.com
# Please include the string​: [perl #122703]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122703 >

This is a bug report for perl from felipe@​felipegasper.com,
generated with the help of perlbug 1.39 running under perl 5.14.4.

-----------------------------------------------------------------
[Please describe your issue here]

perl -MFile​::Temp -e'my ($fh, $path) = File​::Temp​::tempfile(); close $fh; local ($!); my $ok = chmod( 0111, $fh ); print "ok? [$ok] err? [$!/$^E]"'

The above breaks on every Perl version that I've tried​: 5.14.4/Linux, 5.18.2/Mac, and 5.20.0/Mac.

If you take out the "local ($!);", then it populates $! as you'd expect.

It sets $! to "Inappropriate ioctl for device" on my box, which
doesn't at all seem an error message I was expecting.

In fact, that's what $! contains after File​::Temp​::tempfile​:

  #!/usr/bin/perl

  use 5.010;
  use File​::Temp;

  say "[$!]";
  my ($fh, $path) = File​::Temp​::tempfile;
  say "[$!]";

  __END__
  []
  [Inappropriate ioctl for device]

Which further indicates what Leon was saying, the issue here is that
chmod() doesn't populate $!.

Abigail

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 22, 2014

From @tonycoz

On Thu Sep 04 14​:14​:31 2014, LeonT wrote​:

Yes, it does not set $! if $fh is a closed filehandle (because it doesn't
do any syscall). This is probably a bug, the attached patch fixes this.

I've applied essentially this patch, but with some tests as 8334cae.

I didn't notice yours until after I'd written mine.

Tony

@p5pRT p5pRT closed this Oct 22, 2014
@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 22, 2014

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

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Oct 22, 2014

From @FGasper

Thank you! :)

On 22 Oct 2014 12​:39 AM, Tony Cook via RT wrote​:

According to our records, your request regarding
"chmod() doesn't populate a local()ed $!"
has been resolved.

If you have any further questions or concerns, please respond to this message.

For other topics, please create a new ticket.

<URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122703 >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.