[newlib-cygwin] Cygwin: processes: fix handling of native Windows processes
Corinna Vinschen
corinna@sourceware.org
Sat Feb 2 11:24:00 GMT 2019
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=448cf5aa4b429d5a9cebf92a0da4ab4b5b6d23fe
commit 448cf5aa4b429d5a9cebf92a0da4ab4b5b6d23fe
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Sat Feb 2 12:23:39 2019 +0100
Cygwin: processes: fix handling of native Windows processes
Since commit b5e1003722cb14235c4f166be72c09acdffc62ea, native
Windows processes not started by Cygwin processes don't have a
Cygwin PID anymore. This breaks ps -W and kill -f <WINPID>.
Introduce MAX_PID (65536 for now).
Cygwin processes as well as native Windows processes started
from a Cygwin process get a PID < MAX_PID. All other native
Windows processes get a faked Cygwin PID >= MAX_PID.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/external.cc | 12 ++++++++----
winsup/cygwin/pinfo.cc | 2 +-
winsup/cygwin/pinfo.h | 2 ++
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc
index 3a9130e..ae30695 100644
--- a/winsup/cygwin/external.cc
+++ b/winsup/cygwin/external.cc
@@ -63,19 +63,23 @@ fillout_pinfo (pid_t pid, int winpid)
_pinfo *p = pids[i];
i++;
+ /* Native Windows process not started from Cygwin have no procinfo
+ attached. They don't have a real Cygwin PID either. We fake a
+ Cygwin PID beyond MAX_PID. */
if (!p)
{
- if (!nextpid && thispid != (DWORD) pid)
+ if (!nextpid && thispid + MAX_PID != (DWORD) pid)
continue;
- ep.pid = cygwin_pid (thispid);
+ ep.pid = thispid + MAX_PID;
ep.dwProcessId = thispid;
ep.process_state = PID_IN_USE;
ep.ctty = -1;
break;
}
- else if (nextpid || p->pid == pid || (winpid && thispid == (DWORD) pid))
+ else if (nextpid || p->pid == pid)
{
- ep.ctty = (p->ctty < 0 || iscons_dev (p->ctty)) ? p->ctty : device::minor (p->ctty);
+ ep.ctty = (p->ctty < 0 || iscons_dev (p->ctty))
+ ? p->ctty : device::minor (p->ctty);
ep.pid = p->pid;
ep.ppid = p->ppid;
ep.dwProcessId = p->dwProcessId;
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 98168c7..c902577 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -241,7 +241,7 @@ create_cygwin_pid ()
do
{
pid = ((uint32_t) InterlockedIncrement (&cygwin_shared->pid_src))
- % 65536;
+ % MAX_PID;
}
while (pid < 2);
__small_swprintf (sym_name, L"cygpid.%u", pid);
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 81e10d3..a1e5afe 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -211,6 +211,8 @@ private:
DWORD status_exit (DWORD);
};
+#define MAX_PID 65536
+
#define ISSTATE(p, f) (!!((p)->process_state & f))
#define NOTSTATE(p, f) (!((p)->process_state & f))
More information about the Cygwin-cvs
mailing list