Req #41003 [Opn->Csd]: proc_get_status - PID is -1 out

From: Date: Mon, 19 Jul 2021 15:47:15 +0000
Subject: Req #41003 [Opn->Csd]: proc_get_status - PID is -1 out
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235188@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=41003&edit=1 ID: 41003 Updated by: cmb@php.net Reported by: andy dot shellam at mailnetwork dot co dot uk Summary: proc_get_status - PID is -1 out -Status: Open +Status: Closed Type: Feature/Change Request Package: Program Execution Operating System: Unix (FreeBSD) PHP Version: 5.2.1 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: As of PHP 7.4.0, the first argument to proc_open() can be an array, in which case the shell is bypassed. Previous Comments: ------------------------------------------------------------------------ [2012-02-27 14:45:08] arto at bendiken dot net Note that a very simple user-level workaround on Unix systems is to call proc_open("exec /usr/bin/myprogram") instead of proc_open("/usr/bin/myprogram"), in which case the shell is replaced by the program being executed and proc_get_status() thus returns the program's PID instead of the shell's. Similarly, the very simplest (though not most efficient) way to have the "bypass_shell" option work on Unix as well would be to simply prepend "exec " to the command string automatically in the implementation of proc_open(). It seems to me that proc_get_status() works correctly, and that indeed this bug report is really about "bypass_shell" not being honored on Unix, so perhaps the bug report could be retitled accordingly. ------------------------------------------------------------------------ [2009-03-17 07:55:31] vdovin_m at mail dot ru I have w/changes for FreeBSD. W/pacth you can use "bypass_shell" to start binary executable file w/o /bin/sh process. To compile w/patch, modification in Makefile are needed (add "-lpopt" to EXTRA_LIBS parameter line). -----proc_open.patch start---- {{{ 19c19,21 < --- > #ifndef PHP_WIN32 > #include <popt.h> > #endif 469a472,474 > char *param_str = NULL; > char *param_dup = NULL; > char *const *av = NULL; 501d505 < int bypass_shell = 0; 502a507 > int bypass_shell = 0; 517a523,524 > command_len = strlen(command); > 533a541,552 > #else > if (other_options) { > zval **item; > if (SUCCESS == zend_hash_find(Z_ARRVAL_P(other_options), "bypass_shell", > sizeof("bypass_shell"), (void**)&item)) { > if ((Z_TYPE_PP(item) == IS_BOOL || Z_TYPE_PP(item) == IS_LONG) && > Z_LVAL_PP(item)) { > param_dup = pemalloc(command_len+1, is_persistent); > memcpy(param_dup, command, command_len+1); > bypass_shell = 1; > } > } > } 536,537d554 < command_len = strlen(command); < 881c898,915 < execle("/bin/sh", "sh", "-c", command, NULL, env.envarray); --- > if (bypass_shell) { > int rc; > if ((param_str = strchr(command, ' '))) { > rc = poptParseArgvString(command, NULL, (const char ***)&av); > *param_str = '\0'; > if (!rc && av != NULL){ > execve(command, (char * const *) av, env.envarray); > free((void*)av); > } else { > param_str++; > execle(command, command, param_str, NULL, env.envarray); > } > } else { > execlp(command, NULL); > } > } else { > execle("/bin/sh", "sh", "-c", command, NULL, env.envarray); > } 883c917,934 < execl("/bin/sh", "sh", "-c", command, NULL); --- > if (bypass_shell) { > int rc; > if ((param_str = strchr(command, ' '))) { > rc = poptParseArgvString(command, NULL, (const char ***)&av); > *param_str = '\0'; > if (!rc && av != NULL){ > execvp(command, (char * const *) av); > free((void*)av); > } else { > param_str++; > execlp(command, command, param_str, NULL); > } > } else { > execlp(command, NULL); > } > } else { > execl("/bin/sh", "sh", "-c", command, NULL); > } 909c960,965 < proc->command = command; --- > if (bypass_shell) { > pefree(command, is_persistent); > proc->command = param_dup; > } else { > proc->command = command; > } 991a1048 > pefree(param_dup, is_persistent); }}} -----proc_open.patch end------ ------------------------------------------------------------------------ [2007-06-19 11:59:10] andy dot shellam at mailnetwork dot co dot uk Can this be raised as a feature request, that PHP can optionally bypass the shell when launching a process, as in the Windows version? ------------------------------------------------------------------------ [2007-04-09 11:56:47] andy dot shellam at mailnetwork dot co dot uk Sorry that might have been a bad example, but even without a shell script (i.e. an executable) a shell process is still launched to run that process. You are correct, PHP is returning the ID of the process it launches (the shell.) But can this not be changed as it is in the Windows version, so you can (optionally) bypass the shell and launch the process directly, as that would then return the correct PID of the process itself? I.e. in Windows PHP is launching cmd.exe, in Unix it's launching sh. In the Windows version there's an option to bypass cmd.exe and launch the process directly. Can't you do the same for Unix? ------------------------------------------------------------------------ [2007-04-08 15:14:23] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php PHP started the ./loop.sh script, which is why its PID is returned. The other command was initiated by the shell script and PHP has no way of knowing about it. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=41003 -- Edit this bug report at https://bugs.php.net/bug.php?id=41003&edit=1

« previous php.bugs (#235188) next »