@@ -512,6 +512,38 @@ static int set_proc_descriptor_to_blackhole(struct php_proc_open_descriptor_item
512
512
return SUCCESS ;
513
513
}
514
514
515
+ static int set_proc_descriptor_to_pipe (struct php_proc_open_descriptor_item * desc , zval * zmode )
516
+ {
517
+ php_file_descriptor_t newpipe [2 ];
518
+
519
+ if (pipe (newpipe )) {
520
+ php_error_docref (NULL , E_WARNING , "Unable to create pipe %s" , strerror (errno ));
521
+ return FAILURE ;
522
+ }
523
+
524
+ desc -> mode = DESC_PIPE ;
525
+
526
+ if (strncmp (Z_STRVAL_P (zmode ), "w" , 1 ) != 0 ) {
527
+ desc -> parentend = newpipe [1 ];
528
+ desc -> childend = newpipe [0 ];
529
+ desc -> mode_flags = O_WRONLY ;
530
+ } else {
531
+ desc -> parentend = newpipe [0 ];
532
+ desc -> childend = newpipe [1 ];
533
+ desc -> mode_flags = O_RDONLY ;
534
+ }
535
+
536
+ #ifdef PHP_WIN32
537
+ /* don't let the child inherit the parent side of the pipe */
538
+ desc -> parentend = dup_handle (desc -> parentend , FALSE, TRUE);
539
+
540
+ if (Z_STRLEN_P (zmode ) >= 2 && Z_STRVAL_P (zmode )[1 ] == 'b' )
541
+ desc -> mode_flags |= O_BINARY ;
542
+ #endif
543
+
544
+ return SUCCESS ;
545
+ }
546
+
515
547
static void efree_argv (char * * argv )
516
548
{
517
549
if (argv ) {
@@ -690,7 +722,6 @@ PHP_FUNCTION(proc_open)
690
722
}
691
723
692
724
if (strcmp (Z_STRVAL_P (ztype ), "pipe" ) == 0 ) {
693
- php_file_descriptor_t newpipe [2 ];
694
725
zval * zmode ;
695
726
696
727
if ((zmode = zend_hash_index_find (Z_ARRVAL_P (descitem ), 1 )) != NULL ) {
@@ -702,30 +733,9 @@ PHP_FUNCTION(proc_open)
702
733
goto exit_fail ;
703
734
}
704
735
705
- descriptors [ndesc ].mode = DESC_PIPE ;
706
-
707
- if (0 != pipe (newpipe )) {
708
- php_error_docref (NULL , E_WARNING , "Unable to create pipe %s" , strerror (errno ));
736
+ if (set_proc_descriptor_to_pipe (& descriptors [ndesc ], zmode ) == FAILURE ) {
709
737
goto exit_fail ;
710
738
}
711
-
712
- if (strncmp (Z_STRVAL_P (zmode ), "w" , 1 ) != 0 ) {
713
- descriptors [ndesc ].parentend = newpipe [1 ];
714
- descriptors [ndesc ].childend = newpipe [0 ];
715
- descriptors [ndesc ].mode_flags = O_WRONLY ;
716
- } else {
717
- descriptors [ndesc ].parentend = newpipe [0 ];
718
- descriptors [ndesc ].childend = newpipe [1 ];
719
- descriptors [ndesc ].mode_flags = O_RDONLY ;
720
- }
721
- #ifdef PHP_WIN32
722
- /* don't let the child inherit the parent side of the pipe */
723
- descriptors [ndesc ].parentend = dup_handle (descriptors [ndesc ].parentend , FALSE, TRUE);
724
-
725
- if (Z_STRLEN_P (zmode ) >= 2 && Z_STRVAL_P (zmode )[1 ] == 'b' )
726
- descriptors [ndesc ].mode_flags |= O_BINARY ;
727
- #endif
728
-
729
739
} else if (strcmp (Z_STRVAL_P (ztype ), "file" ) == 0 ) {
730
740
zval * zfile , * zmode ;
731
741
php_socket_t fd ;
0 commit comments