CHROMIUM: test_initctl: Block while reaping

Extend the solution from https://crrev.com/c/5447915 to include
blocking.

The use of nih_child_poll() in the above CL  looks essentially like:

  // During Upstart's quiesce:
  kill (job_pid, SIGKILL);

  // In the test logic, via nih_child_poll():
  while (waitid (P_ALL, 0, &info, WEXITED | WNOHANG) == 0) {
    if (info.st_pid == 0)
      break;
    ...
  }

Importantly, there's a time period between kill() and waitid() when
|job_pid| has not yet exited -- even the unmaskable SIGKILL signal takes
some time for the kernel to process it. And due to WNOHANG, waitid()
will also not wait for it, and the reaping procedure may fail.

We need to truly wait*() on this job_pid, either by dropping WNOHANG or
some equivalent procedure. We can leverage our timed_waitpid() for this.

This should resolve still-more instances of this flaky failure:

  ...system shutdown: 2 jobs (1 long-running job which ignores SIGTERM, 1 which starts on session-end and ignores SIGTERM)
  BAD: wrong value for kill (job_pid, 0), expected -1 got 0
	  at tests/test_initctl.c:12080 (test_quiesce).

BUG=b:232122437
TEST=unit tests under load
TEST=unit tests in CQ

Change-Id: I94ca006b02609b7d1f8b8dfe8b74bd4c87c1afbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/upstart/+/5539069
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Allen Webb <allenwebb@google.com>
Commit-Queue: Brian Norris <briannorris@chromium.org>
1 file changed