Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2006-05-22 01:02:52 +0400
committerChristopher Faylor <me@cgf.cx>2006-05-22 01:02:52 +0400
commit8ae1d98d8ee2a0e0813d32aa42f2e584f99d17bf (patch)
treec4a5ce842315220304ac821793a889011679490e /winsup
parent9c9959a5125dda20e76a4e4b36df9386a7b8740f (diff)
* 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.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog18
-rw-r--r--winsup/cygwin/fhandler.h10
-rw-r--r--winsup/cygwin/pipe.cc68
3 files changed, 64 insertions, 32 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 45566718c..d1481ee87 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,23 @@
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.
* dtable.cc (dtable::stdio_init): Cosmetic change.
* fhandler.h (fhandler_base::create_read_state): Protect handle.
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 2bd4bac5a..7fb5411a1 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -513,11 +513,11 @@ 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 ()
- {
- guard = CreateMutex (&sec_none, FALSE, NULL);
- ProtectHandleINH (guard);
- }
+ void create_guard (SECURITY_ATTRIBUTES *sa)
+ {
+ guard = CreateMutex (sa, FALSE, NULL);
+ ProtectHandleINH (guard);
+ }
int dup (fhandler_base *child);
int ioctl (unsigned int cmd, void *);
void fixup_in_child ();
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index f913fc1ec..b6bd0cf0c 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -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,10 +267,10 @@ 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))
+ DUPLICATE_SAME_ACCESS))
ProtectHandle1 (ftp->guard, guard);
else
{
@@ -264,21 +278,21 @@ 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,
- DUPLICATE_SAME_ACCESS))
+ &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;
}