-
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
Implement pcntl_waitid #14617
Conversation
Note: you can perfectly add non standard flags but you need to make sure they exist before defining them
FreeBSD has its own non standard flags if you want to add them too. Once you fixed all, we need a test for this. |
@devnexen Thanks for the quick review! I addressed your comments (ValueErrors, unit test, guard for the Linux speciifc P_PIDFD), please take another look. |
I see the progress but take your time :) I ll have a look later. |
starting to look good, but I ll let it rest enough days to give a chance to other reviewers :). |
Please review this patch, it is done and tested to work on:
Error handling is done in POSIX style, by accessing [1] On macOS, though, existence of |
The FreeBSD failing test seems legit. |
@petk what do you think build system wise ? |
@devnexen Right, there was a race condition in the test. Fixed it, thanks for noticing and raising. On a related note, in multiple other unit tests there are guards that skip them on FreeBSD. I suspect many of them could also be due to incorrect (buggy) test code. For example, there is an issue in pcntl/tests/002.phpt, that was silenced by Nikita Popov in 2021:
I took a quick look at that test code, looks like a race condition (SIGTERM can be sent too early). I could fix that one as well, but as a separate issue/PR. |
Build system changes look very good and professional. Even nicely checked those |
@petk Thanks for reviewing 🤝 The aim is to be strict and explicit about requirements, but flexible about the way they are provisioned. Regarding m4 formatting... Starting with a disclaimer that this is purely a cosmetic discussion with no impact to functionality... Some of those m4 lines are very long, I'd like to break them up somewhere for readability, popping the includes out seemed like a nice place to break the line, although the list of declarations is also rather long. Eventually includes turned out to be a short, unprotected, one-liner. Perhaps a compromise, with Lisp-style trailing braces:
|
Perfect. Yes that's how I was thinking also. :D |
Looking ok by me, cc @kocsismate |
While this is in review I started working on documentation. |
Looks reasonable |
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.
Since it targets master, we can always improve/fix upon if needs be. I ll merge it in few days if no disagreement arise in the meantime.
ZEND_PARSE_PARAMETERS_START(0, 4) | ||
Z_PARAM_OPTIONAL | ||
Z_PARAM_LONG(idtype) | ||
Z_PARAM_LONG_OR_NULL(id, id_is_null) |
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 the id
parameter will be ignored in the characteristic case of idtype = P_ALL
, it can allow PHP programmers to better express their intent and help readability.
For example, compare:
pcntl_waitid(P_ALL, null, $info);
with
pcntl_waitid(P_ALL, 0, $info);
or even
pcntl_waitid(P_ALL, 42, $info);
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.
Thanks for the elaborate answer! I support the decision fully, it just looked weird at the first sight that |
No problem, thanks for taking the time to review the code. There's a follow up PR, that adds a non-POSIX rusage parameter on systems that support it, that could also benefit from some additional eyeballs on it. |
Closes #14616
To round out the support for the "wait" family of functions this PR adds the
pcntl_waitid
function.Here's the POSIX reference to
waitid
:https://pubs.opengroup.org/onlinepubs/9699919799/functions/waitid.html
Since status information struct is shared with
sigwaitinfo
, relevant code frompcntl_sigwaitinfo
has been reused.Note to maintainers: if this patch is accepted, I'll be happy to provide the English documentation in the follow-up PR.