[PATCH] cygwin: pread/pwrite: prevent EBADF error after fork()
Christian Franke
Christian.Franke@t-online.de
Tue Sep 24 10:09:04 GMT 2024
This addresses:
https://sourceware.org/pipermail/cygwin/2024-September/256468.html
--
Regards,
Christian
-------------- next part --------------
From a688e962eb493140010a75dc24b6b49b34b7d558 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Tue, 24 Sep 2024 11:56:43 +0200
Subject: [PATCH] cygwin: pread/pwrite: prevent EBADF error after fork()
If the parent process has already used pread() or pwrite(), these
functions fail with EBADF if used on the inherited fd. Ensure that
fix_after_fork() is called to invalidate the prw_handle. This issue
has been detected by 'stress-ng --pseek 1'.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
winsup/cygwin/fhandler/disk_file.cc | 3 +++
1 file changed, 3 insertions(+)
diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/disk_file.cc
index f4c21d3b7..2008fb61b 100644
--- a/winsup/cygwin/fhandler/disk_file.cc
+++ b/winsup/cygwin/fhandler/disk_file.cc
@@ -1803,6 +1803,9 @@ fhandler_disk_file::prw_open (bool write, void *aio)
return -1;
}
+ /* prw_handle is invalid after fork. */
+ need_fork_fixup (true);
+
/* record prw_handle's asyncness for subsequent pread/pwrite operations */
prw_handle_isasync = !!aio;
return 0;
--
2.45.1
More information about the Cygwin-patches
mailing list