From c208ecd540c02773b0d25246e0fbaadcd416600a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 5 Jan 2019 21:49:16 +0100 Subject: [PATCH] Cygwin: fhandler_base::open: allow to reopen file from handle So far io_handle is NULL when calling fhandler_base::open to open or create a file. Add a check for io_handle to allow priming the fhandler with a HANDLE value so we can reopen a file from a HANDLE on file systems supporting it. This allows to open already deleted files for further action. This will be used by open("/proc/PID/fd/DESCRIPTOR") scenarios. Signed-off-by: Corinna Vinschen --- winsup/cygwin/fhandler.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index f7e34c746..01afdb29b 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -552,7 +552,12 @@ fhandler_base::open (int flags, mode_t mode) syscall_printf ("(%S, %y)", pc.get_nt_native_path (), flags); - pc.get_object_attr (attr, *sec_none_cloexec (flags)); + /* Allow to reopen from handle. This is utilized by + open ("/proc/PID/fd/DESCRIPTOR", ...); */ + if (get_handle ()) + pc.init_reopen_attr (attr, get_handle ()); + else + pc.get_object_attr (attr, *sec_none_cloexec (flags)); options = FILE_OPEN_FOR_BACKUP_INTENT; switch (query_open ())