Return-Path: Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 78649 invoked by uid 500); 11 Feb 2002 20:11:09 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 78636 invoked by uid 500); 11 Feb 2002 20:11:09 -0000 Delivered-To: apmail-new-httpd@apache.org Errors-To: Message-ID: <014401c1b338$189457c0$94c0b0d0@v505> From: "William A. Rowe, Jr." To: Subject: [Patch] Reintroduce CREATE_SUSPENDED? Date: Mon, 11 Feb 2002 14:05:16 -0600 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0134_01C1B305.21CC9AB0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_0134_01C1B305.21CC9AB0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Attached is a patch that reintroduced the CREATE_SUSPENDED. It doesn't resume the thread until the pipe is full of our handles for the child. It must pause while the child starts, before duplicating the listeners. For the moment that's still sleep (1000) - I'm thinking if we used PulseEvent on the child's event handle - the child could pulse it itself once it is awake in the init_child code. Pulse will reset itself, the child can go off to processing. The parent can resume sending the listeners once it hears that event pulsed. It saves us wasting another event for this purpose. Just a thought. The code also cleans up just a bit of FirstBill's hShareError code and some other handle cleanups, so they are all unwound and unwound correctly upon failure. Bill ------=_NextPart_000_0134_01C1B305.21CC9AB0 Content-Type: application/octet-stream; name="suspend.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="suspend.patch" Index: mpm_winnt.c =================================================================== RCS file: /home/cvs/httpd-2.0/server/mpm/winnt/mpm_winnt.c,v retrieving revision 1.232 diff -u -r1.232 mpm_winnt.c --- mpm_winnt.c 11 Feb 2002 15:46:44 -0000 1.232 +++ mpm_winnt.c 11 Feb 2002 20:02:00 -0000 @@ -1537,7 +1537,9 @@ CloseHandle(hPipeWrite); CloseHandle(hPipeRead); CloseHandle(hNullOutput); - CloseHandle(hShareError); + if (GetStdHandle(STD_ERROR_HANDLE) != hShareError) { + CloseHandle(hShareError); + } return -1; } @@ -1580,24 +1582,26 @@ rv = CreateProcess(NULL, pCommand, NULL, NULL, TRUE, /* Inherit handles */ - 0, /* Creation flags */ + CREATE_SUSPENDED, /* Creation flags */ pEnvBlock, /* Environment block */ NULL, &si, &pi); - /* Important: - * Give the child process a chance to run before dup'ing the sockets. - * We have already set the listening sockets noninheritable, but if - * WSADuplicateSocket runs before the child process initializes - * the listeners will be inherited anyway. - * - * XXX: This is badness; needs some mutex interlocking - */ - Sleep(1000); + if (!rv) { + ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, + "Parent: Failed to create the child process."); + } + else { + ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, + "Parent: Created child process %d", pi.dwProcessId); + if (send_handles_to_child(p, *child_exit_event, pi.hProcess, hPipeWrite)) { + TerminateProcess(pi.hProcess, 1); + rv = 0; + } + } /* Undo everything we created for the child only */ - CloseHandle(pi.hThread); CloseHandle(hPipeRead); CloseHandle(hNullOutput); if (GetStdHandle(STD_ERROR_HANDLE) != hShareError) { @@ -1609,25 +1613,33 @@ _putenv("AP_PARENT_PID="); _putenv("AP_MY_GENERATION="); - if (!rv) { - ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, - "Parent: Failed to create the child process."); + if (!rv) /* Failure above */ { + CloseHandle(*child_exit_event); + *child_exit_event = NULL; CloseHandle(hPipeWrite); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return -1; } - ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, - "Parent: Created child process %d", pi.dwProcessId); - - if (send_handles_to_child(p, *child_exit_event, pi.hProcess, hPipeWrite)) { - CloseHandle(hPipeWrite); - return -1; - } + /* Important: + * Give the child process a chance to run before dup'ing the sockets. + * We have already set the listening sockets noninheritable, but if + * WSADuplicateSocket runs before the child process initializes + * the listeners will be inherited anyway. + * + * XXX: This is badness; needs some mutex interlocking + */ + ResumeThread(pi.hThread); + CloseHandle(pi.hThread); + Sleep(1000); if (send_listeners_to_child(p, pi.dwProcessId, hPipeWrite)) { + SetEvent(*child_exit_event); + CloseHandle(*child_exit_event); + *child_exit_event = NULL; CloseHandle(hPipeWrite); + CloseHandle(pi.hProcess); return -1; } ------=_NextPart_000_0134_01C1B305.21CC9AB0--