Cygwin: winpids: Fix getting process multiple times, take 2

commit d1be0a59d4,
"Cygwin: winpids: Fix getting process multiple times"
fixed duplicate processes in ps -W output, but it fixed
the symptom, not the cause.  It also didn't fix the problem
that the `ps' process itself may show up twice in its own
output.

This patch fixes it.  The spawn worker only deleted the
"winpid.PID" symlink of the current process if the child is
a non-Cygwin process, under the assumption that the exec'ing
process exits anyway.  However, the Window in which both
winpid.PID symlinks point to the same cygpid.PID area is just
too long.  The spawn worker now also deletes its own winpid.PID
symlink if the exec'ed process is a Cygwin process.

Additionally the fix from d1be0a59d4
is now performed on the calling process, too.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2019-04-02 13:00:22 +02:00
parent 4fb8d091f2
commit b9009a5880
3 changed files with 21 additions and 8 deletions

View File

@ -1443,10 +1443,10 @@ winpids::add (DWORD& nelem, bool winpid, DWORD pid)
perform_copy = onreturn ? make_copy : true;
p.init (cygpid, PID_PROCINFO | pinfo_access, NULL);
/* Did we catch the process during exec? Try to fix. */
if (p && p->dwProcessId != pid)
pid = p->dwProcessId;
}
/* Did we catch the process during exec? Try to fix. */
if (p && p->dwProcessId != pid)
pid = p->dwProcessId;
/* If we're just looking for winpids then don't do any special cygwin "stuff* */
if (winpid)

View File

@ -0,0 +1,14 @@
What's new:
-----------
What changed:
-------------
Bug Fixes
---------
- Fix the problem that `ps' or `pstree' may show up in their own
output twice.
Addresses: Report on IRC

View File

@ -727,16 +727,15 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
myself->dwProcessId = pi.dwProcessId;
strace.execing = 1;
myself.hProcess = hExeced = pi.hProcess;
HANDLE old_winpid_hdl = myself.shared_winpid_handle ();
if (!real_path.iscygexec ())
{
/* If the child process is not a Cygwin process, we have to
create a new winpid symlink and drop the old one on
behalf of the child process not being able to do this
by itself. */
HANDLE old_winpid_hdl = myself.shared_winpid_handle ();
create a new winpid symlink on behalf of the child process
not being able to do this by itself. */
myself.create_winpid_symlink ();
NtClose (old_winpid_hdl);
}
NtClose (old_winpid_hdl);
real_path.get_wide_win32_path (myself->progname); // FIXME: race?
sigproc_printf ("new process name %W", myself->progname);
if (!iscygwin ())