From 91611de0ffa89bf74d84042b160447b64ce617eb Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 26 Jun 2020 12:35:02 +0900 Subject: [PATCH] waitid: implement WNOHANG If there's no child status available immediately, return 0 without blocking as specified by the standards. I checked the following version of the standard. I believe it has always been this way though. The Open Group Base Specifications Issue 7, 2018 edition IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008) --- sched/sched/sched_waitid.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sched/sched/sched_waitid.c b/sched/sched/sched_waitid.c index e310fbbf16f..2b8590dc556 100644 --- a/sched/sched/sched_waitid.c +++ b/sched/sched/sched_waitid.c @@ -311,6 +311,22 @@ int nx_waitid(int idtype, id_t id, FAR siginfo_t *info, int options) } #endif + if ((options & WNOHANG) != 0) + { + /* SUSv4 says: + * + * "If waitid() returns because WNOHANG was specified and status + * is not available for any process specified by idtype and id, + * then the si_signo and si_pid members of the structure pointed + * to by infop shall be set to zero and the values of other + * members of the structure are unspecified." + */ + + info->si_signo = 0; + info->si_pid = 0; + break; + } + /* Wait for any death-of-child signal */ ret = nxsig_waitinfo(&set, info);