summaryrefslogtreecommitdiff
path: root/sys/kern/kern_exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/kern_exit.c')
-rw-r--r--sys/kern/kern_exit.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 2c9e2e4..9377eed 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -30,6 +30,7 @@
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/syslog.h>
+#include <sys/atomic.h>
#include <sys/panic.h>
#include <sys/filedesc.h>
#include <sys/vnode.h>
@@ -44,6 +45,9 @@
#define pr_trace(fmt, ...) kprintf("exit: " fmt, ##__VA_ARGS__)
#define pr_error(...) pr_trace(__VA_ARGS__)
+extern volatile size_t g_nthreads;
+extern struct proc g_init;
+
static void
unload_td(struct proc *td)
{
@@ -147,14 +151,17 @@ exit1(struct proc *td, int flags)
curtd = this_td();
curpid = curtd->pid;
+
td->flags |= PROC_EXITING;
parent = td->parent;
- /* If we have any children, kill them too */
+ /* We have one less process in the system! */
+ atomic_dec_64(&g_nthreads);
+
+ /* Reassign children to init */
if (td->nleaves > 0) {
TAILQ_FOREACH(procp, &td->leafq, leaf_link) {
- if (!ISSET(procp->flags, PROC_EXITING))
- exit1(procp, flags);
+ procp->parent = &g_init;
}
}