diff options
author | Christopher Faylor <me@cgf.cx> | 2004-06-07 04:26:32 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2004-06-07 04:26:32 +0000 |
commit | beffbc5efd36a3103c1c8b27202c9d97621f961b (patch) | |
tree | 38af781c06db587a1052db27b8cefef005a6f9d9 /winsup/cygwin/pinfo.cc | |
parent | 6a02213b528eaac0c0955ede85ca2e4867b96e46 (diff) | |
download | cygnal-beffbc5efd36a3103c1c8b27202c9d97621f961b.tar.gz cygnal-beffbc5efd36a3103c1c8b27202c9d97621f961b.tar.bz2 cygnal-beffbc5efd36a3103c1c8b27202c9d97621f961b.zip |
* dtable.cc (dtable::find_fifo): Release lock after fifo found (still racy).
* fhandler.h (fhandler_fifo::get_io_handle): New fifo-specific method.
* fhandler_fifo.cc (fhandler_fifo::close): Close output_handle only if it is
open.
(fhandler_fifo::open_not_mine): Reorganize slightly. Don't call _pinfo methods
when the fifo is owned by me or suffer dtable lock_cs deadlock.
(fhandler_fifo::open): Call open_not_mine first, otherwise open myself
(racy).
* pinfo.cc (_pinfo::commune_recv): Duplicate fifo handles here in requesting
processes arena to avoid one potential race (of many).
(_pinfo::commune_send): Move all PICOM_FIFO code under one case statement.
* thread.cc (pthread::init_mainthread) Use existing hMainProc handle rather
than calling GetCurrentProcess.
Diffstat (limited to 'winsup/cygwin/pinfo.cc')
-rw-r--r-- | winsup/cygwin/pinfo.cc | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 0ed74009f..79d4c60d4 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -351,11 +351,11 @@ _pinfo::commune_recv () return; } - CloseHandle (hp); hello_pid = 0; if (!ReadFile (__fromthem, &code, sizeof code, &nr, NULL) || nr != sizeof code) { + CloseHandle (hp); /* __seterrno ();*/ // this is run from the signal thread, so don't set errno goto out; } @@ -368,6 +368,8 @@ _pinfo::commune_recv () CloseHandle (__fromthem); __fromthem = NULL; extern int __argc_safe; const char *argv[__argc_safe + 1]; + + CloseHandle (hp); for (int i = 0; i < __argc_safe; i++) { if (IsBadStringPtr (__argv[i], INT32_MAX)) @@ -403,6 +405,7 @@ _pinfo::commune_recv () if (!ReadFile (__fromthem, &len, sizeof len, &nr, NULL) || nr != sizeof len) { + CloseHandle (hp); /* __seterrno ();*/ // this is run from the signal thread, so don't set errno goto out; } @@ -410,6 +413,7 @@ _pinfo::commune_recv () if (!ReadFile (__fromthem, path, len, &nr, NULL) || nr != len) { + CloseHandle (hp); /* __seterrno ();*/ // this is run from the signal thread, so don't set errno goto out; } @@ -422,8 +426,16 @@ _pinfo::commune_recv () { it[0] = fh->get_handle (); it[1] = fh->get_output_handle (); + for (int i = 0; i < 2; i++) + if (!DuplicateHandle (hMainProc, it[i], hp, &it[i], 0, false, + DUPLICATE_SAME_ACCESS)) + { + it[0] = it[1] = NULL; /* FIXME: possibly left a handle open in child? */ + break; + } } + CloseHandle (hp); if (!WriteFile (__tothem, it, sizeof (it), &nr, NULL)) { /*__seterrno ();*/ // this is run from the signal thread, so don't set errno @@ -442,7 +454,7 @@ out: CloseHandle (__tothem); } -#define PIPEBUFSIZE (16 * sizeof (DWORD)) +#define PIPEBUFSIZE (4096 * sizeof (DWORD)) commune_result _pinfo::commune_send (DWORD code, ...) @@ -485,21 +497,6 @@ _pinfo::commune_send (DWORD code, ...) goto err; } - switch (code) - { - case PICOM_FIFO: - { - char *path = va_arg (args, char *); - size_t len = strlen (path) + 1; - if (!WriteFile (tothem, path, len, &nr, NULL) || nr != len) - { - __seterrno (); - goto err; - } - break; - } - } - if (sig_send (this, __SIGCOMMUNE)) goto err; @@ -550,10 +547,25 @@ _pinfo::commune_send (DWORD code, ...) break; case PICOM_FIFO: { + char *path = va_arg (args, char *); + size_t len = strlen (path) + 1; + if (!WriteFile (tothem, &len, sizeof (len), &nr, NULL) + || nr != sizeof (len)) + { + __seterrno (); + goto err; + } + if (!WriteFile (tothem, path, len, &nr, NULL) || nr != len) + { + __seterrno (); + goto err; + } + DWORD x = ReadFile (fromthem, res.handles, sizeof (res.handles), &nr, NULL); - WriteFile (tothem, &x, sizeof (x), &x, NULL); + (void) WriteFile (tothem, &x, sizeof (x), &x, NULL); if (!x) goto err; + if (nr != sizeof (res.handles)) { set_errno (EPIPE); |