@@ -588,26 +588,26 @@ static void init_process_info(PROCESS_INFORMATION *pi)
588
588
memset (& pi , 0 , sizeof (pi ));
589
589
}
590
590
591
- static int convert_command_to_use_shell (wchar_t * * cmdw , size_t cmdw_len )
591
+ static bool convert_command_to_use_shell (wchar_t * * cmdw , size_t cmdw_len )
592
592
{
593
593
size_t len = sizeof (COMSPEC_NT ) + sizeof (" /s /c " ) + cmdw_len + 3 ;
594
594
wchar_t * cmdw_shell = (wchar_t * )malloc (len * sizeof (wchar_t ));
595
595
596
596
if (cmdw_shell == NULL ) {
597
597
php_error_docref (NULL , E_WARNING , "Command conversion failed" );
598
- return FAILURE ;
598
+ return false ;
599
599
}
600
600
601
601
if (_snwprintf (cmdw_shell , len , L"%hs /s /c \"%s\"" , COMSPEC_NT , * cmdw ) == -1 ) {
602
602
free (cmdw_shell );
603
603
php_error_docref (NULL , E_WARNING , "Command conversion failed" );
604
- return FAILURE ;
604
+ return false ;
605
605
}
606
606
607
607
free (* cmdw );
608
608
* cmdw = cmdw_shell ;
609
609
610
- return SUCCESS ;
610
+ return true ;
611
611
}
612
612
#endif
613
613
@@ -659,26 +659,26 @@ static zend_string* get_string_parameter(zval *array, int index, char *param_nam
659
659
return zval_try_get_string (array_item );
660
660
}
661
661
662
- static int set_proc_descriptor_to_blackhole (descriptorspec_item * desc )
662
+ static bool set_proc_descriptor_to_blackhole (descriptorspec_item * desc )
663
663
{
664
664
#ifdef PHP_WIN32
665
665
desc -> childend = CreateFileA ("nul" , GENERIC_READ | GENERIC_WRITE ,
666
666
FILE_SHARE_READ | FILE_SHARE_WRITE , NULL , OPEN_EXISTING , 0 , NULL );
667
667
if (desc -> childend == NULL ) {
668
668
php_error_docref (NULL , E_WARNING , "Failed to open nul" );
669
- return FAILURE ;
669
+ return false ;
670
670
}
671
671
#else
672
672
desc -> childend = open ("/dev/null" , O_RDWR );
673
673
if (desc -> childend < 0 ) {
674
674
php_error_docref (NULL , E_WARNING , "Failed to open /dev/null: %s" , strerror (errno ));
675
- return FAILURE ;
675
+ return false ;
676
676
}
677
677
#endif
678
- return SUCCESS ;
678
+ return true ;
679
679
}
680
680
681
- static int set_proc_descriptor_to_pty (descriptorspec_item * desc , int * master_fd , int * slave_fd )
681
+ static bool set_proc_descriptor_to_pty (descriptorspec_item * desc , int * master_fd , int * slave_fd )
682
682
{
683
683
#if HAVE_OPENPTY
684
684
/* All FDs set to PTY in the child process will go to the slave end of the same PTY.
@@ -689,18 +689,18 @@ static int set_proc_descriptor_to_pty(descriptorspec_item *desc, int *master_fd,
689
689
if (* master_fd == -1 ) {
690
690
if (openpty (master_fd , slave_fd , NULL , NULL , NULL )) {
691
691
php_error_docref (NULL , E_WARNING , "Could not open PTY (pseudoterminal): %s" , strerror (errno ));
692
- return FAILURE ;
692
+ return false ;
693
693
}
694
694
}
695
695
696
696
desc -> type = DESCRIPTOR_TYPE_PIPE ;
697
697
desc -> childend = dup (* slave_fd );
698
698
desc -> parentend = dup (* master_fd );
699
699
desc -> mode_flags = O_RDWR ;
700
- return SUCCESS ;
700
+ return true ;
701
701
#else
702
702
php_error_docref (NULL , E_WARNING , "PTY (pseudoterminal) not supported on this system" );
703
- return FAILURE ;
703
+ return false ;
704
704
#endif
705
705
}
706
706
@@ -717,13 +717,13 @@ static php_file_descriptor_t make_descriptor_cloexec(php_file_descriptor_t fd)
717
717
#endif
718
718
}
719
719
720
- static int set_proc_descriptor_to_pipe (descriptorspec_item * desc , zend_string * zmode )
720
+ static bool set_proc_descriptor_to_pipe (descriptorspec_item * desc , zend_string * zmode )
721
721
{
722
722
php_file_descriptor_t newpipe [2 ];
723
723
724
724
if (pipe (newpipe )) {
725
725
php_error_docref (NULL , E_WARNING , "Unable to create pipe %s" , strerror (errno ));
726
- return FAILURE ;
726
+ return false ;
727
727
}
728
728
729
729
desc -> type = DESCRIPTOR_TYPE_PIPE ;
@@ -745,7 +745,7 @@ static int set_proc_descriptor_to_pipe(descriptorspec_item *desc, zend_string *z
745
745
desc -> mode_flags |= O_BINARY ;
746
746
#endif
747
747
748
- return SUCCESS ;
748
+ return true ;
749
749
}
750
750
751
751
#ifdef PHP_WIN32
@@ -754,15 +754,15 @@ static int set_proc_descriptor_to_pipe(descriptorspec_item *desc, zend_string *z
754
754
#define create_socketpair (socks ) socketpair(AF_UNIX, SOCK_STREAM, 0, (socks))
755
755
#endif
756
756
757
- static int set_proc_descriptor_to_socket (descriptorspec_item * desc )
757
+ static bool set_proc_descriptor_to_socket (descriptorspec_item * desc )
758
758
{
759
759
php_socket_t sock [2 ];
760
760
761
761
if (create_socketpair (sock )) {
762
762
zend_string * err = php_socket_error_str (php_socket_errno ());
763
763
php_error_docref (NULL , E_WARNING , "Unable to create socket pair: %s" , ZSTR_VAL (err ));
764
764
zend_string_release (err );
765
- return FAILURE ;
765
+ return false ;
766
766
}
767
767
768
768
desc -> type = DESCRIPTOR_TYPE_SOCKET ;
@@ -771,10 +771,10 @@ static int set_proc_descriptor_to_socket(descriptorspec_item *desc)
771
771
/* Pass sock[1] to child because it will never use overlapped IO on Windows. */
772
772
desc -> childend = (php_file_descriptor_t ) sock [1 ];
773
773
774
- return SUCCESS ;
774
+ return true ;
775
775
}
776
776
777
- static int set_proc_descriptor_to_file (descriptorspec_item * desc , zend_string * file_path ,
777
+ static bool set_proc_descriptor_to_file (descriptorspec_item * desc , zend_string * file_path ,
778
778
zend_string * file_mode )
779
779
{
780
780
php_socket_t fd ;
@@ -783,13 +783,13 @@ static int set_proc_descriptor_to_file(descriptorspec_item *desc, zend_string *f
783
783
php_stream * stream = php_stream_open_wrapper (ZSTR_VAL (file_path ), ZSTR_VAL (file_mode ),
784
784
REPORT_ERRORS |STREAM_WILL_CAST , NULL );
785
785
if (stream == NULL ) {
786
- return FAILURE ;
786
+ return false ;
787
787
}
788
788
789
789
/* force into an fd */
790
790
if (php_stream_cast (stream , PHP_STREAM_CAST_RELEASE |PHP_STREAM_AS_FD , (void * * )& fd ,
791
791
REPORT_ERRORS ) == FAILURE ) {
792
- return FAILURE ;
792
+ return false ;
793
793
}
794
794
795
795
#ifdef PHP_WIN32
@@ -804,30 +804,30 @@ static int set_proc_descriptor_to_file(descriptorspec_item *desc, zend_string *f
804
804
#else
805
805
desc -> childend = fd ;
806
806
#endif
807
- return SUCCESS ;
807
+ return true ;
808
808
}
809
809
810
- static int dup_proc_descriptor (php_file_descriptor_t from , php_file_descriptor_t * to ,
810
+ static bool dup_proc_descriptor (php_file_descriptor_t from , php_file_descriptor_t * to ,
811
811
size_t nindex )
812
812
{
813
813
#ifdef PHP_WIN32
814
814
* to = dup_handle (from , TRUE, FALSE);
815
815
if (* to == NULL ) {
816
816
php_error_docref (NULL , E_WARNING , "Failed to dup() for descriptor %zu" , nindex );
817
- return FAILURE ;
817
+ return false ;
818
818
}
819
819
#else
820
820
* to = dup (from );
821
821
if (* to < 0 ) {
822
822
php_error_docref (NULL , E_WARNING , "Failed to dup() for descriptor %zu: %s" ,
823
823
nindex , strerror (errno ));
824
- return FAILURE ;
824
+ return false ;
825
825
}
826
826
#endif
827
- return SUCCESS ;
827
+ return true ;
828
828
}
829
829
830
- static int redirect_proc_descriptor (descriptorspec_item * desc , int target ,
830
+ static bool redirect_proc_descriptor (descriptorspec_item * desc , int target ,
831
831
descriptorspec_item * descriptors , size_t ndesc , size_t nindex )
832
832
{
833
833
php_file_descriptor_t redirect_to = PHP_INVALID_FD ;
@@ -842,7 +842,7 @@ static int redirect_proc_descriptor(descriptorspec_item *desc, int target,
842
842
if (redirect_to == PHP_INVALID_FD ) { /* Didn't find the index we wanted */
843
843
if (target < 0 || target > 2 ) {
844
844
php_error_docref (NULL , E_WARNING , "Redirection target %d not found" , target );
845
- return FAILURE ;
845
+ return false ;
846
846
}
847
847
848
848
/* Support referring to a stdin/stdout/stderr pipe adopted from the parent,
@@ -863,15 +863,16 @@ static int redirect_proc_descriptor(descriptorspec_item *desc, int target,
863
863
}
864
864
865
865
/* Process one item from `$descriptorspec` argument to `proc_open` */
866
- static int set_proc_descriptor_from_array (zval * descitem , descriptorspec_item * descriptors ,
866
+ static bool set_proc_descriptor_from_array (zval * descitem , descriptorspec_item * descriptors ,
867
867
size_t ndesc , size_t nindex , int * pty_master_fd , int * pty_slave_fd ) {
868
868
zend_string * ztype = get_string_parameter (descitem , 0 , "handle qualifier" );
869
869
if (!ztype ) {
870
- return FAILURE ;
870
+ return false ;
871
871
}
872
872
873
873
zend_string * zmode = NULL , * zfile = NULL ;
874
- int retval = FAILURE ;
874
+ bool retval = false;
875
+
875
876
if (zend_string_equals_literal (ztype , "pipe" )) {
876
877
/* Set descriptor to pipe */
877
878
zmode = get_string_parameter (descitem , 1 , "mode parameter for 'pipe'" );
@@ -923,35 +924,35 @@ static int set_proc_descriptor_from_array(zval *descitem, descriptorspec_item *d
923
924
return retval ;
924
925
}
925
926
926
- static int set_proc_descriptor_from_resource (zval * resource , descriptorspec_item * desc , size_t nindex )
927
+ static bool set_proc_descriptor_from_resource (zval * resource , descriptorspec_item * desc , size_t nindex )
927
928
{
928
929
/* Should be a stream - try and dup the descriptor */
929
930
php_stream * stream = (php_stream * )zend_fetch_resource (Z_RES_P (resource ), "stream" ,
930
931
php_file_le_stream ());
931
932
if (stream == NULL ) {
932
- return FAILURE ;
933
+ return false ;
933
934
}
934
935
935
936
php_socket_t fd ;
936
937
int status = php_stream_cast (stream , PHP_STREAM_AS_FD , (void * * )& fd , REPORT_ERRORS );
937
938
if (status == FAILURE ) {
938
- return FAILURE ;
939
+ return false ;
939
940
}
940
941
941
942
#ifdef PHP_WIN32
942
943
php_file_descriptor_t fd_t = (php_file_descriptor_t )_get_osfhandle (fd );
943
944
#else
944
945
php_file_descriptor_t fd_t = fd ;
945
946
#endif
946
- if (dup_proc_descriptor (fd_t , & desc -> childend , nindex ) == FAILURE ) {
947
- return FAILURE ;
947
+ if (! dup_proc_descriptor (fd_t , & desc -> childend , nindex )) {
948
+ return false ;
948
949
}
949
950
950
- return SUCCESS ;
951
+ return true ;
951
952
}
952
953
953
954
#ifndef PHP_WIN32
954
- static int close_parentends_of_pipes (descriptorspec_item * descriptors , size_t ndesc )
955
+ static bool close_parentends_of_pipes (descriptorspec_item * descriptors , size_t ndesc )
955
956
{
956
957
/* We are running in child process
957
958
* Close the 'parent end' of pipes which were opened before forking/spawning
@@ -965,13 +966,13 @@ static int close_parentends_of_pipes(descriptorspec_item *descriptors, size_t nd
965
966
if (dup2 (descriptors [i ].childend , descriptors [i ].index ) < 0 ) {
966
967
php_error_docref (NULL , E_WARNING , "Unable to copy file descriptor %d (for pipe) into " \
967
968
"file descriptor %d: %s" , descriptors [i ].childend , descriptors [i ].index , strerror (errno ));
968
- return FAILURE ;
969
+ return false ;
969
970
}
970
971
close (descriptors [i ].childend );
971
972
}
972
973
}
973
974
974
- return SUCCESS ;
975
+ return true ;
975
976
}
976
977
#endif
977
978
@@ -1096,12 +1097,12 @@ PHP_FUNCTION(proc_open)
1096
1097
descriptors [ndesc ].index = nindex ;
1097
1098
1098
1099
if (Z_TYPE_P (descitem ) == IS_RESOURCE ) {
1099
- if (set_proc_descriptor_from_resource (descitem , & descriptors [ndesc ], ndesc ) == FAILURE ) {
1100
+ if (! set_proc_descriptor_from_resource (descitem , & descriptors [ndesc ], ndesc )) {
1100
1101
goto exit_fail ;
1101
1102
}
1102
1103
} else if (Z_TYPE_P (descitem ) == IS_ARRAY ) {
1103
- if (set_proc_descriptor_from_array (descitem , descriptors , ndesc , nindex ,
1104
- & pty_master_fd , & pty_slave_fd ) == FAILURE ) {
1104
+ if (! set_proc_descriptor_from_array (descitem , descriptors , ndesc , nindex ,
1105
+ & pty_master_fd , & pty_slave_fd )) {
1105
1106
goto exit_fail ;
1106
1107
}
1107
1108
} else {
@@ -1160,7 +1161,7 @@ PHP_FUNCTION(proc_open)
1160
1161
}
1161
1162
1162
1163
if (!bypass_shell ) {
1163
- if (convert_command_to_use_shell (& cmdw , cmdw_len ) == FAILURE ) {
1164
+ if (! convert_command_to_use_shell (& cmdw , cmdw_len )) {
1164
1165
goto exit_fail ;
1165
1166
}
1166
1167
}
@@ -1188,7 +1189,7 @@ PHP_FUNCTION(proc_open)
1188
1189
if (child == 0 ) {
1189
1190
/* This is the child process */
1190
1191
1191
- if (close_parentends_of_pipes (descriptors , ndesc ) == FAILURE ) {
1192
+ if (! close_parentends_of_pipes (descriptors , ndesc )) {
1192
1193
/* We are already in child process and can't do anything to make
1193
1194
* `proc_open` return an error in the parent
1194
1195
* All we can do is exit with a non-zero (error) exit code */
0 commit comments