From owner-freebsd-bugs@FreeBSD.ORG Fri Nov 15 15:30:01 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E8C691AE for ; Fri, 15 Nov 2013 15:30:00 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id CB9A720C5 for ; Fri, 15 Nov 2013 15:30:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id rAFFU0s8091695 for ; Fri, 15 Nov 2013 15:30:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id rAFFU0Ah091686; Fri, 15 Nov 2013 15:30:00 GMT (envelope-from gnats) Resent-Date: Fri, 15 Nov 2013 15:30:00 GMT Resent-Message-Id: <201311151530.rAFFU0Ah091686@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitrijs Ledkovs Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E4A50FE7 for ; Fri, 15 Nov 2013 15:28:12 +0000 (UTC) Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BA2E220B1 for ; Fri, 15 Nov 2013 15:28:12 +0000 (UTC) Received: from oldred.freebsd.org ([127.0.1.6]) by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id rAFFSCnc079940 for ; Fri, 15 Nov 2013 15:28:12 GMT (envelope-from nobody@oldred.freebsd.org) Received: (from nobody@localhost) by oldred.freebsd.org (8.14.5/8.14.5/Submit) id rAFFSCQ2079936; Fri, 15 Nov 2013 15:28:12 GMT (envelope-from nobody) Message-Id: <201311151528.rAFFSCQ2079936@oldred.freebsd.org> Date: Fri, 15 Nov 2013 15:28:12 GMT From: Dmitrijs Ledkovs To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: misc/184002: wait6 / waitid returns wrong value in siginfo.si_status X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Nov 2013 15:30:01 -0000 >Number: 184002 >Category: misc >Synopsis: wait6 / waitid returns wrong value in siginfo.si_status >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Nov 15 15:30:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Dmitrijs Ledkovs >Release: 9.2, 10 >Organization: Debian >Environment: GNU/kFreeBSD kfree 10.0-0-amd64 #0 Fri Aug 2 21:27:23 CEST 2013 x86_64 amd64 QEMU Virtual CPU version 1.6.1 GNU/kFreeBSD >Description: As per http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html siginfo_t.si_status is "Exit value or signal." The waitid call is suppose to fill in siginfo_t structure if one was passed to the function http://pubs.opengroup.org/onlinepubs/9699919799/functions/waitid.html Instead at the moment the returned siginfo_t.si_status of FreeBSD is same on as &status returned by waitpid() call. I.E. value which hasn't been extraced with WEXITSTATUS() >How-To-Repeat: The below program should not assert. #include #include #include #include int main() { siginfo_t siginfo; pid_t pid = -1; pid = fork (); if (pid > 0) { waitid (P_PID, pid, &siginfo, WEXITED | WNOWAIT); assert (siginfo.si_code == CLD_EXITED); assert (siginfo.si_status == 123); } else if (pid == 0) { exit (123); } } >Fix: Untested patch against kfreebsd-source-10.0/sys/kern/kern_exit.c --- kern_exit.c.orig 2013-11-15 15:23:25.000000000 +0000 +++ kern_exit.c 2013-11-15 15:26:26.000000000 +0000 @@ -975,16 +975,18 @@ * cases TRAPPED, STOPPED, and CONTINUED later. */ if (WCOREDUMP(p->p_xstat)) siginfo->si_code = CLD_DUMPED; - else if (WIFSIGNALED(p->p_xstat)) + else if (WIFSIGNALED(p->p_xstat)) { siginfo->si_code = CLD_KILLED; - else + siginfo->si_status = WTERMSIG(p->p_xstat); + } else { siginfo->si_code = CLD_EXITED; + siginfo->si_status = WEXITSTATUS(p->p_xstat); + } siginfo->si_pid = p->p_pid; siginfo->si_uid = p->p_ucred->cr_uid; - siginfo->si_status = p->p_xstat; /* * The si_addr field would be useful additional * detail, but apparently the PC value may be lost >Release-Note: >Audit-Trail: >Unformatted: