From: claudio Date: Thu, 21 Sep 2023 13:49:25 +0000 (+0000) Subject: Move code inside exit1() to better spots. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2efc32385a6a8a5e5ab185e59496e32e1b1381e1;p=openbsd Move code inside exit1() to better spots. - PS_PROFIL bit is moved into the process cleanup block where it belongs - The proc read-only limit cache cleanup is moved up right after clearing p->p_fd cache. lim_free() can potentially sleep and so needs to be above the line where p_stat is set to SDEAD. With and OK jca@ --- diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 4d7bfd5fddb..f57d48415ef 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.215 2023/09/13 14:25:49 claudio Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.216 2023/09/21 13:49:25 claudio Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -165,8 +165,6 @@ exit1(struct proc *p, int xexit, int xsig, int flags) /* main thread gotta wait because it has the pid, et al */ while (pr->ps_threadcnt > 1) tsleep_nsec(&pr->ps_threads, PWAIT, "thrdeath", INFSLP); - if (pr->ps_flags & PS_PROFIL) - stopprofclock(pr); } rup = pr->ps_ru; @@ -190,6 +188,9 @@ exit1(struct proc *p, int xexit, int xsig, int flags) #endif if ((p->p_flag & P_THREAD) == 0) { + if (pr->ps_flags & PS_PROFIL) + stopprofclock(pr); + sigio_freelist(&pr->ps_sigiolst); /* close open files and release open-file table */ @@ -224,6 +225,15 @@ exit1(struct proc *p, int xexit, int xsig, int flags) p->p_fd = NULL; /* zap the thread's copy */ + /* Release the thread's read reference of resource limit structure. */ + if (p->p_limit != NULL) { + struct plimit *limit; + + limit = p->p_limit; + p->p_limit = NULL; + lim_free(limit); + } + /* * Remove proc from pidhash chain and allproc so looking * it up won't work. We will put the proc on the @@ -342,15 +352,6 @@ exit1(struct proc *p, int xexit, int xsig, int flags) KASSERT(pr->ps_threadcnt > 0); } - /* Release the thread's read reference of resource limit structure. */ - if (p->p_limit != NULL) { - struct plimit *limit; - - limit = p->p_limit; - p->p_limit = NULL; - lim_free(limit); - } - /* * Other substructures are freed from reaper and wait(). */