public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: POSIX msg queues: Implement dup
Date: Tue, 25 May 2021 14:56:35 +0000 (GMT)	[thread overview]
Message-ID: <20210525145635.920F63938C3B@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fbcd61063b10ab053c4067095383b535c5d3c125

commit fbcd61063b10ab053c4067095383b535c5d3c125
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue May 25 16:50:16 2021 +0200

    Cygwin: POSIX msg queues: Implement dup
    
    Create a private method fhandler_mqueue::_dup and call it from
    dup and fixup_after_fork methods.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler.h         |  2 ++
 winsup/cygwin/fhandler_mqueue.cc | 44 ++++++++++++++++++++++++----------------
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 4c8fe0f1f..ff51d29a5 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -3113,6 +3113,8 @@ class fhandler_mqueue: public fhandler_disk_file
   struct mq_info *mqinfo_open (int);
   void mq_open_finish (bool success, bool created);
 
+  int _dup (HANDLE parent, fhandler_mqueue *child);
+
 public:
   fhandler_mqueue ();
   fhandler_mqueue (void *) {}
diff --git a/winsup/cygwin/fhandler_mqueue.cc b/winsup/cygwin/fhandler_mqueue.cc
index 6b0d98d75..9114d8f32 100644
--- a/winsup/cygwin/fhandler_mqueue.cc
+++ b/winsup/cygwin/fhandler_mqueue.cc
@@ -353,15 +353,7 @@ fhandler_mqueue::fstat (struct stat *buf)
 }
 
 int
-fhandler_mqueue::dup (fhandler_base *child, int flags)
-{
-  /* FIXME */
-  set_errno (EBADF);
-  return -1;
-}
-
-void
-fhandler_mqueue::fixup_after_fork (HANDLE parent)
+fhandler_mqueue::_dup (HANDLE parent, fhandler_mqueue *fhc)
 {
   __try
     {
@@ -370,7 +362,7 @@ fhandler_mqueue::fixup_after_fork (HANDLE parent)
       NTSTATUS status;
 
       if (!DuplicateHandle (parent, mqinfo ()->mqi_sect,
-			    GetCurrentProcess (), &mqinfo ()->mqi_sect,
+			    GetCurrentProcess (), &fhc->mqinfo ()->mqi_sect,
 			    0, FALSE, DUPLICATE_SAME_ACCESS))
 	__leave;
       status = NtMapViewOfSection (mqinfo ()->mqi_sect, NtCurrentProcess (),
@@ -380,31 +372,47 @@ fhandler_mqueue::fixup_after_fork (HANDLE parent)
 	api_fatal ("Mapping message queue failed in fork, status 0x%x\n",
 		   status);
 
-      mqinfo ()->mqi_hdr = (struct mq_hdr *) mptr;
+      fhc->mqinfo ()->mqi_hdr = (struct mq_hdr *) mptr;
       if (!DuplicateHandle (parent, mqinfo ()->mqi_waitsend,
-			    GetCurrentProcess (), &mqinfo ()->mqi_waitsend,
+			    GetCurrentProcess (), &fhc->mqinfo ()->mqi_waitsend,
 			    0, FALSE, DUPLICATE_SAME_ACCESS))
 	__leave;
       if (!DuplicateHandle (parent, mqinfo ()->mqi_waitrecv,
-			    GetCurrentProcess (), &mqinfo ()->mqi_waitrecv,
+			    GetCurrentProcess (), &fhc->mqinfo ()->mqi_waitrecv,
 			    0, FALSE, DUPLICATE_SAME_ACCESS))
 	__leave;
       if (!DuplicateHandle (parent, mqinfo ()->mqi_lock,
-			    GetCurrentProcess (), &mqinfo ()->mqi_lock,
+			    GetCurrentProcess (), &fhc->mqinfo ()->mqi_lock,
 			    0, FALSE, DUPLICATE_SAME_ACCESS))
 	__leave;
-      return;
+      return 0;
     }
   __except (EFAULT) {}
   __endtry
-  api_fatal ("Creating IPC object failed in fork, %E");
+  return -1;
 }
 
 int
-fhandler_mqueue::close ()
+fhandler_mqueue::dup (fhandler_base *child, int flags)
 {
-  int ret = -1;
+  fhandler_mqueue *fhc = (fhandler_mqueue *) child;
 
+  int ret = fhandler_disk_file::dup (child, flags);
+  if (!ret)
+    ret = _dup (GetCurrentProcess (), fhc);
+  return ret;
+}
+
+void
+fhandler_mqueue::fixup_after_fork (HANDLE parent)
+{
+  if (_dup (parent, this))
+    api_fatal ("Creating IPC object failed in fork, %E");
+}
+
+int
+fhandler_mqueue::close ()
+{
   __try
     {
       mqinfo ()->mqi_magic = 0;          /* just in case */


                 reply	other threads:[~2021-05-25 14:56 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=20210525145635.920F63938C3B@sourceware.org \
    --to=corinna@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: link
Be 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).