Skip to content

Commit f80a5d4

Browse files
committed
Fix interrupted CLI output causing the process to exit
When writing the output in the CLI is interrupted by a signal, the writing will fail in sapi_cli_single_write(), causing an exit later in sapi_cli_ub_write(). This was the other part of the issue in GH-11498. The solution is to restart the write if an EINTR has been observed.
1 parent 039dd0b commit f80a5d4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sapi/cli/php_cli.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ PHP_CLI_API ssize_t sapi_cli_single_write(const char *str, size_t str_length) /*
261261

262262
#ifdef PHP_WRITE_STDOUT
263263
do {
264+
errno = 0;
264265
ret = write(STDOUT_FILENO, str, str_length);
265-
} while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO));
266+
} while (ret <= 0 && (errno == EINTR || (errno == EAGAIN && sapi_cli_select(STDOUT_FILENO))));
266267
#else
267268
ret = fwrite(str, 1, MIN(str_length, 16384), stdout);
268269
if (ret == 0 && ferror(stdout)) {

0 commit comments

Comments
 (0)