From d00c8ea42945820f55fa7290e85707cb26df4cb3 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Tue, 1 Jul 2014 06:29:15 +0000 Subject: [PATCH] Perform a lockless check in sigacts_shared. It is used only during execve (i.e. singlethreaded), so there is no fear of returning 'not shared' which soon becomes 'shared'. While here reorganize the code a little to avoid proc lock/unlock in shared case. MFC after: 1 week --- sys/kern/kern_exec.c | 9 ++++----- sys/kern/kern_sig.c | 6 +----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 53182db530b..91d161d91fe 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -621,18 +621,17 @@ do_execve(td, args, mac_p) * handlers. In execsigs(), the new process will have its signals * reset. */ - PROC_LOCK(p); - oldcred = crcopysafe(p, newcred); if (sigacts_shared(p->p_sigacts)) { oldsigacts = p->p_sigacts; - PROC_UNLOCK(p); newsigacts = sigacts_alloc(); sigacts_copy(newsigacts, oldsigacts); - PROC_LOCK(p); - p->p_sigacts = newsigacts; } else oldsigacts = NULL; + PROC_LOCK(p); + if (oldsigacts) + p->p_sigacts = newsigacts; + oldcred = crcopysafe(p, newcred); /* Stop profiling */ stopprofclock(p); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 67845a25d1b..7ec48893556 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -3453,10 +3453,6 @@ sigacts_copy(struct sigacts *dest, struct sigacts *src) int sigacts_shared(struct sigacts *ps) { - int shared; - mtx_lock(&ps->ps_mtx); - shared = ps->ps_refcnt > 1; - mtx_unlock(&ps->ps_mtx); - return (shared); + return (ps->ps_refcnt > 1); }