Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8.1k
Implement pcntl_waitid#14617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Implement pcntl_waitid #14617
Changes from all commits
1fe4de10483f22ecefc18c8ff3b62dd62b90ccd92f712b536dfe3bfee23bc2d651df1f3ab725d93f4fadee6b65d4830687e3cfd08ba5d347324b79cab07bc0f01aeb352fce3dd39033a5deaba1e1399cfd173be15793dcd509c92f31f3856a0df46687635485021e881bf887325fc4db2df267a9124b1e80a1da8ea331225f540d8595b9c400115411993ec119e0612207ea17e69f6c7ed38397File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,6 +25,82 @@ | ||
| */ | ||
| const WCONTINUED = UNKNOWN; | ||
| #endif | ||
| #if defined (HAVE_DECL_WEXITED) && HAVE_DECL_WEXITED == 1 | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(WEXITED) | ||
| */ | ||
| const WEXITED = UNKNOWN; | ||
| #endif | ||
| #if defined (HAVE_DECL_WSTOPPED) && HAVE_DECL_WSTOPPED == 1 | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(WSTOPPED) | ||
| */ | ||
| const WSTOPPED = UNKNOWN; | ||
| #endif | ||
| #if defined (HAVE_DECL_WNOWAIT) && HAVE_DECL_WNOWAIT== 1 | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(WNOWAIT) | ||
| */ | ||
| const WNOWAIT = UNKNOWN; | ||
| #endif | ||
| #ifdef HAVE_WAITID | ||
| /* First argument to waitid */ | ||
| #ifdef HAVE_POSIX_IDTYPES | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_ALL) | ||
| */ | ||
| const P_ALL = UNKNOWN; | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_PID) | ||
| */ | ||
| const P_PID = UNKNOWN; | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_PGID) | ||
| */ | ||
| const P_PGID = UNKNOWN; | ||
| #endif | ||
| /* Linux specific idtype */ | ||
| #ifdef HAVE_LINUX_IDTYPES | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_PIDFD) | ||
| */ | ||
| const P_PIDFD = UNKNOWN; | ||
vrza marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| #endif | ||
| /* NetBSD specific idtypes */ | ||
| #ifdef HAVE_NETBSD_IDTYPES | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_UID) | ||
| */ | ||
| const P_UID = UNKNOWN; | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_GID) | ||
| */ | ||
| const P_GID = UNKNOWN; | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_SID) | ||
| */ | ||
| const P_SID = UNKNOWN; | ||
| #endif | ||
| /* FreeBSD specific idtype */ | ||
| #ifdef HAVE_FREEBSD_IDTYPES | ||
| /** | ||
| * @var int | ||
| * @cvalue LONG_CONST(P_JAILID) | ||
| */ | ||
| const P_JAILID = UNKNOWN; | ||
| #endif | ||
| #endif | ||
| /* Signal Constants */ | ||
| @@ -927,6 +1003,11 @@ function pcntl_fork(): int {} | ||
| */ | ||
| function pcntl_waitpid(int $process_id, &$status, int $flags = 0, &$resource_usage = []): int {} | ||
| #if defined (HAVE_WAITID) && defined (HAVE_POSIX_IDTYPES) && defined (HAVE_DECL_WEXITED) && HAVE_DECL_WEXITED == 1 | ||
| /** @param array $info */ | ||
| function pcntl_waitid(int $idtype = P_ALL, ?int $id = null, &$info = [], int $flags = WEXITED): bool {} | ||
| #endif | ||
| /** | ||
| * @param int $status | ||
| * @param array $resource_usage | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| --TEST-- | ||
| pcntl_waitid() | ||
| --EXTENSIONS-- | ||
| pcntl | ||
| posix | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!function_exists('pcntl_waitid')) die('skip pcntl_waitid unavailable'); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| $pid = pcntl_fork(); | ||
| if ($pid == -1) { | ||
| die("failed"); | ||
| } else if ($pid) { | ||
| // invalid flags | ||
| var_dump(pcntl_waitid(P_PID, $pid, $siginfo, 0)); | ||
| var_dump(pcntl_get_last_error() == PCNTL_EINVAL); | ||
| var_dump(pcntl_waitid(P_PID, $pid, $siginfo, WSTOPPED)); | ||
| posix_kill($pid, SIGCONT); | ||
| var_dump(pcntl_waitid(P_PID, $pid, $siginfo, WCONTINUED)); | ||
| posix_kill($pid, SIGUSR1); | ||
| var_dump(pcntl_waitid(P_PID, $pid, $siginfo, WEXITED)); | ||
| var_dump($siginfo["status"]); | ||
| } else { | ||
| pcntl_signal(SIGUSR1, function ($_signo, $_siginfo) { exit(42); }); | ||
| posix_kill(posix_getpid(), SIGSTOP); | ||
| pcntl_signal_dispatch(); | ||
| sleep(42); | ||
| pcntl_signal_dispatch(); | ||
| exit(6); | ||
| } | ||
| ?> | ||
| --EXPECTF-- | ||
| bool(false) | ||
| bool(true) | ||
| bool(true) | ||
| bool(true) | ||
| bool(true) | ||
| int(42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this parameter nullable? Apparently, it's not used anywhere.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minor style point. From the API design standpoint it's not strictly necessary to allow
id = null, but since theidparameter will be ignored in the characteristic case ofidtype = P_ALL, it can allow PHP programmers to better express their intent and help readability.For example, compare:
with
or even
They all do the same thing, but IMHO the first version best communicates to the person reading the PHP code that we don't really care about the value of the second param (
id).In the C code, the
id_is_nullvalue is not used anywhere, as passing 0 to the system call will suffice, but I'm not sure if it's possible to allow a parameter to be null without using this Z_PARAM_LONG_OR_NULL macro.