summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_tty.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2006-06-03 07:17:53 +0000
committerChristopher Faylor <me@cgf.cx>2006-06-03 07:17:53 +0000
commitdaff15870e39ca7dd2936ab8e80a79b91f105931 (patch)
treeeaed001a6423056262c9142199cc37bfe4e9a134 /winsup/cygwin/fhandler_tty.cc
parent578e142a2be9dcca7f64c54e6ae8cecd01e6ac71 (diff)
downloadcygnal-daff15870e39ca7dd2936ab8e80a79b91f105931.tar.gz
cygnal-daff15870e39ca7dd2936ab8e80a79b91f105931.tar.bz2
cygnal-daff15870e39ca7dd2936ab8e80a79b91f105931.zip
* fhandler_tty.cc (fhandler_pty_master::close): Don't close handles if we don't
own them. (fhandler_pty_master::setup): Make sure that original handle is closed when changing inheritance. (fhandler_pty_master::fixup_after_fork): Set from_master/to_master to arch value always. (fhandler_pty_master::fixup_after_exec): Clear from_master/to_master when close_on_exec.
Diffstat (limited to 'winsup/cygwin/fhandler_tty.cc')
-rw-r--r--winsup/cygwin/fhandler_tty.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index bca148647..e006c4ced 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1170,10 +1170,18 @@ fhandler_pty_master::close ()
}
fhandler_tty_master *arch = (fhandler_tty_master *) archetype;
- if (!ForceCloseHandle (arch->from_master))
- termios_printf ("error closing from_master %p, %E", arch->from_master);
- if (!ForceCloseHandle (arch->to_master))
- termios_printf ("error closing from_master %p, %E", arch->to_master);
+ if (arch->dwProcessId != GetCurrentProcessId ())
+ termios_printf ("not closing from_master(%p)/to_master(%p) since we don't own them(%d)",
+ arch->from_master, arch->to_master, arch->dwProcessId);
+ else
+ {
+ termios_printf ("closing from_master(%p)/to_master(%p) since we own them(%d)",
+ arch->from_master, arch->to_master, arch->dwProcessId);
+ if (!ForceCloseHandle (arch->from_master))
+ termios_printf ("error closing from_master %p, %E", arch->from_master);
+ if (!ForceCloseHandle (arch->to_master))
+ termios_printf ("error closing from_master %p, %E", arch->to_master);
+ }
fhandler_tty_common::close ();
if (!hExeced && get_ttyp ()->master_pid == myself->pid)
@@ -1390,14 +1398,14 @@ fhandler_pty_master::setup (tty& t)
goto err;
if (!DuplicateHandle (hMainProc, from_master, hMainProc, &from_master, 0, false,
- DUPLICATE_SAME_ACCESS))
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
{
errstr = "non-inheritable from_master";
goto err;
}
if (!DuplicateHandle (hMainProc, to_master, hMainProc, &to_master, 0, false,
- DUPLICATE_SAME_ACCESS))
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
{
errstr = "non-inheritable to_master";
goto err;
@@ -1452,6 +1460,8 @@ fhandler_pty_master::fixup_after_fork (HANDLE parent)
}
arch->dwProcessId = wpid;
}
+ from_master = arch->from_master;
+ to_master = arch->to_master;
report_tty_counts (this, "inherited master", "");
}
@@ -1460,4 +1470,6 @@ fhandler_pty_master::fixup_after_exec ()
{
if (!close_on_exec ())
fixup_after_fork (spawn_info->parent);
+ else
+ from_master = to_master = NULL;
}