From d9c1b93d193f4bf5746393fb3770017716352600 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 22 Jun 2005 19:59:19 +0000 Subject: * fhandler.h (class fhandler_dev_tape): Add declaration for fixup_after_fork and set_close_on_exec. * fhandler_tape.cc (fhandler_dev_tape::open): Create mt_mtx mutex inheritable. (fhandler_dev_tape::close): Close mt_mtx. (fhandler_dev_tape::dup): Duplicate mt_mtx and mt_evt as necessary. (fhandler_dev_tape::fixup_after_fork): New method. (fhandler_dev_tape::set_close_on_exec): New method. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/fhandler.h | 2 ++ winsup/cygwin/fhandler_tape.cc | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index fef61697c..6f7c84021 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2005-06-22 Corinna Vinschen + + * fhandler.h (class fhandler_dev_tape): Add declaration for + fixup_after_fork and set_close_on_exec. + * fhandler_tape.cc (fhandler_dev_tape::open): Create mt_mtx mutex + inheritable. + (fhandler_dev_tape::close): Close mt_mtx. + (fhandler_dev_tape::dup): Duplicate mt_mtx and mt_evt as necessary. + (fhandler_dev_tape::fixup_after_fork): New method. + (fhandler_dev_tape::set_close_on_exec): New method. + 2005-06-21 Corinna Vinschen * security.cc (get_initgroups_sidlist): Drop special_pgrp parameter. diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index dcab4d52f..b3a478bea 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -636,6 +636,8 @@ class fhandler_dev_tape: public fhandler_dev_raw virtual int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2))); virtual int dup (fhandler_base *child); + virtual void fixup_after_fork (HANDLE parent); + virtual void set_close_on_exec (bool val); virtual int ioctl (unsigned int cmd, void *buf); }; diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc index c733a7d59..1c7f5aa9e 100644 --- a/winsup/cygwin/fhandler_tape.cc +++ b/winsup/cygwin/fhandler_tape.cc @@ -1218,7 +1218,7 @@ fhandler_dev_tape::open (int flags, mode_t) set_errno (ENOENT); return 0; } - if (!(mt_mtx = CreateMutex (&sec_all, FALSE, NULL))) + if (!(mt_mtx = CreateMutex (&sec_all, TRUE, NULL))) { __seterrno (); return 0; @@ -1256,6 +1256,7 @@ fhandler_dev_tape::close (void) ret = mt->drive (driveno ())->close (get_handle (), is_rewind_device ()); if (mt_evt) CloseHandle (mt_evt); + CloseHandle (mt_mtx); if (ret) __seterrno_from_win_error (ret); cret = fhandler_dev_raw::close (); @@ -1446,9 +1447,46 @@ int fhandler_dev_tape::dup (fhandler_base *child) { lock (-1); + fhandler_dev_tape *fh = (fhandler_dev_tape *) child; + if (!DuplicateHandle (hMainProc, mt_mtx, hMainProc, &fh->mt_mtx, 0, TRUE, + DUPLICATE_SAME_ACCESS)) + { + debug_printf ("dup(%s) failed, mutex handle %x, %E", + get_name (), mt_mtx); + __seterrno (); + return unlock (-1); + } + fh->mt_evt = NULL; + if (mt_evt && + !DuplicateHandle (hMainProc, mt_evt, hMainProc, &fh->mt_evt, 0, TRUE, + DUPLICATE_SAME_ACCESS)) + { + debug_printf ("dup(%s) failed, event handle %x, %E", + get_name (), mt_evt); + __seterrno (); + return unlock (-1); + } return unlock (fhandler_dev_raw::dup (child)); } +void +fhandler_dev_tape::fixup_after_fork (HANDLE parent) +{ + fhandler_dev_raw::fixup_after_fork (parent); + fork_fixup (parent, mt_mtx, "mt_mtx"); + if (mt_evt) + fork_fixup (parent, mt_evt, "mt_evt"); +} + +void +fhandler_dev_tape::set_close_on_exec (bool val) +{ + fhandler_dev_raw::set_close_on_exec (val); + set_no_inheritance (mt_mtx, val); + if (mt_evt) + set_no_inheritance (mt_evt, val); +} + int fhandler_dev_tape::ioctl (unsigned int cmd, void *buf) { -- cgit v1.2.3