2
2
+----------------------------------------------------------------------+
3
3
| PHP Version 7 |
4
4
+----------------------------------------------------------------------+
5
- | Copyright (c) 1997-2017 The PHP Group |
5
+ | Copyright (c) 1997-2018 The PHP Group |
6
6
+----------------------------------------------------------------------+
7
7
| This source file is subject to version 3.01 of the PHP license, |
8
8
| that is bundled with this package in the file LICENSE, and is |
15
15
| Author: Wez Furlong <wez@thebrainroom.com> |
16
16
+----------------------------------------------------------------------+
17
17
*/
18
- /* $Id$ */
19
18
20
19
#if 0 && (defined(__linux__ ) || defined(sun ) || defined(__IRIX__ ))
21
20
# define _BSD_SOURCE /* linux wants this when XOPEN mode is on */
22
- # define _BSD_COMPAT /* irix: uint */
21
+ # define _BSD_COMPAT /* irix: uint32_t */
23
22
# define _XOPEN_SOURCE 500 /* turn on Unix98 */
24
- # define __EXTENSIONS__ 1 /* Solaris: uint */
23
+ # define __EXTENSIONS__ 1 /* Solaris: uint32_t */
25
24
#endif
26
25
27
26
#include "php.h"
36
35
#include "SAPI.h"
37
36
#include "main/php_network.h"
38
37
39
- #ifdef NETWARE
40
- #include <proc.h>
41
- #include <library.h>
42
- #endif
43
-
44
38
#if HAVE_SYS_WAIT_H
45
39
#include <sys/wait.h>
46
40
#endif
60
54
* Other platforms may modify that configure check and add suitable #ifdefs
61
55
* around the alternate code.
62
56
* */
63
-
64
57
#if 0 && HAVE_PTSNAME && HAVE_GRANTPT && HAVE_UNLOCKPT && HAVE_SYS_IOCTL_H && HAVE_TERMIOS_H
65
58
# include <sys/ioctl.h>
66
59
# include <termios.h>
@@ -108,7 +101,11 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
108
101
str = zval_get_string (element );
109
102
110
103
if (ZSTR_LEN (str ) == 0 ) {
104
+ #if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 3 )
105
+ zend_string_release_ex (str , 0 );
106
+ #else
111
107
zend_string_release (str );
108
+ #endif
112
109
continue ;
113
110
}
114
111
@@ -147,10 +144,14 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
147
144
#endif
148
145
p += ZSTR_LEN (str ) + 1 ;
149
146
}
150
- zend_string_release (str );
147
+ #if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 3 )
148
+ zend_string_release_ex (str , 0 );
149
+ #else
150
+ zend_string_release (str );
151
+ #endif
151
152
} ZEND_HASH_FOREACH_END ();
152
153
153
- assert ((uint )(p - env .envp ) <= sizeenv );
154
+ assert ((uint32_t )(p - env .envp ) <= sizeenv );
154
155
155
156
zend_hash_destroy (env_hash );
156
157
FREE_HASHTABLE (env_hash );
@@ -189,10 +190,10 @@ static void proc_open_rsrc_dtor(zend_resource *rsrc)
189
190
/* Close all handles to avoid a deadlock */
190
191
for (i = 0 ; i < proc -> npipes ; i ++ ) {
191
192
if (proc -> pipes [i ] != 0 ) {
192
- #if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 3 )
193
- GC_REFCOUNT (proc -> pipes [i ])-- ;
194
- #else
193
+ #if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 3 )
195
194
GC_DELREF (proc -> pipes [i ]);
195
+ #else
196
+ GC_REFCOUNT (proc -> pipes [i ])-- ;
196
197
#endif
197
198
zend_list_close (proc -> pipes [i ]);
198
199
proc -> pipes [i ] = 0 ;
@@ -247,17 +248,19 @@ PHP_MINIT_FUNCTION(proc_open)
247
248
}
248
249
/* }}} */
249
250
250
- /* {{{ proto bool proc_terminate(resource process [, long signal])
251
+ /* {{{ proto bool proc_terminate(resource process [, int signal])
251
252
kill a process opened by proc_open */
252
253
PHP_FUNCTION (proc_terminate )
253
254
{
254
255
zval * zproc ;
255
256
struct php_process_handle * proc ;
256
257
zend_long sig_no = SIGTERM ;
257
258
258
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "r|l" , & zproc , & sig_no ) == FAILURE ) {
259
- RETURN_FALSE ;
260
- }
259
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
260
+ Z_PARAM_RESOURCE (zproc )
261
+ Z_PARAM_OPTIONAL
262
+ Z_PARAM_LONG (sig_no )
263
+ ZEND_PARSE_PARAMETERS_END_EX (RETURN_FALSE );
261
264
262
265
if ((proc = (struct php_process_handle * )zend_fetch_resource (Z_RES_P (zproc ), "process" , le_proc_open )) == NULL ) {
263
266
RETURN_FALSE ;
@@ -286,9 +289,9 @@ PHP_FUNCTION(proc_close)
286
289
zval * zproc ;
287
290
struct php_process_handle * proc ;
288
291
289
- if ( zend_parse_parameters ( ZEND_NUM_ARGS (), "r" , & zproc ) == FAILURE ) {
290
- RETURN_FALSE ;
291
- }
292
+ ZEND_PARSE_PARAMETERS_START ( 1 , 1 )
293
+ Z_PARAM_RESOURCE ( zproc )
294
+ ZEND_PARSE_PARAMETERS_END_EX ( RETURN_FALSE );
292
295
293
296
if ((proc = (struct php_process_handle * )zend_fetch_resource (Z_RES_P (zproc ), "process" , le_proc_open )) == NULL ) {
294
297
RETURN_FALSE ;
@@ -316,9 +319,9 @@ PHP_FUNCTION(proc_get_status)
316
319
int running = 1 , signaled = 0 , stopped = 0 ;
317
320
int exitcode = -1 , termsig = 0 , stopsig = 0 ;
318
321
319
- if ( zend_parse_parameters ( ZEND_NUM_ARGS (), "r" , & zproc ) == FAILURE ) {
320
- RETURN_FALSE ;
321
- }
322
+ ZEND_PARSE_PARAMETERS_START ( 1 , 1 )
323
+ Z_PARAM_RESOURCE ( zproc )
324
+ ZEND_PARSE_PARAMETERS_END_EX ( RETURN_FALSE );
322
325
323
326
if ((proc = (struct php_process_handle * )zend_fetch_resource (Z_RES_P (zproc ), "process" , le_proc_open )) == NULL ) {
324
327
RETURN_FALSE ;
@@ -349,11 +352,8 @@ PHP_FUNCTION(proc_get_status)
349
352
if (WIFSIGNALED (wstatus )) {
350
353
running = 0 ;
351
354
signaled = 1 ;
352
- #ifdef NETWARE
353
- termsig = WIFTERMSIG (wstatus );
354
- #else
355
+
355
356
termsig = WTERMSIG (wstatus );
356
- #endif
357
357
}
358
358
if (WIFSTOPPED (wstatus )) {
359
359
stopped = 1 ;
@@ -424,6 +424,7 @@ PHP_FUNCTION(proc_open)
424
424
php_process_env_t env ;
425
425
int ndesc = 0 ;
426
426
int i ;
427
+ int current_procopen_call_id = ++ procopen_call_id ;
427
428
zval * descitem = NULL ;
428
429
zend_string * str_index ;
429
430
zend_ulong nindex ;
@@ -432,20 +433,14 @@ PHP_FUNCTION(proc_open)
432
433
#ifdef PHP_WIN32
433
434
PROCESS_INFORMATION pi ;
434
435
HANDLE childHandle ;
435
- STARTUPINFO si ;
436
+ STARTUPINFOW si ;
436
437
BOOL newprocok ;
437
438
SECURITY_ATTRIBUTES security ;
438
439
DWORD dwCreateFlags = 0 ;
439
- char * command_with_cmd ;
440
440
UINT old_error_mode ;
441
441
char cur_cwd [MAXPATHLEN ];
442
- #endif
443
- #ifdef NETWARE
444
- char * * child_argv = NULL ;
445
- char * command_dup = NULL ;
446
- char * orig_cwd = NULL ;
447
- int command_num_args = 0 ;
448
- wiring_t channel ;
442
+ wchar_t * cmdw = NULL , * cwdw = NULL , * envpw = NULL ;
443
+ size_t tmp_len ;
449
444
#endif
450
445
php_process_id_t child ;
451
446
struct php_process_handle * proc ;
@@ -459,13 +454,16 @@ PHP_FUNCTION(proc_open)
459
454
php_file_descriptor_t dev_ptmx = -1 ; /* master */
460
455
php_file_descriptor_t slave_pty = -1 ;
461
456
#endif
462
-
463
- int current_procopen_call_id = ++ procopen_call_id ;
464
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "saz/|s!a!a!" , & command ,
465
- & command_len , & descriptorspec , & pipes , & cwd , & cwd_len , & environment ,
466
- & other_options ) == FAILURE ) {
467
- RETURN_FALSE ;
468
- }
457
+
458
+ ZEND_PARSE_PARAMETERS_START (3 , 6 )
459
+ Z_PARAM_STRING (command , command_len )
460
+ Z_PARAM_ARRAY (descriptorspec )
461
+ Z_PARAM_ZVAL_DEREF (pipes )
462
+ Z_PARAM_OPTIONAL
463
+ Z_PARAM_STRING_EX (cwd , cwd_len , 1 , 0 )
464
+ Z_PARAM_ARRAY_EX (environment , 1 , 0 )
465
+ Z_PARAM_ARRAY_EX (other_options , 1 , 0 )
466
+ ZEND_PARSE_PARAMETERS_END_EX (RETURN_FALSE );
469
467
470
468
command = pestrdup (command , is_persistent );
471
469
@@ -547,7 +545,7 @@ PHP_FUNCTION(proc_open)
547
545
#else
548
546
descriptors [ndesc ].childend = dup (fd );
549
547
if (descriptors [ndesc ].childend < 0 ) {
550
- php_error_docref (NULL , E_WARNING , "unable to dup File-Handle for descriptor %pd - %s" , nindex , strerror (errno ));
548
+ php_error_docref (NULL , E_WARNING , "unable to dup File-Handle for descriptor " ZEND_ULONG_FMT " - %s" , nindex , strerror (errno ));
551
549
goto exit_fail ;
552
550
}
553
551
#endif
@@ -592,15 +590,15 @@ PHP_FUNCTION(proc_open)
592
590
descriptors [ndesc ].childend = current_procopen_call_id ;
593
591
descriptors [ndesc ].parentend = open (device_path , O_WRONLY );
594
592
} else {
595
- if (strncmp (Z_STRVAL_P (zmode ), "w" , 1 ) != 0 ) {
596
- descriptors [ndesc ].parentend = newpipe [1 ];
597
- descriptors [ndesc ].childend = newpipe [0 ];
598
- descriptors [ndesc ].mode |= DESC_PARENT_MODE_WRITE ;
599
- } else {
600
- descriptors [ndesc ].parentend = newpipe [0 ];
601
- descriptors [ndesc ].childend = newpipe [1 ];
602
- }
603
- }
593
+ if (strncmp (Z_STRVAL_P (zmode ), "w" , 1 ) != 0 ) {
594
+ descriptors [ndesc ].parentend = newpipe [1 ];
595
+ descriptors [ndesc ].childend = newpipe [0 ];
596
+ descriptors [ndesc ].mode |= DESC_PARENT_MODE_WRITE ;
597
+ } else {
598
+ descriptors [ndesc ].parentend = newpipe [0 ];
599
+ descriptors [ndesc ].childend = newpipe [1 ];
600
+ }
601
+ }
604
602
#ifdef PHP_WIN32
605
603
/* don't let the child inherit the parent side of the pipe */
606
604
descriptors [ndesc ].parentend = dup_handle (descriptors [ndesc ].parentend , FALSE, TRUE);
@@ -689,6 +687,7 @@ PHP_FUNCTION(proc_open)
689
687
ndesc ++ ;
690
688
} ZEND_HASH_FOREACH_END ();
691
689
690
+
692
691
// the wasm way {{{
693
692
js_open_process (
694
693
command ,
@@ -698,7 +697,7 @@ PHP_FUNCTION(proc_open)
698
697
descriptors [2 ].childend ,
699
698
descriptors [2 ].parentend
700
699
);
701
- // }}}
700
+ // }}}
702
701
/* we forked/spawned and this is the parent */
703
702
704
703
proc = (struct php_process_handle * )pemalloc (sizeof (struct php_process_handle ), is_persistent );
@@ -712,10 +711,7 @@ PHP_FUNCTION(proc_open)
712
711
#endif
713
712
proc -> env = env ;
714
713
715
- if (pipes != NULL ) {
716
- zval_dtor (pipes );
717
- }
718
-
714
+ zval_ptr_dtor (pipes );
719
715
array_init (pipes );
720
716
721
717
#if PHP_CAN_DO_PTS
@@ -791,6 +787,11 @@ PHP_FUNCTION(proc_open)
791
787
efree (descriptors );
792
788
_php_free_envp (env , is_persistent );
793
789
pefree (command , is_persistent );
790
+ #ifdef PHP_WIN32
791
+ free (cwdw );
792
+ free (cmdw );
793
+ free (envpw );
794
+ #endif
794
795
#if PHP_CAN_DO_PTS
795
796
if (dev_ptmx >= 0 ) {
796
797
close (dev_ptmx );
@@ -803,12 +804,3 @@ PHP_FUNCTION(proc_open)
803
804
804
805
}
805
806
/* }}} */
806
-
807
- /*
808
- * Local variables:
809
- * tab-width: 4
810
- * c-basic-offset: 4
811
- * End:
812
- * vim600: sw=4 ts=4 fdm=marker
813
- * vim<600: sw=4 ts=4
814
- */
0 commit comments