diff options
Diffstat (limited to 'winsup/cygwin/pinfo.cc')
-rw-r--r-- | winsup/cygwin/pinfo.cc | 78 |
1 files changed, 34 insertions, 44 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 6e66e47a1..4591feded 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -1,6 +1,6 @@ /* pinfo.cc: process table support - Copyright 1996, 1997, 1998, 2000, 2001 Red Hat, Inc. + Copyright 1996, 1997, 1998, 2000, 2001, 2002 Red Hat, Inc. This file is part of Cygwin. @@ -18,7 +18,6 @@ details. */ #include "path.h" #include "dtable.h" #include "cygerrno.h" -#include "sync.h" #include "sigproc.h" #include "pinfo.h" #include "cygwin_version.h" @@ -28,7 +27,7 @@ details. */ #include <ntdef.h> #include "ntdll.h" -static char NO_COPY pinfo_dummy[sizeof(pinfo)] = {0}; +static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0}; pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks @@ -62,33 +61,14 @@ set_myself (pid_t pid, HANDLE h) myself->process_state |= PID_IN_USE; myself->start_time = time (NULL); /* Register our starting time. */ - char buf[30]; - __small_sprintf (buf, "cYg%8x %x", _STRACE_INTERFACE_ACTIVATE_ADDR, - &strace.active); - OutputDebugString (buf); - - (void) GetModuleFileName (NULL, myself->progname, - sizeof(myself->progname)); - if (strace.active) - { - strace.prntf (1, NULL, "**********************************************"); - strace.prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid); - strace.prntf (1, NULL, "App version: %d.%d, api: %d.%d", - user_data->dll_major, user_data->dll_minor, - user_data->api_major, user_data->api_minor); - strace.prntf (1, NULL, "DLL version: %d.%d, api: %d.%d", - cygwin_version.dll_major, cygwin_version.dll_minor, - cygwin_version.api_major, cygwin_version.api_minor); - strace.prntf (1, NULL, "DLL build: %s", cygwin_version.dll_build_date); - strace.prntf (1, NULL, "OS version: Windows %s", wincap.osname ()); - strace.prntf (1, NULL, "**********************************************"); - } - + (void) GetModuleFileName (NULL, myself->progname, sizeof (myself->progname)); + if (!strace.active) + strace.hello (); return; } /* Initialize the process table entry for the current task. - This is not called for fork'd tasks, only exec'd ones. */ + This is not called for forked tasks, only execed ones. */ void __stdcall pinfo_init (char **envp, int envc) { @@ -106,7 +86,7 @@ pinfo_init (char **envp, int envc) myself->ppid = 1; myself->pgid = myself->sid = myself->pid; myself->ctty = -1; - myself->uid = USHRT_MAX; + myself->uid = ILLEGAL_UID; environ_init (NULL, 0); /* call after myself has been set up */ } @@ -117,14 +97,17 @@ pinfo_init (char **envp, int envc) void _pinfo::exit (UINT n, bool norecord) { - if (!norecord) - process_state = PID_EXITED; - - /* FIXME: There is a potential race between an execed process and its - parent here. I hated to add a mutex just for this, though. */ - struct rusage r; - fill_rusage (&r, hMainProc); - add_rusage (&rusage_self, &r); + if (this) + { + if (!norecord) + process_state = PID_EXITED; + + /* FIXME: There is a potential race between an execed process and its + parent here. I hated to add a mutex just for this, though. */ + struct rusage r; + fill_rusage (&r, hMainProc); + add_rusage (&rusage_self, &r); + } sigproc_printf ("Calling ExitProcess %d", n); ExitProcess (n); @@ -133,7 +116,7 @@ _pinfo::exit (UINT n, bool norecord) void pinfo::init (pid_t n, DWORD flag, HANDLE in_h) { - if (n == myself->pid) + if (myself && n == myself->pid) { procinfo = myself; destroy = 0; @@ -182,7 +165,8 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h) procinfo = (_pinfo *) MapViewOfFile (h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); ProtectHandle1 (h, pinfo_shared_handle); - if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)) + if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR) + && cygwin_pid (procinfo->dwProcessId) != procinfo->pid) { release (); set_errno (ENOENT); @@ -198,6 +182,11 @@ pinfo::init (pid_t n, DWORD flag, HANDLE in_h) api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n); n = realpid; release (); + if (flag & PID_ALLPIDS) + { + set_errno (ENOENT); + break; + } continue; } @@ -272,7 +261,7 @@ a cygwin pid.</para> extern "C" pid_t cygwin_winpid_to_pid (int winpid) { - pinfo p (winpid); + pinfo p (cygwin_pid (winpid)); if (p) return p->pid; @@ -293,11 +282,11 @@ winpids::add (DWORD& nelem, bool winpid, DWORD pid) if (nelem >= npidlist) { npidlist += slop_pidlist; - pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist)); - pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist)); + pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist + 1)); + pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist + 1)); } - pinfolist[nelem].init (cygpid, PID_NOREDIR); + pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0)); if (winpid) /* nothing to do */; else if (!pinfolist[nelem]) @@ -324,12 +313,12 @@ winpids::enumNT (bool winpid) DWORD nelem = 0; if (!szprocs) - procs = (SYSTEM_PROCESSES *) malloc (szprocs = 200 * sizeof (*procs)); + procs = (SYSTEM_PROCESSES *) malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs))); NTSTATUS res; for (;;) { - res = ZwQuerySystemInformation (SystemProcessesAndThreadsInformation, + res = NtQuerySystemInformation (SystemProcessesAndThreadsInformation, procs, szprocs, NULL); if (res == 0) break; @@ -387,7 +376,8 @@ void winpids::init (bool winpid) { npids = (this->*enum_processes) (winpid); - pidlist[npids] = 0; + if (pidlist) + pidlist[npids] = 0; } DWORD |