NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/51606: wait4() (and friends) with WNOHANG and no children does not error



>Number:         51606
>Category:       standards
>Synopsis:       wait4() (and friends) with WNOHANG and no children does not error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 06 14:30:00 +0000 2016
>Originator:     Robert Elz
>Release:        NetBSD 7.99.42  (current of today, probably since April)
>Organization:
>Environment:
	(irrelevant, this is from the system running send-pr ...)
System: NetBSD andromeda.noi.kre.to 7.99.36 NetBSD 7.99.36 (VBOX64-1.1-20160831) #49: Thu Sep 1 02:41:07 ICT 2016 kre%onyx.coe.psu.ac.th@localhost:/usr/obj/current/kernels/amd64/VBOX64 amd64
Architecture: x86_64
Machine: amd64
>Description:
	POSIX says (of waitpid - which is wait4() without the rusage arg)

|| If waitpid( ) was invoked with WNOHANG set in options, it has at least
|| one child process specified by pid for which status is not available,
|| and status is not available for any process specified by pid, 0 is returned.
|| Otherwise, -1 shall be returned, and errno set to indicate the error.

	and

|| The waitpid( ) function shall fail if:
||     [ECHILD] The process specified by pid does not exist or is not a
||		child of the calling process, or the process group specified
||		by pid does not exist or does not have any member process
||		that is a child of the calling process.

Currently, on NetBSD (since wait6() and waitid() were added)
wait4() (and consequently waitpid()) return 0 in this case (which
is what should happen if there is a process, but it is just not
ready to be awaited yet.).

This is reported as not broken in NetBSD 7 (ie: it acts correctly there.)

>How-To-Repeat:
	This code from Nicolas Joly...

#include <sys/wait.h>

#include <assert.h>
#include <errno.h>

int main() {
  pid_t pid;
  int e;

  pid = wait4(-1, NULL, 0, NULL);
  assert(pid == -1 && errno == ECHILD);
  pid = wait4(-1, NULL, WNOHANG, NULL);
  assert(pid == -1 && errno == ECHILD);
}

	Observe the 2nd assert, when pid == 0, instead of the
	expected -1.

>Fix:
	Working on it...

	One issue is that the posix spec is not nearly as clear as
	to what should happen in a similar case using waitid() instead
	of waitpid() ...

	I sent a query to the austin list to gather opinions.



Home | Main Index | Thread Index | Old Index