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
CORE::socket() mangles EMFILE and turns it into EBADF #15383
Comments
From @leonerdCreated by @leonerdThis is a bug report for perl from leonerd@leonerd.org.uk, ----------------------------------------------------------------- $ ulimit -n 64 At strace level: ... Perl Info
|
From @jkeenanOn Fri Jun 03 08:01:38 2016, leonerd@leonerd.org.uk wrote:
Copying those commands to the command-prompt, I got: ##### Should '-Mblib' actually be '-Iblib'? Only when I made that correction did I get your results:
-- |
The RT System itself - Status changed from 'new' to 'open' |
From zefram@fysh.orgLeoNerd wrote:
There is explicit code to do that: fd = PerlSock_socket(domain, type, protocol); The SETERRNO() was introduced by commit 375ed12 in 2014. I don't see -zefram |
From @leonerdOn Sat, 4 Jun 2016 19:02:16 -0700
Oh oops, that's just a leftover -Mblib from my testing of something -- leonerd@leonerd.org.uk |
From @jhi
Your analysis seems correct. |
From zefram@fysh.orgJarkko Hietaniemi via RT wrote:
OK, so that hunk should be reverted. Reviewing the rest of the commit, It introduces a similar bug into pp_truncate, in the branch that truncates There's another in pp_fttext, for the case where the file is identified All three of these fixes should be candidates for backporting to maint -zefram |
From @tonycozOn Mon Jun 06 23:02:48 2016, zefram@fysh.org wrote:
...
Does the attached address the problems you're describing. The test (surprisingly to me) also passes on Win32, though I had to push the limit to 2046 for it to fail there. Tony |
From @tonycoz0001-perl-128316-preserve-errno-from-failed-system-calls.patchFrom 3f6b66c14467c0f8c7459e32c576618155ca89f3 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Thu, 16 Jun 2016 14:08:18 +1000
Subject: (perl #128316) preserve errno from failed system calls
---
pp_sys.c | 4 ++--
t/io/socket.t | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/pp_sys.c b/pp_sys.c
index 33cba46..3bf2673 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2497,7 +2497,6 @@ PP(pp_socket)
TAINT_PROPER("socket");
fd = PerlSock_socket(domain, type, protocol);
if (fd < 0) {
- SETERRNO(EBADF,RMS_IFI);
RETPUSHUNDEF;
}
IoIFP(io) = PerlIO_fdopen(fd, "r"SOCKET_OPEN_MODE); /* stdio gets confused about sockets */
@@ -3531,8 +3530,9 @@ PP(pp_fttext)
}
PL_laststatval = PerlLIO_fstat(fd, &PL_statcache);
if (PL_laststatval < 0) {
+ dSAVE_ERRNO;
(void)PerlIO_close(fp);
- SETERRNO(EBADF,RMS_IFI);
+ RESTORE_ERRNO;
FT_RETURNUNDEF;
}
PerlIO_binmode(aTHX_ fp, '<', O_BINARY, NULL);
diff --git a/t/io/socket.t b/t/io/socket.t
index b51079a..54e4438 100644
--- a/t/io/socket.t
+++ b/t/io/socket.t
@@ -128,6 +128,28 @@ SKIP: {
}
}
+SKIP:
+{
+ eval { require Errno; defined &Errno::EMFILE }
+ or skip "Can't load Errno or EMFILE not defined", 1;
+ my @socks;
+ my $sock_limit = 1000; # don't consume every file in the system
+ # Default limits on various systems I have:
+ # 65536 - Linux
+ # 256 - Solaris
+ # 128 - NetBSD
+ # 256 - Cygwin
+ # 256 - darwin
+ while (@socks < $sock_limit) {
+ socket my $work, PF_INET, SOCK_STREAM, $tcp
+ or last;
+ push @socks, $work;
+ }
+ @socks == $sock_limit
+ and skip "Didn't run out of open handles", 1;
+ is(0+$!, Errno::EMFILE(), "check correct errno for too many files");
+}
+
done_testing();
my @child_tests;
--
2.1.4
|
From zefram@fysh.orgTony Cook via RT wrote:
Looks good. -zefram |
From zefram@fysh.orgThis was fixed by 3f6b66c. This ticket -zefram |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#128316 (status was 'resolved')
Searchable as RT128316$
The text was updated successfully, but these errors were encountered: