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>
This commit is contained in:
Corinna Vinschen 2019-01-05 21:57:03 +01:00
parent 91b264c76c
commit c76468182b
2 changed files with 38 additions and 2 deletions

View File

@ -637,7 +637,7 @@ commune_process (void *arg)
} }
case PICOM_PIPE_FHANDLER: 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; int64_t unique_id = si._si_commune._si_pipe_unique_id;
unsigned int n = 0; unsigned int n = 0;
cygheap_fdenum cfd; cygheap_fdenum cfd;
@ -656,6 +656,26 @@ commune_process (void *arg)
sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E"); sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E");
break; 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: case PICOM_FD:
{ {
sigproc_printf ("processing PICOM_FD"); sigproc_printf ("processing PICOM_FD");
@ -741,6 +761,7 @@ _pinfo::commune_request (__uint32_t code, ...)
break; break;
case PICOM_FD: case PICOM_FD:
case PICOM_FILE_PATHCONV:
si._si_commune._si_fd = va_arg (args, int); si._si_commune._si_fd = va_arg (args, int);
break; break;
@ -773,6 +794,7 @@ _pinfo::commune_request (__uint32_t code, ...)
case PICOM_FDS: case PICOM_FDS:
case PICOM_FD: case PICOM_FD:
case PICOM_PIPE_FHANDLER: case PICOM_PIPE_FHANDLER:
case PICOM_FILE_PATHCONV:
if (!ReadPipeOverlapped (fromthem, &n, sizeof n, &nr, 1000L) if (!ReadPipeOverlapped (fromthem, &n, sizeof n, &nr, 1000L)
|| nr != sizeof n) || nr != sizeof n)
{ {
@ -829,6 +851,18 @@ _pinfo::pipe_fhandler (int64_t unique_id, size_t &n)
return (fhandler_pipe *) cr.s; 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 * char *
_pinfo::fd (int fd, size_t &n) _pinfo::fd (int fd, size_t &n)
{ {

View File

@ -27,7 +27,8 @@ enum picom
PICOM_FDS = 4, PICOM_FDS = 4,
PICOM_FD = 5, PICOM_FD = 5,
PICOM_PIPE_FHANDLER = 6, PICOM_PIPE_FHANDLER = 6,
PICOM_ENVIRON = 7 PICOM_FILE_PATHCONV = 7,
PICOM_ENVIRON = 8
}; };
#define EXITCODE_SET 0x8000000 #define EXITCODE_SET 0x8000000
@ -102,6 +103,7 @@ public:
commune_result commune_request (__uint32_t, ...); commune_result commune_request (__uint32_t, ...);
bool alive (); bool alive ();
fhandler_pipe *pipe_fhandler (int64_t, size_t &); fhandler_pipe *pipe_fhandler (int64_t, size_t &);
void *file_pathconv (int, size_t &);
char *fd (int fd, size_t &); char *fd (int fd, size_t &);
char *fds (size_t &); char *fds (size_t &);
char *root (size_t &); char *root (size_t &);