diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-06-22 23:59:19 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-06-22 23:59:19 +0400 |
commit | d9c1b93d193f4bf5746393fb3770017716352600 (patch) | |
tree | a73c23e6ee36c0774f4c0ce41b3456e11d60398a /winsup/cygwin/fhandler_tape.cc | |
parent | 2a770b2a6f38678409b7f5cc1d56f786ba1e7bf3 (diff) |
* 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.
Diffstat (limited to 'winsup/cygwin/fhandler_tape.cc')
-rw-r--r-- | winsup/cygwin/fhandler_tape.cc | 40 |
1 files changed, 39 insertions, 1 deletions
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) { |