Skip to content

Commit 14bb2aa

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/pcntl: fix pcntl_setns() error handling.
2 parents 4c65b3e + e2a5909 commit 14bb2aa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ext/pcntl/pcntl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ PHP_FUNCTION(pcntl_setns)
16311631

16321632
pid = pid_is_null ? getpid() : pid;
16331633
fd = syscall(SYS_pidfd_open, pid, 0);
1634-
if (errno) {
1634+
if (fd == -1) {
16351635
PCNTL_G(last_error) = errno;
16361636
switch (errno) {
16371637
case EINVAL:
@@ -1657,11 +1657,12 @@ PHP_FUNCTION(pcntl_setns)
16571657
RETURN_FALSE;
16581658
}
16591659
ret = setns(fd, (int)nstype);
1660+
int setns_errno = errno;
16601661
close(fd);
16611662

16621663
if (ret == -1) {
1663-
PCNTL_G(last_error) = errno;
1664-
switch (errno) {
1664+
PCNTL_G(last_error) = setns_errno;
1665+
switch (setns_errno) {
16651666
case ESRCH:
16661667
zend_argument_value_error(1, "process no longer available (" ZEND_LONG_FMT ")", pid);
16671668
RETURN_THROWS();
@@ -1671,11 +1672,11 @@ PHP_FUNCTION(pcntl_setns)
16711672
RETURN_THROWS();
16721673

16731674
case EPERM:
1674-
php_error_docref(NULL, E_WARNING, "Error %d: No required capability for this process", errno);
1675+
php_error_docref(NULL, E_WARNING, "Error %d: No required capability for this process", setns_errno);
16751676
break;
16761677

16771678
default:
1678-
php_error_docref(NULL, E_WARNING, "Error %d", errno);
1679+
php_error_docref(NULL, E_WARNING, "Error %d", setns_errno);
16791680
}
16801681
RETURN_FALSE;
16811682
} else {

0 commit comments

Comments
 (0)