[newlib-cygwin] Cygwin: pinfo: add method to send a serialized path_conv and HANDLE
Corinna Vinschen
corinna@sourceware.org
Sun Jan 6 19:42:00 GMT 2019
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c76468182b18272f3e40295e85186fda3d225c66
commit c76468182b18272f3e40295e85186fda3d225c66
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Sat Jan 5 21:57:03 2019 +0100
Cygwin: pinfo: add method to send a serialized path_conv and HANDLE
To allow reopening a file open in another process by HANDLE, introduce
a matching file_pathconv method, taking a file descriptor as parameter.
The result is a serialized path_conv and a HANDLE value. The HANDLE is
valid in the foreign process and MUST be duplicated into the target
process before usage.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/pinfo.cc | 36 +++++++++++++++++++++++++++++++++++-
winsup/cygwin/pinfo.h | 4 +++-
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 6b6986c..00b3ed6 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -637,7 +637,7 @@ commune_process (void *arg)
}
case PICOM_PIPE_FHANDLER:
{
- sigproc_printf ("processing PICOM_FDS");
+ sigproc_printf ("processing PICOM_PIPE_FHANDLER");
int64_t unique_id = si._si_commune._si_pipe_unique_id;
unsigned int n = 0;
cygheap_fdenum cfd;
@@ -656,6 +656,26 @@ commune_process (void *arg)
sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E");
break;
}
+ case PICOM_FILE_PATHCONV:
+ {
+ sigproc_printf ("processing PICOM_FILE_PATHCONV");
+ int fd = si._si_commune._si_fd;
+ unsigned int n = 0;
+ cygheap_fdget cfd (fd);
+ if (cfd >= 0)
+ {
+ fhandler_base *fh = cfd;
+ void *ser_buf = fh->pc.serialize (fh->get_handle (), n);
+ if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
+ sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E");
+ else if (!WritePipeOverlapped (tothem, ser_buf, n, &nr, 1000L))
+ sigproc_printf ("WritePipeOverlapped hdl failed, %E");
+ cfree (ser_buf);
+ }
+ else if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
+ sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E");
+ break;
+ }
case PICOM_FD:
{
sigproc_printf ("processing PICOM_FD");
@@ -741,6 +761,7 @@ _pinfo::commune_request (__uint32_t code, ...)
break;
case PICOM_FD:
+ case PICOM_FILE_PATHCONV:
si._si_commune._si_fd = va_arg (args, int);
break;
@@ -773,6 +794,7 @@ _pinfo::commune_request (__uint32_t code, ...)
case PICOM_FDS:
case PICOM_FD:
case PICOM_PIPE_FHANDLER:
+ case PICOM_FILE_PATHCONV:
if (!ReadPipeOverlapped (fromthem, &n, sizeof n, &nr, 1000L)
|| nr != sizeof n)
{
@@ -829,6 +851,18 @@ _pinfo::pipe_fhandler (int64_t unique_id, size_t &n)
return (fhandler_pipe *) cr.s;
}
+void *
+_pinfo::file_pathconv (int fd, size_t &n)
+{
+ if (!pid)
+ return NULL;
+ if (pid == myself->pid)
+ return NULL;
+ commune_result cr = commune_request (PICOM_FILE_PATHCONV, fd);
+ n = cr.n;
+ return (void *) cr.s;
+}
+
char *
_pinfo::fd (int fd, size_t &n)
{
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index aedb3d4..8eb3c43 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -27,7 +27,8 @@ enum picom
PICOM_FDS = 4,
PICOM_FD = 5,
PICOM_PIPE_FHANDLER = 6,
- PICOM_ENVIRON = 7
+ PICOM_FILE_PATHCONV = 7,
+ PICOM_ENVIRON = 8
};
#define EXITCODE_SET 0x8000000
@@ -102,6 +103,7 @@ public:
commune_result commune_request (__uint32_t, ...);
bool alive ();
fhandler_pipe *pipe_fhandler (int64_t, size_t &);
+ void *file_pathconv (int, size_t &);
char *fd (int fd, size_t &);
char *fds (size_t &);
char *root (size_t &);
More information about the Cygwin-cvs
mailing list