diff options
Diffstat (limited to 'winsup/cygwin/pinfo.cc')
-rw-r--r-- | winsup/cygwin/pinfo.cc | 85 |
1 files changed, 71 insertions, 14 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 6c59860c6..884b994a3 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -12,9 +12,10 @@ details. */ #include <stdlib.h> #include <time.h> #include <limits.h> +#include <stdarg.h> #include "security.h" -#include "fhandler.h" #include "path.h" +#include "fhandler.h" #include "dtable.h" #include "cygerrno.h" #include "sigproc.h" @@ -28,6 +29,7 @@ details. */ #include "cygthread.h" #include "shared_info.h" #include "cygheap.h" +#include "fhandler.h" static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0}; @@ -318,11 +320,34 @@ _pinfo::commune_recv () sigproc_printf ("WriteFile arg %d failed, %E", a - argv); break; } - if (!WriteFile (__tothem, "", 1, &nr, NULL)) - { - sigproc_printf ("WriteFile null failed, %E"); - break; - } + if (!WriteFile (__tothem, "", 1, &nr, NULL)) + { + sigproc_printf ("WriteFile null failed, %E"); + break; + } + break; + } + case PICOM_FIFO: + { + int formic; + if (!ReadFile (__fromthem, &formic, sizeof formic, &nr, NULL) + || nr != sizeof formic) + { + /* __seterrno ();*/ // this is run from the signal thread, so don't set errno + goto out; + } + + fhandler_fifo *fh = cygheap->fdtab.find_fifo ((ATOM) formic); + HANDLE it[] = {(fh->get_handle ()), (fh->get_output_handle ())}; + + if (!WriteFile (__tothem, it, sizeof (it), &nr, NULL)) + { + /*__seterrno ();*/ // this is run from the signal thread, so don't set errno + sigproc_printf ("WriteFile read handle failed, %E"); + } + + (void) ReadFile (__fromthem, &nr, sizeof (nr), &nr, NULL); + break; } } @@ -336,12 +361,15 @@ out: #define PIPEBUFSIZE (16 * sizeof (DWORD)) commune_result -_pinfo::commune_send (DWORD code) +_pinfo::commune_send (DWORD code, ...) { HANDLE fromthem = NULL, tome = NULL; HANDLE fromme = NULL, tothem = NULL; DWORD nr; commune_result res; + va_list args; + + va_start (args, code); res.s = NULL; res.n = 0; @@ -373,6 +401,20 @@ _pinfo::commune_send (DWORD code) goto err; } + switch (code) + { + case PICOM_FIFO: + { + int formic = va_arg (args, int); + if (!WriteFile (tothem, &formic, sizeof formic, &nr, NULL) || nr != sizeof formic) + { + __seterrno (); + goto err; + } + break; + } + } + if (sig_send (this, __SIGCOMMUNE)) goto err; @@ -402,14 +444,14 @@ _pinfo::commune_send (DWORD code) } size_t n; - if (!ReadFile (fromthem, &n, sizeof n, &nr, NULL) || nr != sizeof n) - { - __seterrno (); - goto err; - } switch (code) { case PICOM_CMDLINE: + if (!ReadFile (fromthem, &n, sizeof n, &nr, NULL) || nr != sizeof n) + { + __seterrno (); + goto err; + } res.s = (char *) malloc (n); char *p; for (p = res.s; ReadFile (fromthem, p, n, &nr, NULL); p += nr) @@ -421,6 +463,19 @@ _pinfo::commune_send (DWORD code) } res.n = n; break; + case PICOM_FIFO: + { + DWORD x = ReadFile (fromthem, res.handles, sizeof (res.handles), &nr, NULL); + WriteFile (tothem, &x, sizeof (x), &x, NULL); + if (!x) + goto err; + if (nr != sizeof (res.handles)) + { + set_errno (EPIPE); + goto err; + } + break; + } } CloseHandle (tothem); CloseHandle (fromthem); @@ -435,7 +490,8 @@ err: CloseHandle (tothem); if (fromme) CloseHandle (fromme); - res.n = 0; + memset (&res, 0, sizeof (res)); + out: myself->hello_pid = 0; LeaveCriticalSection (&myself->lock); @@ -477,7 +533,8 @@ pinfo::release () if (h) { #ifdef DEBUGGING - if (((DWORD) procinfo & 0x77000000) == 0x61000000) try_to_debug (); + if (((DWORD) procinfo & 0x77000000) == 0x61000000) + try_to_debug (); #endif UnmapViewOfFile (procinfo); procinfo = NULL; |