Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13832 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62009 invoked by uid 1010); 14 Nov 2004 11:11:39 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 61941 invoked from network); 14 Nov 2004 11:11:38 -0000 Received: from unknown (HELO rproxy.gmail.com) (64.233.170.207) by pb1.pair.com with SMTP; 14 Nov 2004 11:11:38 -0000 Received: by rproxy.gmail.com with SMTP id q1so615349rnf for ; Sun, 14 Nov 2004 03:11:38 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type; b=HO/4su6My/EFBBgGM/RpT7scF3q1hgrFA6JXwkaAStp5hUECCWtrKhiqW/XcMY8PLW7GjSEgnHypdStbtkB0mq4lQa4rn9xN5YkMBM5Ye6IRZlOLx0rrkryBbO4jkd00b0X5TRrNF2Ze585WaHCi2WjFbEH7gep3s2pGi8ijrGU= Received: by 10.39.3.28 with SMTP id f28mr610465rni; Sun, 14 Nov 2004 03:11:38 -0800 (PST) Received: by 10.38.70.1 with HTTP; Sun, 14 Nov 2004 03:11:38 -0800 (PST) Message-ID: Date: Sun, 14 Nov 2004 13:11:38 +0200 Reply-To: "ilya77@gmail.com" To: internals@lists.php.net Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_236_26427711.1100430698626" Subject: [PATCH] proc_open() invokes unnecessary instances of CMD.EXE on Win32 for *each* started process, even if it's not necessary From: ilya77@gmail.com ("ilya77@gmail.com") ------=_Part_236_26427711.1100430698626 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Here's a patch, which logic is pretty simple: 1st try to invoke without CMD.EXE (this will work for executable files), and if that fails - invoke with CMD.EXE. Shouldn't be too much of a burden for the CPU, but saves memory. It also allows to kill processes later, which wouldn't happen if CMD.EXE would wrap the child process - only CMD.EXE would be killed. Also, attached the patch in text file form since gmail might screw some characters. ----------------------------------------------------------------- Index: php-src/ext/standard/proc_open.c =================================================================== RCS file: /repository/php-src/ext/standard/proc_open.c,v retrieving revision 1.30 diff -u -p -w -r1.30 proc_open.c --- php-src/ext/standard/proc_open.c 10 Nov 2004 19:47:15 -0000 1.30 +++ php-src/ext/standard/proc_open.c 14 Nov 2004 10:45:56 -0000 @@ -729,23 +729,30 @@ PHP_FUNCTION(proc_open) } + if (suppress_errors) { + old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX); + } + memset(&pi, 0, sizeof(pi)); + // Try invoking without CMD first + newprocok = CreateProcess(NULL, command, &security, &security, TRUE, NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi); + + if (newprocok == FALSE) + { + // If failed - invoke with CMD command_with_cmd = emalloc(command_len + sizeof(COMSPEC_9X) + 1 + sizeof(" /c ")); sprintf(command_with_cmd, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command); - if (suppress_errors) { - old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX); - } - newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi); + efree(command_with_cmd); + } + if (suppress_errors) { SetErrorMode(old_error_mode); } - efree(command_with_cmd); - if (FALSE == newprocok) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateProcess failed"); goto exit_fail; ------=_Part_236_26427711.1100430698626 Content-Type: text/plain; name="proc_open_cmd.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="proc_open_cmd.patch" Index: php-src/ext/standard/proc_open.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /repository/php-src/ext/standard/proc_open.c,v retrieving revision 1.30 diff -u -p -w -r1.30 proc_open.c --- php-src/ext/standard/proc_open.c=0910 Nov 2004 19:47:15 -0000=091.30 +++ php-src/ext/standard/proc_open.c=0914 Nov 2004 10:45:56 -0000 @@ -729,23 +729,30 @@ PHP_FUNCTION(proc_open) =09} =20 =09 +=09if (suppress_errors) { +=09=09old_error_mode =3D SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULT= ERRORBOX); +=09} + =09memset(&pi, 0, sizeof(pi)); =09 +=09// Try invoking without CMD first +=09newprocok =3D CreateProcess(NULL, command, &security, &security, TRUE, = NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi); + +=09if (newprocok =3D=3D FALSE) +=09{ +=09=09// If failed - invoke with CMD =09command_with_cmd =3D emalloc(command_len + sizeof(COMSPEC_9X) + 1 + siz= eof(" /c ")); =09sprintf(command_with_cmd, "%s /c %s", GetVersion() < 0x80000000 ? COMSP= EC_NT : COMSPEC_9X, command); =20 -=09if (suppress_errors) { -=09=09old_error_mode =3D SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOGPFAULT= ERRORBOX); -=09} -=09 =09newprocok =3D CreateProcess(NULL, command_with_cmd, &security, &securit= y, TRUE, NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi); =20 +=09=09efree(command_with_cmd); +=09} + =09if (suppress_errors) { =09=09SetErrorMode(old_error_mode); =09} =09 -=09efree(command_with_cmd); - =09if (FALSE =3D=3D newprocok) { =09=09php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateProcess failed"); =09=09goto exit_fail; ------=_Part_236_26427711.1100430698626--