Skip to content

Commit 4506432

Browse files
committed
Address code review
1 parent 99c1b79 commit 4506432

File tree

8 files changed

+79
-10
lines changed

8 files changed

+79
-10
lines changed

ext/pcntl/pcntl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,9 @@ PHP_FUNCTION(pcntl_signal)
895895
if (signo < 1) {
896896
zend_argument_value_error(1, "must be greater than or equal to 1");
897897
RETURN_THROWS();
898-
} else if (signo >= NSIG) {
898+
}
899+
900+
if (signo >= NSIG) {
899901
zend_argument_value_error(1, "must be less than %d", NSIG);
900902
RETURN_THROWS();
901903
}
@@ -1201,7 +1203,7 @@ PHP_FUNCTION(pcntl_getpriority)
12011203
php_error_docref(NULL, E_WARNING, "Error %d: No process was located using the given parameters", errno);
12021204
break;
12031205
case EINVAL:
1204-
zend_argument_value_error(2, "must be a valid identifier flag");
1206+
zend_argument_value_error(2, "must be one of PRIO_PGRP, PRIO_USER, or PRIO_PROCESS");
12051207
RETURN_THROWS();
12061208
default:
12071209
php_error_docref(NULL, E_WARNING, "Unknown error %d has occurred", errno);
@@ -1235,7 +1237,7 @@ PHP_FUNCTION(pcntl_setpriority)
12351237
php_error_docref(NULL, E_WARNING, "Error %d: No process was located using the given parameters", errno);
12361238
break;
12371239
case EINVAL:
1238-
zend_argument_value_error(3, "must be a valid identifier flag");
1240+
zend_argument_value_error(3, "must be one of PRIO_PGRP, PRIO_USER, or PRIO_PROCESS");
12391241
RETURN_THROWS();
12401242
break;
12411243
case EPERM:
@@ -1415,7 +1417,7 @@ PHP_FUNCTION(pcntl_unshare)
14151417
switch (errno) {
14161418
#ifdef EINVAL
14171419
case EINVAL:
1418-
zend_argument_value_error(1, "must be a valid identifier flag");
1420+
zend_argument_value_error(1, "must be a combination of CLONE_* flags");
14191421
RETURN_THROWS();
14201422
break;
14211423
#endif

ext/pcntl/pcntl.stub.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function pcntl_wait(&$status, int $options = 0, &$rusage = []): int {}
1919
/** @param callable|int $handler */
2020
function pcntl_signal(int $signo, $handler, bool $restart_syscalls = true): bool {}
2121

22-
function pcntl_signal_get_handler(int $signo): mixed {}
22+
/** @return callable|int */
23+
function pcntl_signal_get_handler(int $signo) {}
2324

2425
function pcntl_signal_dispatch(): bool {}
2526

ext/pcntl/pcntl_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 79f0005cda5f8bc55a913c8d2c8791699abc2f0f */
2+
* Stub hash: 306208d94ba3bf6f8112f868a332e99717bc07fa */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pcntl_fork, 0, 0, IS_LONG, 0)
55
ZEND_END_ARG_INFO()
@@ -23,7 +23,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pcntl_signal, 0, 2, _IS_BOOL, 0)
2323
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, restart_syscalls, _IS_BOOL, 0, "true")
2424
ZEND_END_ARG_INFO()
2525

26-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pcntl_signal_get_handler, 0, 1, IS_MIXED, 0)
26+
ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_signal_get_handler, 0, 0, 1)
2727
ZEND_ARG_TYPE_INFO(0, signo, IS_LONG, 0)
2828
ZEND_END_ARG_INFO()
2929

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
pcntl_getpriority() - Wrong process identifier
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pcntl')) {
6+
die('skip ext/pcntl not loaded');
7+
}
8+
if (!function_exists('pcntl_getpriority')) {
9+
die('skip pcntl_getpriority doesn\'t exist');
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
15+
try {
16+
pcntl_getpriority(null, 42);
17+
} catch (ValueError $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
20+
21+
?>
22+
--EXPECT--
23+
pcntl_getpriority(): Argument #2 ($process_identifier) must be one of PRIO_PGRP, PRIO_USER, or PRIO_PROCESS
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
pcntl_setpriority() - Wrong process identifier
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pcntl')) {
6+
die('skip ext/pcntl not loaded');
7+
}
8+
if (!function_exists('pcntl_setpriority')) {
9+
die('skip pcntl_setpriority doesn\'t exist');
10+
}
11+
?>
12+
--FILE--
13+
<?php
14+
15+
try {
16+
pcntl_setpriority(0, null, 42);
17+
} catch (ValueError $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
20+
21+
?>
22+
--EXPECT--
23+
pcntl_setpriority(): Argument #3 ($process_identifier) must be one of PRIO_PGRP, PRIO_USER, or PRIO_PROCESS

ext/pcntl/tests/pcntl_unshare_01.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ if (!extension_loaded("posix")) die("skip posix extension not available");
77
if (!function_exists("pcntl_unshare")) die("skip pcntl_unshare is not available");
88
if (!defined("CLONE_NEWUSER")) die("skip flag unavailable");
99
if (@pcntl_unshare(CLONE_NEWUSER) == false && pcntl_get_last_error() == PCNTL_EPERM) {
10-
die("skip Insufficient previleges to use CLONE_NEWUSER");
10+
die("skip Insufficient privileges to use CLONE_NEWUSER");
1111
}
12-
12+
?>
1313
--FILE--
1414
<?php
1515

ext/pcntl/tests/pcntl_unshare_02.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (posix_getuid() !== 0 &&
1515
if (@pcntl_unshare(CLONE_NEWPID) == false && pcntl_get_last_error() == PCNTL_EPERM) {
1616
die("skip Insufficient privileges for CLONE_NEWPID");
1717
}
18-
18+
?>
1919
--FILE--
2020
<?php
2121

ext/pcntl/tests/pcntl_unshare_04.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
pcntl_unshare() with wrong flag
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("pcntl")) die("skip");
6+
if (!extension_loaded("posix")) die("skip posix extension not available");
7+
if (!function_exists("pcntl_unshare")) die("skip pcntl_unshare is not available");
8+
?>
9+
--FILE--
10+
<?php
11+
12+
try {
13+
pcntl_unshare(42);
14+
} catch (ValueError $exception) {
15+
echo $exception->getMessage() . "\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
pcntl_unshare(): Argument #1 ($flags) must be a combination of CLONE_* flags

0 commit comments

Comments
 (0)