public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: winpids: Fix getting process multiple times, take 2
@ 2019-04-02 11:03 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2019-04-02 11:03 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=557227dda3ed6ce1c4cf104cc7671d56a141da38

commit 557227dda3ed6ce1c4cf104cc7671d56a141da38
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Apr 2 13:00:22 2019 +0200

    Cygwin: winpids: Fix getting process multiple times, take 2
    
    commit d1be0a59d48222d8ea6261ee3e59de2bc3d149e4,
    "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 d1be0a59d48222d8ea6261ee3e59de2bc3d149e4
    is now performed on the calling process, too.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/pinfo.cc      |  6 +++---
 winsup/cygwin/release/3.0.6 | 14 ++++++++++++++
 winsup/cygwin/spawn.cc      |  9 ++++-----
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index bead85b..d002268 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -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)
diff --git a/winsup/cygwin/release/3.0.6 b/winsup/cygwin/release/3.0.6
new file mode 100644
index 0000000..14a8329
--- /dev/null
+++ b/winsup/cygwin/release/3.0.6
@@ -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
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 4e549f7..579b3c9 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -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 ())


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-02 11:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-02 11:03 [newlib-cygwin] Cygwin: winpids: Fix getting process multiple times, take 2 Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).