4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-19 04:49:25 +08:00

* pinfo.cc (winpids:add): New method.

(winpids::enumNT): New method renamed from EnumProcessesNT.  Use add method to
add elements to the lists.
(winpids::enum9x): New method renamed from EnumProcesses9x.  Use add method to
add elements to the lists.
(winpids::enum_init): Accept 'winpid' parameter to control whether to add all
windows pids to the list.
(winpids::release): New method.
* pinfo.h (winpids): Reflect above changes.
* signal.cc (kill_pgrp): Ditto.
* external.cc (fillout_pinfo): Ditto.
This commit is contained in:
Christopher Faylor 2000-11-05 06:42:23 +00:00
parent 7edb836a68
commit 0c9ae85d56
5 changed files with 101 additions and 46 deletions

View File

@ -1,3 +1,17 @@
Sun Nov 5 01:34:51 2000 Christopher Faylor <cgf@cygnus.com>
* pinfo.cc (winpids:add): New method.
(winpids::enumNT): New method renamed from EnumProcessesNT.
Use add method to add elements to the lists.
(winpids::enum9x): New method renamed from EnumProcesses9x.
Use add method to add elements to the lists.
(winpids::enum_init): Accept 'winpid' parameter to control whether
to add all windows pids to the list.
(winpids::release): New method.
* pinfo.h (winpids): Reflect above changes.
* signal.cc (kill_pgrp): Ditto.
* external.cc (fillout_pinfo): Ditto.
Sat Nov 4 22:07:03 2000 Christopher Faylor <cgf@cygnus.com> Sat Nov 4 22:07:03 2000 Christopher Faylor <cgf@cygnus.com>
* exceptions.cc (handle_sigsuspend): Record frame here for signalling. * exceptions.cc (handle_sigsuspend): Record frame here for signalling.

View File

@ -32,23 +32,22 @@ fillout_pinfo (pid_t pid, int winpid)
static winpids pids (0); static winpids pids (0);
if (!pids.npids || !nextpid) if (!pids.npids || !nextpid)
pids.init (); pids.init (winpid);
static unsigned int i = 0; static unsigned int i = 0;
if (!pid) if (!pid)
i = 0; i = 0;
memset (&ep, 0, sizeof ep); memset (&ep, 0, sizeof ep);
for (; i < pids.npids;) while (i < pids.npids)
{ {
DWORD thispid = pids[i++]; DWORD thispid = pids.winpid (i);
if (!thispid) _pinfo *p = pids[i];
continue; i++;
pinfo p (thispid, PID_NOREDIR);
if (!p) if (!p)
{ {
if (!winpid || (!nextpid && thispid != (DWORD) pid)) if (!nextpid && thispid != (DWORD) pid)
continue; continue;
ep.pid = thispid; ep.pid = thispid;
ep.dwProcessId = cygwin_pid (thispid); ep.dwProcessId = cygwin_pid (thispid);

View File

@ -282,7 +282,6 @@ cygwin_winpid_to_pid (int winpid)
#include <tlhelp32.h> #include <tlhelp32.h>
typedef DWORD (WINAPI * ENUMPROCESSES) (DWORD* &, DWORD &);
typedef HANDLE (WINAPI * CREATESNAPSHOT) (DWORD, DWORD); typedef HANDLE (WINAPI * CREATESNAPSHOT) (DWORD, DWORD);
typedef BOOL (WINAPI * PROCESSWALK) (HANDLE, LPPROCESSENTRY32); typedef BOOL (WINAPI * PROCESSWALK) (HANDLE, LPPROCESSENTRY32);
typedef BOOL (WINAPI * CLOSESNAPSHOT) (HANDLE); typedef BOOL (WINAPI * CLOSESNAPSHOT) (HANDLE);
@ -290,15 +289,43 @@ typedef BOOL (WINAPI * CLOSESNAPSHOT) (HANDLE);
static NO_COPY CREATESNAPSHOT myCreateToolhelp32Snapshot = NULL; static NO_COPY CREATESNAPSHOT myCreateToolhelp32Snapshot = NULL;
static NO_COPY PROCESSWALK myProcess32First = NULL; static NO_COPY PROCESSWALK myProcess32First = NULL;
static NO_COPY PROCESSWALK myProcess32Next = NULL; static NO_COPY PROCESSWALK myProcess32Next = NULL;
static DWORD WINAPI enum_init (DWORD* &, DWORD&);
static NO_COPY ENUMPROCESSES myEnumProcesses = enum_init;
#define slop_pidlist 200 #define slop_pidlist 200
#define size_pidlist(i) (sizeof (pidlist[0]) * ((i) + 1)) #define size_pidlist(i) (sizeof (pidlist[0]) * ((i) + 1))
#define size_pinfolist(i) (sizeof (pinfolist[0]) * ((i) + 1))
static DWORD WINAPI inline void
EnumProcessesNT (DWORD* &pidlist, DWORD &npidlist) winpids::add (DWORD& nelem, bool winpid, DWORD pid)
{
pid_t cygpid = cygwin_pid (pid);
if (nelem >= npidlist)
{
npidlist += slop_pidlist;
pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist));
pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist));
}
pinfolist[nelem].init (cygpid, PID_NOREDIR);
if (winpid)
/* nothing to do */;
else if (!pinfolist[nelem])
return;
else
/* Scan list of previously recorded pids to make sure that this pid hasn't
shown up before. This can happen when a process execs. */
for (unsigned i = 0; i < nelem; i++)
if (pinfolist[i]->pid == pinfolist[nelem]->pid )
{
if ((_pinfo *) pinfolist[nelem] != (_pinfo *) myself)
pinfolist[nelem].release ();
return;
}
pidlist[nelem++] = pid;
}
DWORD
winpids::enumNT (bool winpid)
{ {
static DWORD szprocs = 0; static DWORD szprocs = 0;
static SYSTEM_PROCESSES *procs; static SYSTEM_PROCESSES *procs;
@ -328,24 +355,17 @@ EnumProcessesNT (DWORD* &pidlist, DWORD &npidlist)
for (;;) for (;;)
{ {
if (px->ProcessId) if (px->ProcessId)
{ add (nelem, winpid, px->ProcessId);
if (nelem >= npidlist) if (!px->NextEntryDelta)
{ break;
npidlist += slop_pidlist;
pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist));
}
pidlist[nelem++] = cygwin_pid (px->ProcessId);
if (!px->NextEntryDelta)
break;
}
px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta); px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta);
} }
return nelem; return nelem;
} }
static DWORD WINAPI DWORD
EnumProcesses9x (DWORD* &pidlist, DWORD &npidlist) winpids::enum9x (bool winpid)
{ {
DWORD nelem = 0; DWORD nelem = 0;
@ -362,14 +382,8 @@ EnumProcesses9x (DWORD* &pidlist, DWORD &npidlist)
if (myProcess32First(h, &proc)) if (myProcess32First(h, &proc))
do do
{ {
if (!proc.th32ProcessID) if (proc.th32ProcessID)
continue; add (nelem, winpid, proc.th32ProcessID);
if (nelem >= npidlist)
{
npidlist += slop_pidlist;
pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist));
}
pidlist[nelem++] = cygwin_pid (proc.th32ProcessID);
} }
while (myProcess32Next (h, &proc)); while (myProcess32Next (h, &proc));
@ -378,18 +392,18 @@ EnumProcesses9x (DWORD* &pidlist, DWORD &npidlist)
} }
void void
winpids::init () winpids::init (bool winpid)
{ {
npids = myEnumProcesses (pidlist, npidlist); npids = (this->*enum_processes) (winpid);
pidlist[npids] = 0; pidlist[npids] = 0;
} }
static DWORD WINAPI DWORD
enum_init (DWORD* &pidlist, DWORD& npidlist) winpids::enum_init (bool winpid)
{ {
HINSTANCE h; HINSTANCE h;
if (os_being_run == winNT) if (os_being_run == winNT)
myEnumProcesses = EnumProcessesNT; enum_processes = &winpids::enumNT;
else else
{ {
h = GetModuleHandle("kernel32.dll"); h = GetModuleHandle("kernel32.dll");
@ -405,8 +419,26 @@ enum_init (DWORD* &pidlist, DWORD& npidlist)
return 0; return 0;
} }
myEnumProcesses = EnumProcesses9x; enum_processes = &winpids::enum9x;
} }
return myEnumProcesses (pidlist, npidlist); return (this->*enum_processes) (winpid);
}
void
winpids::release ()
{
for (unsigned i = 0; i < npids; i++)
if (pinfolist[i] && (_pinfo *) pinfolist[i] != (_pinfo *) myself)
pinfolist[i].release ();
}
winpids::~winpids ()
{
if (npidlist)
{
release ();
free (pidlist);
free (pinfolist);
}
} }

View File

@ -188,13 +188,23 @@ class winpids
{ {
DWORD *pidlist; DWORD *pidlist;
DWORD npidlist; DWORD npidlist;
pinfo *pinfolist;
DWORD (winpids::* enum_processes) (bool winpid);
DWORD enum_init (bool winpid);
DWORD enumNT (bool winpid);
DWORD enum9x (bool winpid);
void add (DWORD& nelem, bool, DWORD pid);
public: public:
DWORD npids; DWORD npids;
void reset () { npids = 0; } inline void reset () { npids = 0; release (); }
winpids (int) { reset (); } void init (bool winpid);
winpids (): pidlist (NULL), npidlist (0) { init (); }; winpids (int): enum_processes (&winpids::enum_init) { reset (); }
void init (); winpids (): pidlist (NULL), npidlist (0), pinfolist (NULL),
int operator [] (int i) const {return pidlist[i];} enum_processes (&winpids::enum_init), npids (0) { init (0); }
inline DWORD& winpid (int i) const {return pidlist[i];}
inline _pinfo *operator [] (int i) const {return (_pinfo *) pinfolist[i];}
~winpids ();
void release ();
}; };
extern __inline pid_t extern __inline pid_t

View File

@ -207,7 +207,7 @@ kill_pgrp (pid_t pid, int sig)
winpids pids; winpids pids;
for (unsigned i = 0; i < pids.npids; i++) for (unsigned i = 0; i < pids.npids; i++)
{ {
pinfo p (pids[i], PID_NOREDIR); _pinfo *p = pids[i];
if (!proc_exists (p)) if (!proc_exists (p))
continue; continue;