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: AF_UNIX: rework fixup_after_exec
Date: Fri, 28 Feb 2020 14:27:00 -0000	[thread overview]
Message-ID: <20200228142736.36747.qmail@sourceware.org> (raw)

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

commit 729cb70bcf232a1da956ec3725c1f76e28b3caa5
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Feb 28 13:21:05 2020 +0100

    Cygwin: AF_UNIX: rework fixup_after_exec
    
    fhandler_socket_unix::fixup_after_exec incorrectly calls
    fhandler_socket_unix::fixup_after_fork with a NULL parent process
    handle.  Not only that calling DuplicateHandle with a NULL parent
    handle fails, but it's utterly wrong trying to duplicate the handles
    at all here.
    
    Rather just set some important values to NULL and reopen the shared
    memory region.  Create a fixup_helper method to call common code from
    fixup_after_fork and fixup_after_exec.
    
    Add comments to other invocations of fixup_after_fork with NULL
    handle to mark them as correct this way.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler.h              |  1 +
 winsup/cygwin/fhandler_socket_inet.cc |  2 +-
 winsup/cygwin/fhandler_socket_unix.cc | 21 +++++++++++++--------
 winsup/cygwin/fhandler_tty.cc         |  2 +-
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 55f18ae..90805ab 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1076,6 +1076,7 @@ class fhandler_socket_unix : public fhandler_socket
   void fixup_after_fork (HANDLE parent);
   void fixup_after_exec ();
   void set_close_on_exec (bool val);
+  void fixup_helper ();
 
  public:
   fhandler_socket_unix ();
diff --git a/winsup/cygwin/fhandler_socket_inet.cc b/winsup/cygwin/fhandler_socket_inet.cc
index 6f43838..703781d 100644
--- a/winsup/cygwin/fhandler_socket_inet.cc
+++ b/winsup/cygwin/fhandler_socket_inet.cc
@@ -534,7 +534,7 @@ void
 fhandler_socket_wsock::fixup_after_exec ()
 {
   if (need_fixup_before () && !close_on_exec ())
-    fixup_after_fork (NULL);
+    fixup_after_fork (NULL);	/* No parent handle required. */
 }
 
 int
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index 760f210..d7bb109 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -1149,6 +1149,16 @@ fhandler_socket_unix::set_cred ()
   scred->gid = myself->gid;
 }
 
+void
+fhandler_socket_unix::fixup_helper ()
+{
+  if (shmem_handle)
+    reopen_shmem ();
+  connect_wait_thr = NULL;
+  cwt_termination_evt = NULL;
+  cwt_param = NULL;
+}
+
 /* ========================== public methods ========================= */
 
 void
@@ -1158,20 +1168,15 @@ fhandler_socket_unix::fixup_after_fork (HANDLE parent)
   if (backing_file_handle && backing_file_handle != INVALID_HANDLE_VALUE)
     fork_fixup (parent, backing_file_handle, "backing_file_handle");
   if (shmem_handle)
-    {
-      fork_fixup (parent, shmem_handle, "shmem_handle");
-      reopen_shmem ();
-    }
-  connect_wait_thr = NULL;
-  cwt_termination_evt = NULL;
-  cwt_param = NULL;
+    fork_fixup (parent, shmem_handle, "shmem_handle");
+  fixup_helper ();
 }
 
 void
 fhandler_socket_unix::fixup_after_exec ()
 {
   if (!close_on_exec ())
-    fixup_after_fork (NULL);
+    fixup_helper ();
 }
 
 void
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 153bdad..b42e0ae 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2974,7 +2974,7 @@ fhandler_pty_slave::fixup_after_exec ()
   reset_switch_to_pcon ();
 
   if (!close_on_exec ())
-    fixup_after_fork (NULL);
+    fixup_after_fork (NULL);	/* No parent handle required. */
   else if (get_pseudo_console ())
     {
       int used = 0;


                 reply	other threads:[~2020-02-28 14:27 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=20200228142736.36747.qmail@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).