Source-Changes-HG archive

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

[src/trunk]: src/sys Split p_xstat (composite wait(2) status code, or signal ...



details:   https://anonhg.NetBSD.org/src/rev/a7f657f32ec1
branches:  trunk
changeset: 344565:a7f657f32ec1
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Apr 04 20:47:57 2016 +0000

description:
Split p_xstat (composite wait(2) status code, or signal number depending
on context) into:
1. p_xexit:             exit code
2. p_xsig:              signal number
3. p_sflag & WCOREFLAG  bit to indicated that the process core-dumped.

Fix the documentation of the flag bits in <sys/proc.h>

diffstat:

 sys/kern/kern_event.c              |   7 ++--
 sys/kern/kern_exec.c               |   8 ++--
 sys/kern/kern_exit.c               |  54 +++++++++++++++++++++----------------
 sys/kern/kern_lwp.c                |   8 ++--
 sys/kern/kern_proc.c               |   6 ++--
 sys/kern/kern_sig.c                |  32 +++++++++++-----------
 sys/kern/kern_synch.c              |   6 ++--
 sys/kern/sys_process.c             |   8 ++--
 sys/miscfs/procfs/procfs_ctl.c     |   6 ++--
 sys/rump/librump/rumpkern/lwproc.c |   6 ++--
 sys/sys/proc.h                     |  20 +++++++++----
 11 files changed, 88 insertions(+), 73 deletions(-)

diffs (truncated from 615 to 300 lines):

diff -r 799cd578439b -r a7f657f32ec1 sys/kern/kern_event.c
--- a/sys/kern/kern_event.c     Mon Apr 04 20:43:31 2016 +0000
+++ b/sys/kern/kern_event.c     Mon Apr 04 20:47:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_event.c,v 1.85 2016/01/31 04:40:01 christos Exp $ */
+/*     $NetBSD: kern_event.c,v 1.86 2016/04/04 20:47:57 christos Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -58,11 +58,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.85 2016/01/31 04:40:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.86 2016/04/04 20:47:57 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
+#include <sys/wait.h>
 #include <sys/proc.h>
 #include <sys/file.h>
 #include <sys/select.h>
@@ -551,7 +552,7 @@
                struct proc *p = kn->kn_obj;
 
                if (p != NULL)
-                       kn->kn_data = p->p_xstat;
+                       kn->kn_data = P_WAITSTATUS(p);
                /*
                 * Process is gone, so flag the event as finished.
                 *
diff -r 799cd578439b -r a7f657f32ec1 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Mon Apr 04 20:43:31 2016 +0000
+++ b/sys/kern/kern_exec.c      Mon Apr 04 20:47:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.424 2016/03/20 14:58:10 khorben Exp $  */
+/*     $NetBSD: kern_exec.c,v 1.425 2016/04/04 20:47:57 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.424 2016/03/20 14:58:10 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.425 2016/04/04 20:47:57 christos Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1350,7 +1350,7 @@
        /* Acquire the sched-state mutex (exit1() will release it). */
        if (!is_spawn) {
                mutex_enter(p->p_lock);
-               exit1(l, W_EXITCODE(error, SIGABRT));
+               exit1(l, error, SIGABRT, 0);
        }
 
        return error;
@@ -2229,7 +2229,7 @@
         * A NetBSD specific workaround is POSIX_SPAWN_RETURNERROR as
         * flag bit in the attrp argument to posix_spawn(2), see above.
         */
-       exit1(l, W_EXITCODE(127, 0));
+       exit1(l, 127, 0, 0);
 }
 
 void
diff -r 799cd578439b -r a7f657f32ec1 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Mon Apr 04 20:43:31 2016 +0000
+++ b/sys/kern/kern_exit.c      Mon Apr 04 20:47:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exit.c,v 1.251 2016/04/03 23:50:49 christos Exp $ */
+/*     $NetBSD: kern_exit.c,v 1.252 2016/04/04 20:47:57 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.251 2016/04/03 23:50:49 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.252 2016/04/04 20:47:57 christos Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -138,14 +138,19 @@
 
        KSI_INIT(ksi);
        if ((ksi->ksi_signo = P_EXITSIG(p)) == SIGCHLD) {
-               if (WIFSIGNALED(p->p_xstat)) {
-                       if (WCOREDUMP(p->p_xstat))
+               if (p->p_xsig) {
+                       if (p->p_sflag & PS_COREDUMP)
                                ksi->ksi_code = CLD_DUMPED;
                        else
                                ksi->ksi_code = CLD_KILLED;
+                       ksi->ksi_status = p->p_xsig;
                } else {
                        ksi->ksi_code = CLD_EXITED;
+                       ksi->ksi_status = p->p_xexit;
                }
+       } else {
+               ksi->ksi_code = SI_USER;
+               ksi->ksi_status = p->p_xsig;
        }
        /*
         * We fill those in, even for non-SIGCHLD.
@@ -153,7 +158,6 @@
         */
        ksi->ksi_pid = p->p_pid;
        ksi->ksi_uid = kauth_cred_geteuid(p->p_cred);
-       ksi->ksi_status = p->p_xstat;
        /* XXX: is this still valid? */
        ksi->ksi_utime = p->p_stats->p_ru.ru_utime.tv_sec;
        ksi->ksi_stime = p->p_stats->p_ru.ru_stime.tv_sec;
@@ -179,7 +183,7 @@
        }
 
        /* exit1() will release the mutex. */
-       exit1(l, W_EXITCODE(SCARG(uap, rval), 0));
+       exit1(l, SCARG(uap, rval), 0, 0);
        /* NOTREACHED */
        return (0);
 }
@@ -192,7 +196,7 @@
  * Must be called with p->p_lock held.  Does not return.
  */
 void
-exit1(struct lwp *l, int rv)
+exit1(struct lwp *l, int exitcode, int signo, int coredump)
 {
        struct proc     *p, *child, *next_child, *old_parent, *new_parent;
        struct pgrp     *pgrp;
@@ -206,8 +210,7 @@
        KASSERT(p->p_vmspace != NULL);
 
        if (__predict_false(p == initproc)) {
-               panic("init died (signal %d, exit %d)",
-                   WTERMSIG(rv), WEXITSTATUS(rv));
+               panic("init died (signal %d, exit %d)", signo, exitcode);
        }
 
        p->p_sflag |= PS_WEXIT;
@@ -269,7 +272,7 @@
         */
        rw_enter(&p->p_reflock, RW_WRITER);
 
-       DPRINTF(("exit1: %d.%d exiting.\n", p->p_pid, l->l_lid));
+       DPRINTF(("%s: %d.%d exiting.\n", __func__, p->p_pid, l->l_lid));
 
        timers_free(p, TIMERS_ALL);
 #if defined(__HAVE_RAS)
@@ -302,13 +305,17 @@
        }
 #endif
 
+       p->p_xexit = exitcode;
+       p->p_xsig = signo;
+       if (coredump)
+               p->p_sflag |= PS_COREDUMP;
+
        /*
         * If emulation has process exit hook, call it now.
         * Set the exit status now so that the exit hook has
         * an opportunity to tweak it (COMPAT_LINUX requires
         * this for thread group emulation)
         */
-       p->p_xstat = rv;
        if (p->p_emul->e_proc_exit)
                (*p->p_emul->e_proc_exit)(p);
 
@@ -423,8 +430,8 @@
        KNOTE(&p->p_klist, NOTE_EXIT);
 
        SDT_PROBE(proc, kernel, , exit,
-               (WCOREDUMP(rv) ? CLD_DUMPED :
-                (WIFSIGNALED(rv) ? CLD_KILLED : CLD_EXITED)),
+               ((p->p_sflag & PS_COREDUMP) ? CLD_DUMPED :
+                (p->p_xsig ? CLD_KILLED : CLD_EXITED)),
                0,0,0,0);
 
 #if PERFCTRS
@@ -869,15 +876,15 @@
                 *  This is still a rough estimate.  We will fix the
                 *  cases TRAPPED, STOPPED, and CONTINUED later.
                 */
-               if (WCOREDUMP(p->p_xstat)) {
+               if (p->p_sflag & PS_COREDUMP) {
                        siginfo->si_code = CLD_DUMPED;
-                       siginfo->si_status = WTERMSIG(p->p_xstat);
-               } else if (WIFSIGNALED(p->p_xstat)) {
+                       siginfo->si_status = p->p_xsig;
+               } else if (p->p_xsig) {
                        siginfo->si_code = CLD_KILLED;
-                       siginfo->si_status = WTERMSIG(p->p_xstat);
+                       siginfo->si_status = p->p_xsig;
                } else {
                        siginfo->si_code = CLD_EXITED;
-                       siginfo->si_status = WEXITSTATUS(p->p_xstat);
+                       siginfo->si_status = p->p_xexit;
                }
 
                siginfo->si_pid = p->p_pid;
@@ -991,13 +998,13 @@
                        }
 
                        if ((options & WCONTINUED) != 0 &&
-                           child->p_xstat == SIGCONT) {
+                           child->p_xsig == SIGCONT) {
                                if ((options & WNOWAIT) == 0) {
                                        child->p_waited = 1;
                                        parent->p_nstopchild--;
                                }
                                if (si) {
-                                       si->si_status = child->p_xstat;
+                                       si->si_status = child->p_xsig;
                                        si->si_code = CLD_CONTINUED;
                                }
                                break;
@@ -1013,7 +1020,7 @@
                                        parent->p_nstopchild--;
                                }
                                if (si) {
-                                       si->si_status = child->p_xstat;
+                                       si->si_status = child->p_xsig;
                                        si->si_code = 
                                            (child->p_slflag & PSL_TRACED) ?
                                            CLD_TRAPPED : CLD_STOPPED;
@@ -1030,7 +1037,7 @@
                if (child != NULL || error != 0 ||
                    ((options & WNOHANG) != 0 && dead == NULL)) {
                        if (child != NULL) {
-                               *status_p = child->p_xstat;
+                               *status_p = child->p_xsig;
                        }
                        *child_p = child;
                        return error;
@@ -1109,7 +1116,8 @@
                wru->wru_self = p->p_stats->p_ru;
                wru->wru_children = p->p_stats->p_cru;
        }
-       p->p_xstat = 0;
+       p->p_xsig = 0;
+       p->p_xexit = 0;
 
        /*
         * At this point we are going to start freeing the final resources. 
diff -r 799cd578439b -r a7f657f32ec1 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Mon Apr 04 20:43:31 2016 +0000
+++ b/sys/kern/kern_lwp.c       Mon Apr 04 20:47:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lwp.c,v 1.182 2015/11/26 13:15:34 martin Exp $    */
+/*     $NetBSD: kern_lwp.c,v 1.183 2016/04/04 20:47:57 christos Exp $  */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -211,7 +211,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.182 2015/11/26 13:15:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.183 2016/04/04 20:47:57 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -509,7 +509,7 @@
        if (l->l_wchan == NULL) {
                /* setrunnable() will release the lock. */
                setrunnable(l);
-       } else if (p->p_xstat && (l->l_flag & LW_SINTR) != 0) {
+       } else if (p->p_xsig && (l->l_flag & LW_SINTR) != 0) {
                /* setrunnable() so we can receive the signal */
                setrunnable(l);
        } else {
@@ -1043,7 +1043,7 @@
                KASSERT(current == true);
                KASSERT(p != &proc0);
                /* XXXSMP kernel_lock not held */
-               exit1(l, 0);
+               exit1(l, 0, 0, 0);
                /* NOTREACHED */
        }
        p->p_nzlwps++;
diff -r 799cd578439b -r a7f657f32ec1 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c      Mon Apr 04 20:43:31 2016 +0000
+++ b/sys/kern/kern_proc.c      Mon Apr 04 20:47:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_proc.c,v 1.194 2015/09/24 14:33:01 christos Exp $ */
+/*     $NetBSD: kern_proc.c,v 1.195 2016/04/04 20:47:57 christos Exp $ */
 
 /*-
  * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.194 2015/09/24 14:33:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.195 2016/04/04 20:47:57 christos Exp $");
 



Home | Main Index | Thread Index | Old Index