b2938d
From 89341f87f9fc65c4d7133e497bb04586e86b8052 Mon Sep 17 00:00:00 2001
b2938d
From: Tony Cook <tony@develop-help.com>
b2938d
Date: Tue, 12 May 2020 10:29:17 +1000
b2938d
Subject: [PATCH 1/2] make $fh->error report errors from both input and output
b2938d
MIME-Version: 1.0
b2938d
Content-Type: text/plain; charset=UTF-8
b2938d
Content-Transfer-Encoding: 8bit
b2938d
b2938d
For character devices and sockets perl uses separate PerlIO objects
b2938d
for input and output so they can be buffered separately.
b2938d
b2938d
The IO::Handle::error() method only checked the input stream, so
b2938d
if a write error occurs error() would still returned false.
b2938d
b2938d
Change this so both the input and output streams are checked.
b2938d
b2938d
fixes #6799
b2938d
b2938d
Signed-off-by: Petr Písař <ppisar@redhat.com>
b2938d
---
b2938d
 dist/IO/IO.xs     | 12 ++++++++----
b2938d
 dist/IO/t/io_xs.t | 19 ++++++++++++++++++-
b2938d
 2 files changed, 26 insertions(+), 5 deletions(-)
b2938d
b2938d
diff --git a/dist/IO/IO.xs b/dist/IO/IO.xs
b2938d
index 68b7352c38..99d523d2c1 100644
b2938d
--- a/dist/IO/IO.xs
b2938d
+++ b/dist/IO/IO.xs
b2938d
@@ -389,13 +389,17 @@ ungetc(handle, c)
b2938d
 
b2938d
 int
b2938d
 ferror(handle)
b2938d
-	InputStream	handle
b2938d
+	SV *	handle
b2938d
+    PREINIT:
b2938d
+        IO *io = sv_2io(handle);
b2938d
+        InputStream in = IoIFP(io);
b2938d
+        OutputStream out = IoOFP(io);
b2938d
     CODE:
b2938d
-	if (handle)
b2938d
+	if (in)
b2938d
 #ifdef PerlIO
b2938d
-	    RETVAL = PerlIO_error(handle);
b2938d
+	    RETVAL = PerlIO_error(in) || (in != out && PerlIO_error(out));
b2938d
 #else
b2938d
-	    RETVAL = ferror(handle);
b2938d
+	    RETVAL = ferror(in) || (in != out && ferror(out));
b2938d
 #endif
b2938d
 	else {
b2938d
 	    RETVAL = -1;
b2938d
diff --git a/dist/IO/t/io_xs.t b/dist/IO/t/io_xs.t
b2938d
index 1e3c49a4a7..f890e92558 100644
b2938d
--- a/dist/IO/t/io_xs.t
b2938d
+++ b/dist/IO/t/io_xs.t
b2938d
@@ -11,7 +11,7 @@ BEGIN {
b2938d
     }
b2938d
 }
b2938d
 
b2938d
-use Test::More tests => 5;
b2938d
+use Test::More tests => 7;
b2938d
 use IO::File;
b2938d
 use IO::Seekable;
b2938d
 
b2938d
@@ -50,3 +50,20 @@ SKIP:
b2938d
     ok($fh->sync, "sync to a read only handle")
b2938d
 	or diag "sync(): ", $!;
b2938d
 }
b2938d
+
b2938d
+
b2938d
+SKIP: {
b2938d
+    # gh 6799
b2938d
+    #
b2938d
+    # This isn't really a Linux/BSD specific test, but /dev/full is (I
b2938d
+    # hope) reasonably well defined on these.  Patches welcome if your platform
b2938d
+    # also supports it (or something like it)
b2938d
+    skip "no /dev/full or not a /dev/full platform", 2
b2938d
+      unless $^O =~ /^(linux|netbsd|freebsd)$/ && -c "/dev/full";
b2938d
+    open my $fh, ">", "/dev/full"
b2938d
+      or skip "Could not open /dev/full: $!", 2;
b2938d
+    $fh->print("a" x 1024);
b2938d
+    ok(!$fh->flush, "should fail to flush");
b2938d
+    ok($fh->error, "stream should be in error");
b2938d
+    close $fh; # silently ignore the error
b2938d
+}
b2938d
-- 
b2938d
2.25.4
b2938d