public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Ken Brown <kbrown@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: FIFO: honor the flags argument in dup Date: Fri, 8 May 2020 11:29:32 +0000 (GMT) [thread overview] Message-ID: <20200508112932.3E3E2396EC5C@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=624fda1e96adf3c4de745115d97fe254d4be53e8 commit 624fda1e96adf3c4de745115d97fe254d4be53e8 Author: Ken Brown <kbrown@cornell.edu> Date: Wed Mar 25 09:31:29 2020 -0400 Cygwin: FIFO: honor the flags argument in dup Also improve the error handling. Diff: --- winsup/cygwin/fhandler_fifo.cc | 60 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index 44919c19e..f61e2fe72 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -955,56 +955,62 @@ fhandler_fifo::fcntl (int cmd, intptr_t arg) int fhandler_fifo::dup (fhandler_base *child, int flags) { - int ret = -1; + int i = 0; fhandler_fifo *fhf = NULL; if (get_flags () & O_PATH) return fhandler_base::dup (child, flags); if (fhandler_base::dup (child, flags)) - goto out; + goto err; fhf = (fhandler_fifo *) child; if (!DuplicateHandle (GetCurrentProcess (), read_ready, GetCurrentProcess (), &fhf->read_ready, - 0, true, DUPLICATE_SAME_ACCESS)) + 0, !(flags & O_CLOEXEC), DUPLICATE_SAME_ACCESS)) { - fhf->close (); __seterrno (); - goto out; + goto err; } if (!DuplicateHandle (GetCurrentProcess (), write_ready, GetCurrentProcess (), &fhf->write_ready, - 0, true, DUPLICATE_SAME_ACCESS)) + 0, !(flags & O_CLOEXEC), DUPLICATE_SAME_ACCESS)) { - NtClose (fhf->read_ready); - fhf->close (); __seterrno (); - goto out; + goto err_close_read_ready; } - fifo_client_lock (); - for (int i = 0; i < nhandlers; i++) + if (reader) { - if (!DuplicateHandle (GetCurrentProcess (), fc_handler[i].h, - GetCurrentProcess (), - &fhf->fc_handler[i].h, - 0, true, DUPLICATE_SAME_ACCESS)) + fifo_client_lock (); + for (i = 0; i < nhandlers; i++) + { + if (!DuplicateHandle (GetCurrentProcess (), fc_handler[i].h, + GetCurrentProcess (), &fhf->fc_handler[i].h, + 0, !(flags & O_CLOEXEC), DUPLICATE_SAME_ACCESS)) + { + __seterrno (); + break; + } + } + if (i < nhandlers) { fifo_client_unlock (); - NtClose (fhf->read_ready); - NtClose (fhf->write_ready); - fhf->close (); - __seterrno (); - goto out; + goto err_close_handlers; } + fifo_client_unlock (); + if (!fhf->listen_client ()) + goto err_close_handlers; + fhf->init_fixup_before (); } - fifo_client_unlock (); - if (!reader || fhf->listen_client ()) - ret = 0; - if (reader) - fhf->init_fixup_before (); -out: - return ret; + return 0; +err_close_handlers: + for (int j = 0; j < i; j++) + fhf->fc_handler[j].close (); + NtClose (fhf->write_ready); +err_close_read_ready: + NtClose (fhf->read_ready); +err: + return -1; } void
reply other threads:[~2020-05-08 11:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200508112932.3E3E2396EC5C@sourceware.org \ --to=kbrown@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).