Skip to content

Commit 2364054

Browse files
authored
ext/pcntl: pcntl_fork refining error handling. (#14021)
1 parent 151a677 commit 2364054

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

ext/pcntl/pcntl.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,26 @@ PHP_FUNCTION(pcntl_fork)
203203
id = fork();
204204
if (id == -1) {
205205
PCNTL_G(last_error) = errno;
206-
php_error_docref(NULL, E_WARNING, "Error %d", errno);
206+
switch (errno) {
207+
case EAGAIN:
208+
php_error_docref(NULL, E_WARNING, "Error %d: Reached the maximum limit of number of processes", errno);
209+
break;
210+
case ENOMEM:
211+
php_error_docref(NULL, E_WARNING, "Error %d: Insufficient memory", errno);
212+
break;
213+
// unlikely, especially nowadays.
214+
case ENOSYS:
215+
php_error_docref(NULL, E_WARNING, "Error %d: Unimplemented", errno);
216+
break;
217+
// QNX is the only platform returning it so far and is a different case from EAGAIN.
218+
// Retries can be handled with sleep eventually.
219+
case EBADF:
220+
php_error_docref(NULL, E_WARNING, "Error %d: File descriptor concurrency issue", errno);
221+
break;
222+
default:
223+
php_error_docref(NULL, E_WARNING, "Error %d", errno);
224+
225+
}
207226
} else if (id == 0) {
208227
zend_max_execution_timer_init();
209228
}

0 commit comments

Comments
 (0)