summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2019-02-09 15:36:02 +0100
committerCorinna Vinschen <corinna@vinschen.de>2019-02-09 15:36:02 +0100
commit0be0b8f0335ec0fad6188b3570dffeba4ec94fea (patch)
tree072c575435d3825941dbdd10b45c0b542fcd62f2
parent7816cf363689a65f6618a57a8190cea0e97efa40 (diff)
downloadcygnal-0be0b8f0335ec0fad6188b3570dffeba4ec94fea.tar.gz
cygnal-0be0b8f0335ec0fad6188b3570dffeba4ec94fea.tar.bz2
cygnal-0be0b8f0335ec0fad6188b3570dffeba4ec94fea.zip
Cygwin: execve: fix setting O_APPEND file offset for native child
dtable::set_file_pointers_for_exec is called from child_info_spawn::worker to move the file position of O_APPEND files to EOF if the child is a native child. However, this only works correctly for the first O_APPEND file descriptor: - set_file_pointers_for_exec calls SetFilePointer. The higher 4 bytes of the desired file offset are given to SetFilePointer as pointer to a DWORD value. On return, SetFilePointer returns the higher 4 bytes of the new file position in this DWORD. - So for the second and subsequent descriptors the higher 4 byte of the file position depend on what the actual file position of the previous file has been set to: - If the file is > 2 Gigs, the high offset will not be 0 anymore. - If the desciptor points to a non-seekable file (i.e., a pipe or socket), SetFilePosition returns an error and sets the high position to -1. Fix this by calling SetFilePointerEx instead, which does not modify the incoming position value. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--winsup/cygwin/dtable.cc5
-rw-r--r--winsup/cygwin/release/3.03
2 files changed, 6 insertions, 2 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 663f99b34..86e0c716d 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -857,12 +857,13 @@ dtable::set_file_pointers_for_exec ()
{
/* This is not POSIX-compliant so the function is only called for
non-Cygwin processes. */
- LONG off_high = 0;
+ LARGE_INTEGER eof = { QuadPart: 0 };
+
lock ();
fhandler_base *fh;
for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL && fh->get_flags () & O_APPEND)
- SetFilePointer (fh->get_handle (), 0, &off_high, FILE_END);
+ SetFilePointerEx (fh->get_handle (), eof, NULL, FILE_END);
unlock ();
}
diff --git a/winsup/cygwin/release/3.0 b/winsup/cygwin/release/3.0
index 4cd422a56..da0fe0961 100644
--- a/winsup/cygwin/release/3.0
+++ b/winsup/cygwin/release/3.0
@@ -100,3 +100,6 @@ Bug Fixes
- Fix exception handling in pthreads.
Addresses: https://cygwin.com/ml/cygwin/2019-01/msg00149.html
+
+- Fix O_APPEND handling on files when calling non-Cygwin applications
+ Addresses: https://cygwin.com/ml/cygwin/2019-02/msg00081.html