From: Arnaud Le Blanc Date: Tue, 4 Nov 2008 21:05:55 +0000 (+0000) Subject: MFH: Open STDIN and php://stdin streams with the relevant X-Git-Tag: php-5.2.7RC3~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be8c7c09884124641fa02b90ecee7c914ac14206;p=php MFH: Open STDIN and php://stdin streams with the relevant wrapper when the file descriptor is a socket (inetd, etc) Fixes bug #43731 --- diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index b3772d5cac..fcf6078a46 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -290,9 +290,23 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch return NULL; } +#if defined(S_IFSOCK) && !defined(WIN32) && !defined(__BEOS__) + do { + struct stat st; + memset(&st, 0, sizeof(st)); + if (fstat(fd, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { + stream = php_stream_sock_open_from_socket(fd, NULL); + if (stream) { + stream->ops = &php_stream_socket_ops; + return stream; + } + } + } while (0); +#endif + if (file) { stream = php_stream_fopen_from_file(file, mode); - } else { + } else { stream = php_stream_fopen_from_fd(fd, mode, NULL); if (stream == NULL) { close(fd); diff --git a/sapi/cli/tests/022.inc b/sapi/cli/tests/022.inc new file mode 100644 index 0000000000..b77512fcf3 --- /dev/null +++ b/sapi/cli/tests/022.inc @@ -0,0 +1,14 @@ + diff --git a/sapi/cli/tests/022.phpt b/sapi/cli/tests/022.phpt new file mode 100644 index 0000000000..eabb8bdf8d --- /dev/null +++ b/sapi/cli/tests/022.phpt @@ -0,0 +1,47 @@ +--TEST-- +STDIN/OUT/ERR stream type +--SKIPIF-- + +--FILE-- + $socket, + 1 => STDOUT, + 2 => STDERR, +); +$pipes = array(); +$proc = proc_open("$php -n " . escapeshellarg($test_file), $desc, $pipes); +var_dump($proc); +if (!$proc) { + exit(1); +} + +$client_socket = stream_socket_client('unix://' . $socket_file); +var_dump($client_socket); +echo stream_get_contents($client_socket); +fclose($client_socket); + +proc_terminate($proc); +proc_close($proc); +unlink($socket_file); +?> +--EXPECTF-- +resource(%d) of type (stream) +resource(%d) of type (process) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream)