* pinfo.h (pinfo::init): Make third parameter non-optional and propagate change

throughout.
* pinfo.cc (set_myself): Pass INVALID_HANDLE_POINTER if h is NULL.
(pinfo::init): Make third parameter non-optional.  Eliminate use of PID_EXECED
as an argument.  Put setting of handle back inside loop but reorganize to try
to open it only when necessary.
This commit is contained in:
Christopher Faylor 2005-01-26 00:15:11 +00:00
parent 72c1491bba
commit 0e32d1ffcd
4 changed files with 73 additions and 62 deletions

View File

@ -1,3 +1,12 @@
2005-01-25 Christopher Faylor <cgf@timesys.com>
* pinfo.h (pinfo::init): Make third parameter non-optional and
propagate change throughout.
* pinfo.cc (set_myself): Pass INVALID_HANDLE_POINTER if h is NULL.
(pinfo::init): Make third parameter non-optional. Eliminate use of
PID_EXECED as an argument. Put setting of handle back inside loop but
reorganize to try to open it only when necessary.
2005-01-25 Corinna Vinschen <corinna@vinschen.de> 2005-01-25 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export getpriority and setpriority. * cygwin.din: Export getpriority and setpriority.

View File

@ -49,7 +49,7 @@ set_myself (HANDLE h)
{ {
if (!h) if (!h)
cygheap->pid = cygwin_pid (GetCurrentProcessId ()); cygheap->pid = cygwin_pid (GetCurrentProcessId ());
myself.init (cygheap->pid, PID_IN_USE | PID_MYSELF, h); myself.init (cygheap->pid, PID_IN_USE, h ?: INVALID_HANDLE_VALUE);
myself->process_state |= PID_IN_USE; myself->process_state |= PID_IN_USE;
myself->dwProcessId = GetCurrentProcessId (); myself->dwProcessId = GetCurrentProcessId ();
@ -62,7 +62,7 @@ set_myself (HANDLE h)
{ {
/* here if execed */ /* here if execed */
static pinfo NO_COPY myself_identity; static pinfo NO_COPY myself_identity;
myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED); myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED, NULL);
myself->start_time = time (NULL); /* Register our starting time. */ myself->start_time = time (NULL); /* Register our starting time. */
myself->exec_sendsig = NULL; myself->exec_sendsig = NULL;
myself->exec_dwProcessId = 0; myself->exec_dwProcessId = 0;
@ -169,74 +169,71 @@ pinfo::exit (DWORD n)
void void
pinfo::init (pid_t n, DWORD flag, HANDLE h0) pinfo::init (pid_t n, DWORD flag, HANDLE h0)
{ {
h = NULL;
if (myself && n == myself->pid) if (myself && n == myself->pid)
{ {
procinfo = myself; procinfo = myself;
destroy = 0; destroy = 0;
h = NULL;
return; return;
} }
h = NULL;
procinfo = NULL;
void *mapaddr; void *mapaddr;
if (!(flag & PID_MYSELF)) bool createit = !!(flag & (PID_IN_USE | PID_EXECED));
bool created;
DWORD access = FILE_MAP_READ
| (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW)
? FILE_MAP_WRITE : 0);
if (!h0)
mapaddr = NULL; mapaddr = NULL;
else else
{ {
flag &= ~PID_MYSELF; /* Try to enforce that myself is always created in the same place */
HANDLE hdummy; mapaddr = open_shared (NULL, 0, h0, 0, SH_MYSELF);
mapaddr = open_shared (NULL, 0, hdummy, 0, SH_MYSELF); created = false;
if (h0 == INVALID_HANDLE_VALUE)
h0 = NULL;
} }
int createit = flag & (PID_IN_USE | PID_EXECED); procinfo = NULL;
DWORD access = FILE_MAP_READ
| (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW) ? FILE_MAP_WRITE : 0);
bool created;
if (h0)
created = 0;
else
{
char mapname[CYG_MAX_PATH];
shared_name (mapname, "cygpid", n);
int mapsize;
if (flag & PID_EXECED)
mapsize = PINFO_REDIR_SIZE;
else
mapsize = sizeof (_pinfo);
if (!createit)
{
h0 = OpenFileMapping (access, FALSE, mapname);
created = 0;
}
else
{
char sa_buf[1024];
PSECURITY_ATTRIBUTES sec_attribs =
sec_user_nih (sa_buf, cygheap->user.sid(), well_known_world_sid,
FILE_MAP_READ);
h0 = CreateFileMapping (INVALID_HANDLE_VALUE, sec_attribs,
PAGE_READWRITE, 0, mapsize, mapname);
created = GetLastError () != ERROR_ALREADY_EXISTS;
}
if (!h0)
{
if (createit)
__seterrno ();
return;
}
}
ProtectHandle1 (h0, pinfo_shared_handle);
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
if (!h0)
{
char mapname[CYG_MAX_PATH];
shared_name (mapname, "cygpid", n);
int mapsize;
if (flag & PID_EXECED)
mapsize = PINFO_REDIR_SIZE;
else
mapsize = sizeof (_pinfo);
if (!createit)
{
h0 = OpenFileMapping (access, FALSE, mapname);
created = false;
}
else
{
char sa_buf[1024];
PSECURITY_ATTRIBUTES sec_attribs =
sec_user_nih (sa_buf, cygheap->user.sid(), well_known_world_sid,
FILE_MAP_READ);
h0 = CreateFileMapping (INVALID_HANDLE_VALUE, sec_attribs,
PAGE_READWRITE, 0, mapsize, mapname);
created = GetLastError () != ERROR_ALREADY_EXISTS;
}
if (!h0)
{
if (createit)
__seterrno ();
return;
}
}
procinfo = (_pinfo *) MapViewOfFileEx (h0, access, 0, 0, 0, mapaddr); procinfo = (_pinfo *) MapViewOfFileEx (h0, access, 0, 0, 0, mapaddr);
if (!procinfo) if (!procinfo)
{ {
if (exit_state) if (exit_state)
@ -263,13 +260,15 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid); debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid);
if (realpid == n) if (realpid == n)
api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n); api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n);
n = realpid;
if ((flag & PID_ALLPIDS)) if ((flag & PID_ALLPIDS))
{ {
set_errno (ESRCH); set_errno (ESRCH);
break; break;
} }
n = realpid;
CloseHandle (h0);
h0 = NULL;
goto loop; goto loop;
} }
@ -299,7 +298,10 @@ pinfo::init (pid_t n, DWORD flag, HANDLE h0)
} }
if (h) if (h)
destroy = 1; {
destroy = 1;
ProtectHandle1 (h, pinfo_shared_handle);
}
else else
{ {
h = h0; h = h0;
@ -959,7 +961,7 @@ winpids::add (DWORD& nelem, bool winpid, DWORD pid)
} }
pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0) pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0)
| pinfo_access); | pinfo_access, NULL);
if (winpid) if (winpid)
goto out; goto out;
@ -967,7 +969,7 @@ winpids::add (DWORD& nelem, bool winpid, DWORD pid)
{ {
if (!pinfo_access) if (!pinfo_access)
return; return;
pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0)); pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0), NULL);
if (!pinfolist[nelem]) if (!pinfolist[nelem])
return; return;
} }

View File

@ -144,11 +144,11 @@ public:
bool waiter_ready; bool waiter_ready;
/* Handle associated with initial Windows pid which started it all. */ /* Handle associated with initial Windows pid which started it all. */
class cygthread *wait_thread; class cygthread *wait_thread;
void init (pid_t, DWORD, HANDLE = NULL) __attribute__ ((regparm(3))); void init (pid_t, DWORD, HANDLE) __attribute__ ((regparm(3)));
pinfo () {} pinfo () {}
pinfo (_pinfo *x): procinfo (x), hProcess (NULL) {} pinfo (_pinfo *x): procinfo (x), hProcess (NULL) {}
pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, 0);} pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, 0, NULL);}
pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, flag);} pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, flag, NULL);}
void release (); void release ();
int wait () __attribute__ ((regparm (1))); int wait () __attribute__ ((regparm (1)));
~pinfo () ~pinfo ()

View File

@ -73,7 +73,7 @@ static char *offsets[] =
}; };
void * __stdcall void * __stdcall
open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, open_shared (const char *name, int n, HANDLE& shared_h, DWORD size,
shared_locations m, PSECURITY_ATTRIBUTES psa) shared_locations m, PSECURITY_ATTRIBUTES psa)
{ {
void *shared; void *shared;