NetBSD Problem Report #51606

From kre@munnari.OZ.AU  Sun Nov  6 14:28:10 2016
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id AE73A7A219
	for <gnats-bugs@www.NetBSD.org>; Sun,  6 Nov 2016 14:28:10 +0000 (UTC)
Message-Id: <201611061427.uA6ERxVX005433@andromeda.noi.kre.to>
Date: Sun, 6 Nov 2016 21:27:59 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@www.NetBSD.org
Subject: wait4() (and friends) with WNOHANG and no children does not error
X-Send-Pr-Version: 3.95

>Number:         51606
>Category:       standards
>Synopsis:       wait4() (and friends) with WNOHANG and no children does not error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 06 14:30:00 +0000 2016
>Closed-Date:    Wed Nov 09 01:06:05 +0000 2016
>Last-Modified:  Wed Nov 09 01:06:05 +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:/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.

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: standards-manager->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Sun, 06 Nov 2016 14:51:25 +0000
Responsible-Changed-Why:
I am looking into this PR


From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51606 CVS commit: src
Date: Sun, 6 Nov 2016 15:03:31 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Sun Nov  6 15:03:31 UTC 2016

 Modified Files:
 	src/distrib/sets/lists/debug: mi
 	src/distrib/sets/lists/tests: mi
 Added Files:
 	src/tests/lib/libc/sys: t_wait_noproc.c t_wait_noproc_wnohang.c

 Log Message:
 Add new tests: tests/lib/libc/sys/t_wait_noproc and t_wait_noproc_wnohang

 The t_wait_noproc test checks whether wait(2)-family of functions return
 error and set ECHILD for lack of childs.

 The t_wait_noproc_wnohang adds to options (except wait(2), wait3(2)) new
 parameter WNOHANG and verifies that error is still signaled and errno set
 to ECHILD.

 Currently t_wait_noproc_wnohang reports failures, these have been marked as
 expected and referenced to PR standards/51606.

 The problem report is authored by Robert Elz, and the initial regression
 has been notified by Nicolas Joly.

 Remove redundant test in tests/lib/libc/sys/t_wait for wait6(2) with no
 WNOHANG specified.

 Sponsored by <The NetBSD Foundation>.


 To generate a diff of this commit:
 cvs rdiff -u -r1.170 -r1.171 src/distrib/sets/lists/debug/mi
 cvs rdiff -u -r1.692 -r1.693 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_wait_noproc.c \
     src/tests/lib/libc/sys/t_wait_noproc_wnohang.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51606 CVS commit: src/tests/lib/libc/sys
Date: Sun, 6 Nov 2016 15:04:14 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Sun Nov  6 15:04:14 UTC 2016

 Modified Files:
 	src/tests/lib/libc/sys: Makefile t_wait.c

 Log Message:
 Add new tests: tests/lib/libc/sys/t_wait_noproc and t_wait_noproc_wnohang

 The t_wait_noproc test checks whether wait(2)-family of functions return
 error and set ECHILD for lack of childs.

 The t_wait_noproc_wnohang adds to options (except wait(2), wait3(2)) new
 parameter WNOHANG and verifies that error is still signaled and errno set
 to ECHILD.

 Currently t_wait_noproc_wnohang reports failures, these have been marked as
 expected and referenced to PR standards/51606.

 The problem report is authored by Robert Elz, and the initial regression
 has been notified by Nicolas Joly.

 Remove redundant test in tests/lib/libc/sys/t_wait for wait6(2) with no
 WNOHANG specified.

 Sponsored by <The NetBSD Foundation>.


 To generate a diff of this commit:
 cvs rdiff -u -r1.43 -r1.44 src/tests/lib/libc/sys/Makefile
 cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/sys/t_wait.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Kamil Rytarowski" <kamil@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51606 CVS commit: src/tests/lib/libc/sys
Date: Mon, 7 Nov 2016 02:23:43 +0000

 Module Name:	src
 Committed By:	kamil
 Date:		Mon Nov  7 02:23:43 UTC 2016

 Modified Files:
 	src/tests/lib/libc/sys: t_wait_noproc.c

 Log Message:
 Enable the wait3 test in t_wait_noproc_wnohang (through t_wait_noproc)

 This test has set expected failure like other functions in the wait(2)
 family and is linked with PR standards/51606.

 The PR is labeled as:
     wait4() (and friends) with WNOHANG and no children does not error

 Originally, this test was accidently disabled in the WNOHANG checks. This
 was noted by Robert Elz.

 Sponsored by <The NetBSD Foundation>.


 To generate a diff of this commit:
 cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_wait_noproc.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/51606 CVS commit: src/sys/kern
Date: Wed, 9 Nov 2016 00:30:17 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Wed Nov  9 00:30:17 UTC 2016

 Modified Files:
 	src/sys/kern: kern_exit.c

 Log Message:
 PR kern/51600 ; PR standards/51606

 Revert 1.264 - that was intended to fix 51600, but didn't, it just
 hid the problem, and caused 51606.  This fixes 51606.

 Handle waiting on a process that has been detatched from its parent
 because of being ptrace'd by some other process.  This fixes 51600.
 ("handle" here means that the wait() hangs, or with WNOHANG, returns 0,
 we cannot actually wait on a process that is not currently an attached
 child.)

 Note: the detatched process waiting is not yet perfect (it fails to
 take account of options like WALLSIG and WALTSIG) - suport for those
 (that is, ignoring a detatched child that one of those options will
 later cause to be ignored when the process is re-attached.)

 For now, for ither than when waiting for a specific process ID, when
 a process does a wait() sys call (any of them), has no applicable
 children attached that can be returned, and has at least one detatched
 child, then we do a linear search of all processes to look for a
 suitable detatched child.  This is likely to be slow - but very rare.
 Eventually it might be better to keep a list of detatched children
 per process.


 To generate a diff of this commit:
 cvs rdiff -u -r1.264 -r1.265 src/sys/kern/kern_exit.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Wed, 09 Nov 2016 01:06:05 +0000
State-Changed-Why:
Problem fixed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.