-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Closed
Closed
Implement pcntl_waitid #14617
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
1fe4de1
ext/pcntl: Added new function pcntl_waitid
vrza 0483f22
Validate flags, fill siginfo array
vrza ecefc18
Expose needed constants from wait.h
vrza c8ff3b6
Add ifdef guards around WEXITED, WSTOPPED, WNOWAIT
vrza 2dd62b9
Unit tests for pcntl_waitid
vrza 0ccd92f
Throw a ValueError if parameter validation fails
vrza 712b536
Evaluate in numerical order
vrza dfe3bfe
Guard Linux-specific P_PIDFD constant
vrza e23bc2d
Linux-specific iptype validation
vrza 651df1f
Include linux/wait.h on Linux to check for idtype constants
vrza 3ab725d
Leave idtype and flags validation out as it is platform-specific
vrza 93f4fad
Added FreeBSD specific idtypes
vrza ee6b65d
Added NetBSD specific idtypes
vrza 4830687
Added check for linux/wait.h
vrza e3cfd08
Guard pcntl_waitid behind HAVE_WAITID
vrza ba5d347
Test pcntl_waitid failing due to invalid arguments
vrza 324b79c
Pick a better bad value for idtype in test
vrza ab07bc0
Removed unnecessary comments
vrza f01aeb3
Comment on NetBSD specific idtypes
vrza 52fce3d
Renamed variable success to status
vrza d39033a
Made the id param to waitid nullable
vrza 5deaba1
Expect warnings about invalid arguments
vrza e1399cf
More tests, including testing error messages
vrza d173be1
Implemented weak idtype validation
vrza 5793dcd
Added test for weak idtype validation
vrza 509c92f
Added tests with PHP_INT_MAX
vrza 31f3856
Throw ValueError on errno == EINVAL
vrza a0df466
Added test for null id when idtype != P_ALL
vrza 8763548
Moved idtype constants detection to autoconf
vrza 5021e88
Fixed typo in comment
vrza 1bf8873
FreeBSD fixes
vrza 25fc4db
macOS fills in siginfo_t even on no state change
vrza 2df267a
Changed API to closely match wait and waitpid
vrza 9124b1e
AC_CHECK_DECLS for WEXITED, WSTOPPED, WNOWAIT
vrza 80a1da8
Test pcntl_get_last_error()
vrza ea33122
AC_CHECK_DECLS superseded importing linux/wait.h
vrza 5f540d8
Improved m4 code intentation
vrza 595b9c4
Better default params
vrza 0011541
Fixed bad value for zend long
vrza 1993ec1
Stricter preprocessor guards
vrza 19e0612
Updated NEWS
vrza 207ea17
Fixed race condition in unit tests
vrza e69f6c7
Marked unused param with underscore
vrza ed38397
m4 formatting
vrza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 theid
parameter 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_null
value 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.