|
|
276c98 |
From 3f6b66c14467c0f8c7459e32c576618155ca89f3 Mon Sep 17 00:00:00 2001
|
|
|
276c98 |
From: Tony Cook <tony@develop-help.com>
|
|
|
276c98 |
Date: Thu, 16 Jun 2016 14:08:18 +1000
|
|
|
276c98 |
Subject: [PATCH] (perl #128316) preserve errno from failed system calls
|
|
|
276c98 |
MIME-Version: 1.0
|
|
|
276c98 |
Content-Type: text/plain; charset=UTF-8
|
|
|
276c98 |
Content-Transfer-Encoding: 8bit
|
|
|
276c98 |
|
|
|
276c98 |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
276c98 |
---
|
|
|
276c98 |
pp_sys.c | 4 ++--
|
|
|
276c98 |
t/io/socket.t | 22 ++++++++++++++++++++++
|
|
|
276c98 |
2 files changed, 24 insertions(+), 2 deletions(-)
|
|
|
276c98 |
|
|
|
276c98 |
diff --git a/pp_sys.c b/pp_sys.c
|
|
|
276c98 |
index 33cba46..3bf2673 100644
|
|
|
276c98 |
--- a/pp_sys.c
|
|
|
276c98 |
+++ b/pp_sys.c
|
|
|
276c98 |
@@ -2497,7 +2497,6 @@ PP(pp_socket)
|
|
|
276c98 |
TAINT_PROPER("socket");
|
|
|
276c98 |
fd = PerlSock_socket(domain, type, protocol);
|
|
|
276c98 |
if (fd < 0) {
|
|
|
276c98 |
- SETERRNO(EBADF,RMS_IFI);
|
|
|
276c98 |
RETPUSHUNDEF;
|
|
|
276c98 |
}
|
|
|
276c98 |
IoIFP(io) = PerlIO_fdopen(fd, "r"SOCKET_OPEN_MODE); /* stdio gets confused about sockets */
|
|
|
276c98 |
@@ -3531,8 +3530,9 @@ PP(pp_fttext)
|
|
|
276c98 |
}
|
|
|
276c98 |
PL_laststatval = PerlLIO_fstat(fd, &PL_statcache);
|
|
|
276c98 |
if (PL_laststatval < 0) {
|
|
|
276c98 |
+ dSAVE_ERRNO;
|
|
|
276c98 |
(void)PerlIO_close(fp);
|
|
|
276c98 |
- SETERRNO(EBADF,RMS_IFI);
|
|
|
276c98 |
+ RESTORE_ERRNO;
|
|
|
276c98 |
FT_RETURNUNDEF;
|
|
|
276c98 |
}
|
|
|
276c98 |
PerlIO_binmode(aTHX_ fp, '<', O_BINARY, NULL);
|
|
|
276c98 |
diff --git a/t/io/socket.t b/t/io/socket.t
|
|
|
276c98 |
index b51079a..54e4438 100644
|
|
|
276c98 |
--- a/t/io/socket.t
|
|
|
276c98 |
+++ b/t/io/socket.t
|
|
|
276c98 |
@@ -128,6 +128,28 @@ SKIP: {
|
|
|
276c98 |
}
|
|
|
276c98 |
}
|
|
|
276c98 |
|
|
|
276c98 |
+SKIP:
|
|
|
276c98 |
+{
|
|
|
276c98 |
+ eval { require Errno; defined &Errno::EMFILE }
|
|
|
276c98 |
+ or skip "Can't load Errno or EMFILE not defined", 1;
|
|
|
276c98 |
+ my @socks;
|
|
|
276c98 |
+ my $sock_limit = 1000; # don't consume every file in the system
|
|
|
276c98 |
+ # Default limits on various systems I have:
|
|
|
276c98 |
+ # 65536 - Linux
|
|
|
276c98 |
+ # 256 - Solaris
|
|
|
276c98 |
+ # 128 - NetBSD
|
|
|
276c98 |
+ # 256 - Cygwin
|
|
|
276c98 |
+ # 256 - darwin
|
|
|
276c98 |
+ while (@socks < $sock_limit) {
|
|
|
276c98 |
+ socket my $work, PF_INET, SOCK_STREAM, $tcp
|
|
|
276c98 |
+ or last;
|
|
|
276c98 |
+ push @socks, $work;
|
|
|
276c98 |
+ }
|
|
|
276c98 |
+ @socks == $sock_limit
|
|
|
276c98 |
+ and skip "Didn't run out of open handles", 1;
|
|
|
276c98 |
+ is(0+$!, Errno::EMFILE(), "check correct errno for too many files");
|
|
|
276c98 |
+}
|
|
|
276c98 |
+
|
|
|
276c98 |
done_testing();
|
|
|
276c98 |
|
|
|
276c98 |
my @child_tests;
|
|
|
276c98 |
--
|
|
|
276c98 |
2.5.5
|
|
|
276c98 |
|