diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-09-28 19:22:25 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-09-28 19:22:25 +0000 |
commit | dcb091caaf9e00e840520141c1a74fb3f0eeb1d2 (patch) | |
tree | 483b37f8f41a0ce565559a2a5340f2fe5c3c9e57 /winsup/cygwin/pinfo.cc | |
parent | 1204c515fe00335920c5707cc136e9562fd7cf38 (diff) | |
download | cygnal-dcb091caaf9e00e840520141c1a74fb3f0eeb1d2.tar.gz cygnal-dcb091caaf9e00e840520141c1a74fb3f0eeb1d2.tar.bz2 cygnal-dcb091caaf9e00e840520141c1a74fb3f0eeb1d2.zip |
Revert erroneous checkin.
Diffstat (limited to 'winsup/cygwin/pinfo.cc')
-rw-r--r-- | winsup/cygwin/pinfo.cc | 159 |
1 files changed, 67 insertions, 92 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index ec0e22bf8..2dd727ba1 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -385,18 +385,39 @@ _pinfo::commune_recv () char path[CYG_MAX_PATH]; DWORD nr; DWORD code; + HANDLE hp; + HANDLE __fromthem = NULL; + HANDLE __tothem = NULL; - /* Don't remove. It's necessary to copy to local variables for process - synchronization. */ - HANDLE __fromthem = this->__fromthem; - HANDLE __tothem = this->__tothem; - HANDLE __them = this->__them; - HANDLE __gotit = this->__gotit; + hp = OpenProcess (PROCESS_DUP_HANDLE, false, dwProcessId); + if (!hp) + { + sigproc_printf ("couldn't open handle for pid %d(%u)", pid, dwProcessId); + hello_pid = -1; + return; + } + if (!DuplicateHandle (hp, fromthem, hMainProc, &__fromthem, 0, false, DUPLICATE_SAME_ACCESS)) + { + sigproc_printf ("couldn't duplicate fromthem, %E"); + CloseHandle (hp); + hello_pid = -1; + return; + } - SetEvent (__gotit); + if (!DuplicateHandle (hp, tothem, hMainProc, &__tothem, 0, false, DUPLICATE_SAME_ACCESS)) + { + sigproc_printf ("couldn't duplicate tothem, %E"); + CloseHandle (__fromthem); + CloseHandle (hp); + hello_pid = -1; + return; + } + + 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; } @@ -410,6 +431,7 @@ _pinfo::commune_recv () 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)) @@ -441,6 +463,7 @@ _pinfo::commune_recv () case PICOM_CWD: { CloseHandle (__fromthem); __fromthem = NULL; + CloseHandle (hp); unsigned int n = strlen (cygheap->cwd.get (path, 1, 1, CYG_MAX_PATH)) + 1; if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL)) @@ -452,6 +475,7 @@ _pinfo::commune_recv () case PICOM_ROOT: { CloseHandle (__fromthem); __fromthem = NULL; + CloseHandle (hp); unsigned int n; if (cygheap->root.exists ()) n = strlen (strcpy (path, cygheap->root.posix_path ())) + 1; @@ -466,6 +490,7 @@ _pinfo::commune_recv () case PICOM_FDS: { CloseHandle (__fromthem); __fromthem = NULL; + CloseHandle (hp); unsigned int n = 0; int fd; cygheap_fdenum cfd; @@ -490,9 +515,11 @@ _pinfo::commune_recv () || nr != sizeof hdl) { sigproc_printf ("ReadFile hdl failed, %E"); + CloseHandle (hp); goto out; } CloseHandle (__fromthem); __fromthem = NULL; + CloseHandle (hp); unsigned int n = 0; cygheap_fdenum cfd; while (cfd.next () >= 0) @@ -516,9 +543,11 @@ _pinfo::commune_recv () || nr != sizeof fd) { sigproc_printf ("ReadFile fd failed, %E"); + CloseHandle (hp); goto out; } CloseHandle (__fromthem); __fromthem = NULL; + CloseHandle (hp); unsigned int n = 0; cygheap_fdget cfd (fd); if (cfd < 0) @@ -537,6 +566,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; } @@ -544,6 +574,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; } @@ -557,7 +588,7 @@ _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], __them, &it[i], 0, false, + 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? */ @@ -567,6 +598,7 @@ _pinfo::commune_recv () fh->close_one_end (); /* FIXME: not quite right - need more handshaking */ } + CloseHandle (hp); if (!WriteFile (__tothem, it, sizeof (it), &nr, NULL)) { /*__seterrno ();*/ // this is run from the signal thread, so don't set errno @@ -579,10 +611,10 @@ _pinfo::commune_recv () } out: - CloseHandle (__fromthem); - CloseHandle (__tothem); - CloseHandle (__them); - CloseHandle (__gotit); + if (__fromthem) + CloseHandle (__fromthem); + if (__tothem) + CloseHandle (__tothem); } #define PIPEBUFSIZE (4096 * sizeof (DWORD)) @@ -631,49 +663,31 @@ _pinfo::commune_send (DWORD code, ...) if (sig_send (this, __SIGCOMMUNE)) goto err; - { - bool isalive = true; - HANDLE w4[2] = { myself->gotit, myself->them }; - /* FIXME: How long should we wait here? */ - switch (WaitForMultipleObjects (2, w4, false, INFINITE)) - { - case WAIT_OBJECT_0: - myself->hello_pid = 0; - break; - case WAIT_OBJECT_0 + 1: - isalive = false; - break; - default: - debug_printf ("WFMO failed with %E"); - myself->hello_pid = -1; - break; - } + /* FIXME: Need something better than an busy loop here */ + bool isalive; + for (int i = 0; (isalive = alive ()) && (i < 10000); i++) + if (myself->hello_pid <= 0) + break; + else + low_priority_sleep (0); - CloseHandle (tome); - tome = NULL; - CloseHandle (fromme); - fromme = NULL; - CloseHandle (myself->them); - myself->them = NULL; - CloseHandle (myself->gotit); - myself->gotit = NULL; - myself->__tothem = NULL; - myself->__fromthem = NULL; - myself->__them = NULL; - myself->__gotit = NULL; - - if (!isalive) - { - set_errno (ESRCH); - goto err; - } + CloseHandle (tome); + tome = NULL; + CloseHandle (fromme); + fromme = NULL; + + if (!isalive) + { + set_errno (ESRCH); + goto err; + } + + if (myself->hello_pid < 0) + { + set_errno (ENOSYS); + goto err; + } - if (myself->hello_pid < 0) - { - set_errno (ENOSYS); - goto err; - } - } size_t n; switch (code) { @@ -771,7 +785,6 @@ err: out: myself->hello_pid = 0; - tothem = fromthem = NULL; myself.unlock (); return res; } @@ -913,44 +926,6 @@ _pinfo::cmdline (size_t& n) return s; } -bool -_pinfo::send_descriptors (int cnt, int *fds) -{ - HANDLE target_proc; - HANDLE my_proc; - - /* First try to create a handle of this process into the space of the - target process which allows the target process to duplicate handles. - If this fails, the target process will try the same. */ - for (int i = 0; i < cnt; ++i) - { - cygheap_fdget cfd (fds[i]); - if (cfd < 0) - { - set_errno (ENOENT); - goto fault; - } - - } - return true; - -fault: - destroy_inflight_descriptors (); - return false; -} - -void -_pinfo::destroy_inflight_descriptors () -{ -} - -#if 0 -bool -_pinfo::recv_descriptors () -{ -} -#endif - /* This is the workhorse which waits for the write end of the pipe created during new process creation. If the pipe is closed or a zero is received on the pipe, it is assumed that the cygwin pid has exited. |