* fhandle.h (fhandler_pipe::create_guard): Revert change which eliminated
SECURITY_ATTRIBUTES argument. * pipe.cc (fhandler_pipe::open): Duplicate guard from other process and protect it appropriately. Eliminate unneeded writepipe_exists temporary variable. Set inheritance appropriately. (fhandler_pipe::set_close_on_exec): Revert change which eliminated handling guard inheritance. (fhandler_pipe::fixup_after_fork): Ditto. Use correct name of entity being checked by fork_fixup. (fhandler_pipe::fixup_after_exec): Don't bother with guard here. (fhandler_pipe::dup): Cosmetic changes and revert creation of writepipe_exists as noninheritable. (fhandler_pipe::create): Revert change which eliminated SECURITY_ATTRIBUTES argument. Revert change which always made writepipe_exists noninheritable.
This commit is contained in:
parent
9c9959a512
commit
8ae1d98d8e
|
@ -1,3 +1,21 @@
|
|||
2006-05-21 Christopher Faylor <cgf@timesys.com>
|
||||
|
||||
* fhandle.h (fhandler_pipe::create_guard): Revert change which
|
||||
eliminated SECURITY_ATTRIBUTES argument.
|
||||
* pipe.cc (fhandler_pipe::open): Duplicate guard from other process and
|
||||
protect it appropriately. Eliminate unneeded writepipe_exists
|
||||
temporary variable. Set inheritance appropriately.
|
||||
(fhandler_pipe::set_close_on_exec): Revert change which eliminated
|
||||
handling guard inheritance.
|
||||
(fhandler_pipe::fixup_after_fork): Ditto. Use correct name of entity
|
||||
being checked by fork_fixup.
|
||||
(fhandler_pipe::fixup_after_exec): Don't bother with guard here.
|
||||
(fhandler_pipe::dup): Cosmetic changes and revert creation of
|
||||
writepipe_exists as noninheritable.
|
||||
(fhandler_pipe::create): Revert change which eliminated
|
||||
SECURITY_ATTRIBUTES argument. Revert change which always made
|
||||
writepipe_exists noninheritable.
|
||||
|
||||
2006-05-21 Christopher Faylor <cgf@timesys.com>
|
||||
|
||||
* debug.cc (add_handle): Print handle value when collision detected.
|
||||
|
|
|
@ -513,9 +513,9 @@ public:
|
|||
void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
||||
int open (int flags, mode_t mode = 0);
|
||||
int close ();
|
||||
void create_guard ()
|
||||
void create_guard (SECURITY_ATTRIBUTES *sa)
|
||||
{
|
||||
guard = CreateMutex (&sec_none, FALSE, NULL);
|
||||
guard = CreateMutex (sa, FALSE, NULL);
|
||||
ProtectHandleINH (guard);
|
||||
}
|
||||
int dup (fhandler_base *child);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* pipe.cc: pipe for Cygwin.
|
||||
|
||||
Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2006 Red Hat, Inc.
|
||||
Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Hat, Inc.
|
||||
|
||||
This file is part of Cygwin.
|
||||
|
||||
|
@ -42,7 +42,7 @@ extern "C" int sscanf (const char *, const char *, ...);
|
|||
int
|
||||
fhandler_pipe::open (int flags, mode_t mode)
|
||||
{
|
||||
HANDLE proc, pipe_hdl, nio_hdl = NULL, nwrp_hdl = NULL;
|
||||
HANDLE proc, pipe_hdl, nio_hdl = NULL;
|
||||
fhandler_pipe *fh = NULL;
|
||||
size_t size;
|
||||
int pid, rwflags = (flags & O_ACCMODE);
|
||||
|
@ -93,25 +93,35 @@ fhandler_pipe::open (int flags, mode_t mode)
|
|||
set_errno (EACCES);
|
||||
goto out;
|
||||
}
|
||||
bool inh = !(flags & O_NOINHERIT);
|
||||
if (!DuplicateHandle (proc, pipe_hdl, hMainProc, &nio_hdl,
|
||||
0, false, DUPLICATE_SAME_ACCESS))
|
||||
0, inh, DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
__seterrno ();
|
||||
goto out;
|
||||
}
|
||||
if (fh->writepipe_exists
|
||||
&& !DuplicateHandle (proc, fh->writepipe_exists, hMainProc, &nwrp_hdl,
|
||||
0, false, DUPLICATE_SAME_ACCESS))
|
||||
if (!fh->guard)
|
||||
/* nothing to do */;
|
||||
else if (DuplicateHandle (proc, fh->guard, hMainProc, &guard,
|
||||
0, inh, DUPLICATE_SAME_ACCESS))
|
||||
ProtectHandle (guard);
|
||||
else
|
||||
{
|
||||
__seterrno ();
|
||||
goto out;
|
||||
}
|
||||
if (!fh->writepipe_exists)
|
||||
/* nothing to do */;
|
||||
else if (!DuplicateHandle (proc, fh->writepipe_exists,
|
||||
hMainProc, &writepipe_exists,
|
||||
0, inh, DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
__seterrno ();
|
||||
goto out;
|
||||
}
|
||||
if (fh->read_state)
|
||||
create_read_state (2);
|
||||
if (fh->guard)
|
||||
create_guard ();
|
||||
init (nio_hdl, fh->get_access (), mode & O_TEXT ?: O_BINARY);
|
||||
writepipe_exists = nwrp_hdl;
|
||||
if (flags & O_NOINHERIT)
|
||||
close_on_exec (true);
|
||||
uninterruptible_io (fh->uninterruptible_io ());
|
||||
|
@ -119,8 +129,10 @@ fhandler_pipe::open (int flags, mode_t mode)
|
|||
CloseHandle (proc);
|
||||
return 1;
|
||||
out:
|
||||
if (nwrp_hdl)
|
||||
CloseHandle (nwrp_hdl);
|
||||
if (writepipe_exists)
|
||||
CloseHandle (writepipe_exists);
|
||||
if (guard)
|
||||
CloseHandle (guard);
|
||||
if (nio_hdl)
|
||||
CloseHandle (nio_hdl);
|
||||
if (fh)
|
||||
|
@ -142,6 +154,8 @@ void
|
|||
fhandler_pipe::set_close_on_exec (bool val)
|
||||
{
|
||||
fhandler_base::set_close_on_exec (val);
|
||||
if (guard)
|
||||
set_no_inheritance (guard, val);
|
||||
if (writepipe_exists)
|
||||
set_no_inheritance (writepipe_exists, val);
|
||||
}
|
||||
|
@ -230,16 +244,16 @@ fhandler_pipe::fixup_after_exec ()
|
|||
{
|
||||
if (!close_on_exec ())
|
||||
fixup_in_child ();
|
||||
else if (guard)
|
||||
ForceCloseHandle (guard);
|
||||
}
|
||||
|
||||
void
|
||||
fhandler_pipe::fixup_after_fork (HANDLE parent)
|
||||
{
|
||||
fhandler_base::fixup_after_fork (parent);
|
||||
if (guard)
|
||||
fork_fixup (parent, guard, "guard");
|
||||
if (writepipe_exists)
|
||||
fork_fixup (parent, writepipe_exists, "guard");
|
||||
fork_fixup (parent, writepipe_exists, "writepipe_exists");
|
||||
fixup_in_child ();
|
||||
}
|
||||
|
||||
|
@ -253,8 +267,8 @@ fhandler_pipe::dup (fhandler_base *child)
|
|||
if (get_handle () && fhandler_base::dup (child))
|
||||
goto err;
|
||||
|
||||
if (guard == NULL)
|
||||
ftp->guard = NULL;
|
||||
if (!guard)
|
||||
/* nothing to do */;
|
||||
else if (DuplicateHandle (hMainProc, guard, hMainProc, &ftp->guard, 0, true,
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
ProtectHandle1 (ftp->guard, guard);
|
||||
|
@ -264,20 +278,20 @@ fhandler_pipe::dup (fhandler_base *child)
|
|||
goto err;
|
||||
}
|
||||
|
||||
if (writepipe_exists == NULL)
|
||||
ftp->writepipe_exists = NULL;
|
||||
if (!writepipe_exists)
|
||||
/* nothing to do */;
|
||||
else if (!DuplicateHandle (hMainProc, writepipe_exists, hMainProc,
|
||||
&ftp->writepipe_exists, 0, false,
|
||||
&ftp->writepipe_exists, 0, true,
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
{
|
||||
debug_printf ("couldn't duplicate writepipe_exists %p, %E", writepipe_exists);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (read_state == NULL)
|
||||
ftp->read_state = NULL;
|
||||
if (!read_state)
|
||||
/* nothing to do */;
|
||||
else if (DuplicateHandle (hMainProc, read_state, hMainProc,
|
||||
&ftp->read_state, 0, 0,
|
||||
&ftp->read_state, 0, false,
|
||||
DUPLICATE_SAME_ACCESS))
|
||||
ProtectHandle1 (ftp->read_state, read_state);
|
||||
else
|
||||
|
@ -439,13 +453,13 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode, bool fif
|
|||
fhs[0]->create_read_state (2);
|
||||
|
||||
res = 0;
|
||||
fhs[0]->create_guard ();
|
||||
fhs[0]->create_guard (sa);
|
||||
if (wincap.has_unreliable_pipes ())
|
||||
{
|
||||
char buf[80];
|
||||
int count = pipecount++; /* FIXME: Should this be InterlockedIncrement? */
|
||||
__small_sprintf (buf, pipeid_fmt, myself->pid, count);
|
||||
fhs[1]->writepipe_exists = CreateEvent (&sec_none_nih, TRUE, FALSE, buf);
|
||||
fhs[1]->writepipe_exists = CreateEvent (sa, TRUE, FALSE, buf);
|
||||
fhs[0]->orig_pid = myself->pid;
|
||||
fhs[0]->id = count;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue