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>
This commit is contained in:
Corinna Vinschen 2020-02-28 13:21:05 +01:00
parent a834dc1ba9
commit 729cb70bcf
4 changed files with 16 additions and 10 deletions

View File

@ -1076,6 +1076,7 @@ class fhandler_socket_unix : public fhandler_socket
void fixup_after_fork (HANDLE parent); void fixup_after_fork (HANDLE parent);
void fixup_after_exec (); void fixup_after_exec ();
void set_close_on_exec (bool val); void set_close_on_exec (bool val);
void fixup_helper ();
public: public:
fhandler_socket_unix (); fhandler_socket_unix ();

View File

@ -534,7 +534,7 @@ void
fhandler_socket_wsock::fixup_after_exec () fhandler_socket_wsock::fixup_after_exec ()
{ {
if (need_fixup_before () && !close_on_exec ()) if (need_fixup_before () && !close_on_exec ())
fixup_after_fork (NULL); fixup_after_fork (NULL); /* No parent handle required. */
} }
int int

View File

@ -1149,6 +1149,16 @@ fhandler_socket_unix::set_cred ()
scred->gid = myself->gid; 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 ========================= */ /* ========================== public methods ========================= */
void void
@ -1158,20 +1168,15 @@ fhandler_socket_unix::fixup_after_fork (HANDLE parent)
if (backing_file_handle && backing_file_handle != INVALID_HANDLE_VALUE) if (backing_file_handle && backing_file_handle != INVALID_HANDLE_VALUE)
fork_fixup (parent, backing_file_handle, "backing_file_handle"); fork_fixup (parent, backing_file_handle, "backing_file_handle");
if (shmem_handle) if (shmem_handle)
{
fork_fixup (parent, shmem_handle, "shmem_handle"); fork_fixup (parent, shmem_handle, "shmem_handle");
reopen_shmem (); fixup_helper ();
}
connect_wait_thr = NULL;
cwt_termination_evt = NULL;
cwt_param = NULL;
} }
void void
fhandler_socket_unix::fixup_after_exec () fhandler_socket_unix::fixup_after_exec ()
{ {
if (!close_on_exec ()) if (!close_on_exec ())
fixup_after_fork (NULL); fixup_helper ();
} }
void void

View File

@ -2974,7 +2974,7 @@ fhandler_pty_slave::fixup_after_exec ()
reset_switch_to_pcon (); reset_switch_to_pcon ();
if (!close_on_exec ()) if (!close_on_exec ())
fixup_after_fork (NULL); fixup_after_fork (NULL); /* No parent handle required. */
else if (get_pseudo_console ()) else if (get_pseudo_console ())
{ {
int used = 0; int used = 0;