Skip to content

Commit ecc1a7c

Browse files
robberphexcmb69
authored andcommitted
Fix bug #44217: Output after stdout/stderr closed cause immediate exit with status 0
We exit with status 255 instead.
1 parent 84d7d4e commit ecc1a7c

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #76427 (Segfault in zend_objects_store_put). (Laruence)
77
. Fixed bug #76422 (ftruncate fails on files > 2GB). (Anatol)
88

9+
- CLI:
10+
. Fixed bug #44217 (Output after stdout/stderr closed cause immediate exit
11+
with status 0). (Robert Lu)
12+
913
- Date:
1014
. Fixed bug #76462 (Undefined property: DateInterval::$f). (Anatol)
1115

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PHP 7.3 INTERNALS UPGRADE NOTES
1717
n. IS_TYPE_COPYABLE
1818
o. IS_UNUSED
1919
p. VM instruction operands (FETCH_CLASS, FETCH_CONSTANT, CATCH)
20+
q. sapi_cli_single_write()
2021

2122
2. Build system changes
2223
a. Unix build system changes
@@ -123,6 +124,8 @@ PHP 7.3 INTERNALS UPGRADE NOTES
123124
- FETCH_CONSTANT op1<fetch-flags>, op2<name>, result<tmp>
124125
- CATCH ext<last-flag>, op1<name>, op2<jump_addr>, result<cv>
125126

127+
q. sapi_cli_single_write() now returns ssize_t instead of size_t.
128+
126129
========================
127130
2. Build system changes
128131
========================

sapi/cli/cli.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#endif
3131

3232

33-
extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length);
33+
extern PHP_CLI_API ssize_t sapi_cli_single_write(const char *str, size_t str_length);
3434

3535
typedef struct {
3636
size_t (*cli_shell_write)(const char *str, size_t str_length);

sapi/cli/php_cli.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,9 @@ static inline int sapi_cli_select(php_socket_t fd)
267267
return ret != -1;
268268
}
269269

270-
PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length) /* {{{ */
270+
PHP_CLI_API ssize_t sapi_cli_single_write(const char *str, size_t str_length) /* {{{ */
271271
{
272-
#ifdef PHP_WRITE_STDOUT
273-
zend_long ret;
274-
#else
275-
size_t ret;
276-
#endif
272+
ssize_t ret;
277273

278274
if (cli_shell_callbacks.cli_shell_write) {
279275
cli_shell_callbacks.cli_shell_write(str, str_length);
@@ -283,24 +279,18 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length) /*
283279
do {
284280
ret = write(STDOUT_FILENO, str, str_length);
285281
} while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO));
286-
287-
if (ret <= 0) {
288-
return 0;
289-
}
290-
291-
return ret;
292282
#else
293283
ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
294-
return ret;
295284
#endif
285+
return ret;
296286
}
297287
/* }}} */
298288

299289
static size_t sapi_cli_ub_write(const char *str, size_t str_length) /* {{{ */
300290
{
301291
const char *ptr = str;
302292
size_t remaining = str_length;
303-
size_t ret;
293+
ssize_t ret;
304294

305295
if (!str_length) {
306296
return 0;
@@ -317,8 +307,9 @@ static size_t sapi_cli_ub_write(const char *str, size_t str_length) /* {{{ */
317307
while (remaining > 0)
318308
{
319309
ret = sapi_cli_single_write(ptr, remaining);
320-
if (!ret) {
310+
if (ret < 0) {
321311
#ifndef PHP_CLI_WIN32_NO_CONSOLE
312+
EG(exit_status) = 255;
322313
php_handle_aborted_connection();
323314
#endif
324315
break;

0 commit comments

Comments
 (0)