diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2019-01-08 21:37:43 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2019-01-08 21:47:28 +0100 |
commit | ec36c59f1a9349e690849e393251623f5936408c (patch) | |
tree | fd8b12b24bdb4fb21a4600cdd0dd14d4e91fb30d | |
parent | 0c545f3264aaaac3d02d3ef785a2e2e9d77ed03f (diff) | |
download | cygnal-ec36c59f1a9349e690849e393251623f5936408c.tar.gz cygnal-ec36c59f1a9349e690849e393251623f5936408c.tar.bz2 cygnal-ec36c59f1a9349e690849e393251623f5936408c.zip |
Cygwin: open: workaround reopen file w/ delete disposition set
On pre-W10 systems there's no way to reopen a file by handle if
the delete disposition is set. We try to get around with
duplicating the handle.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r-- | winsup/cygwin/fhandler.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 9af08d735..9643373b0 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -693,6 +693,23 @@ fhandler_base::open (int flags, mode_t mode) status = NtCreateFile (&fh, access, &attr, &io, NULL, file_attributes, shared, create_disposition, options, p, plen); + /* Pre-W10, we can't open a file by handle with delete disposition + set, so we have to lie our ass off. */ + if (get_handle () && status == STATUS_DELETE_PENDING) + { + BOOL ret = DuplicateHandle (GetCurrentProcess (), get_handle (), + GetCurrentProcess (), &fh, + access, !(flags & O_CLOEXEC), 0); + if (!ret) + ret = DuplicateHandle (GetCurrentProcess (), get_handle (), + GetCurrentProcess (), &fh, + 0, !(flags & O_CLOEXEC), + DUPLICATE_SAME_ACCESS); + if (!ret) + debug_printf ("DuplicateHandle after STATUS_DELETE_PENDING, %E"); + else + status = STATUS_SUCCESS; + } if (!NT_SUCCESS (status)) { /* Trying to create a directory should return EISDIR, not ENOENT. */ |