* sigproc.cc (getsem): Set errno when unable to create own semaphore.

Reorganize to make clearer that error should only come from initial creation of
process semaphore.
This commit is contained in:
Christopher Faylor 2002-01-07 16:47:12 +00:00
parent 10dedaaa4c
commit 4a08cbfefb
2 changed files with 17 additions and 10 deletions

View File

@ -1,3 +1,9 @@
2002-01-07 Christopher Faylor <cgf@redhat.com>
* sigproc.cc (getsem): Set errno when unable to create own semaphore.
Reorganize to make clearer that error should only come from initial
creation of process semaphore.
2002-01-06 Christopher Faylor <cgf@redhat.com> 2002-01-06 Christopher Faylor <cgf@redhat.com>
* dtable.cc (dtable::init_std_file_from_handle): Add some defensive * dtable.cc (dtable::init_std_file_from_handle): Add some defensive

View File

@ -926,6 +926,7 @@ getsem (_pinfo *p, const char *str, int init, int max)
return NULL; return NULL;
} }
int wait = 1000; int wait = 1000;
/* Wait for new process to generate its semaphores. */
sigproc_printf ("pid %d, ppid %d, wait %d, initializing %x", p->pid, p->ppid, wait, sigproc_printf ("pid %d, ppid %d, wait %d, initializing %x", p->pid, p->ppid, wait,
ISSTATE (p, PID_INITIALIZING)); ISSTATE (p, PID_INITIALIZING));
for (int i = 0; ISSTATE (p, PID_INITIALIZING) && i < wait; i++) for (int i = 0; ISSTATE (p, PID_INITIALIZING) && i < wait; i++)
@ -941,27 +942,27 @@ getsem (_pinfo *p, const char *str, int init, int max)
h = CreateSemaphore (allow_ntsec ? sec_user_nih (sa_buf) : &sec_none_nih, h = CreateSemaphore (allow_ntsec ? sec_user_nih (sa_buf) : &sec_none_nih,
init, max, str = shared_name (str, winpid)); init, max, str = shared_name (str, winpid));
p = myself; p = myself;
if (!h)
{
system_printf ("can't %s %s, %E", p ? "open" : "create", str);
__seterrno ();
}
} }
else else
{ {
h = OpenSemaphore (SEMAPHORE_ALL_ACCESS, FALSE, h = OpenSemaphore (SEMAPHORE_ALL_ACCESS, FALSE,
str = shared_name (str, p->dwProcessId)); shared_name (str, p->dwProcessId));
if (h == NULL) if (!h)
{ {
if (GetLastError () == ERROR_FILE_NOT_FOUND && !proc_exists (p)) if (GetLastError () == ERROR_FILE_NOT_FOUND && !proc_exists (p))
set_errno (ESRCH); set_errno (ESRCH); /* No such process */
else else
set_errno (EPERM); set_errno (EPERM); /* Couldn't access the semaphore --
return NULL; different cygwin DLL maybe? */
} }
} }
if (!h)
{
system_printf ("can't %s %s, %E", p ? "open" : "create", str);
set_errno (ESRCH);
}
return h; return h;
} }