Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Nov 2017 18:04:40 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325721 - in head/sys: kern sys
Message-ID:  <201711111804.vABI4e6H038060@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Sat Nov 11 18:04:39 2017
New Revision: 325721
URL: https://svnweb.freebsd.org/changeset/base/325721

Log:
  Add pfind_any
  
  It looks for both regular and zombie processes. This avoids allproc relocking
  previously seen with pfind -> zpfind calls.

Modified:
  head/sys/kern/kern_event.c
  head/sys/kern/kern_proc.c
  head/sys/kern/kern_sig.c
  head/sys/sys/proc.h

Modified: head/sys/kern/kern_event.c
==============================================================================
--- head/sys/kern/kern_event.c	Sat Nov 11 18:03:26 2017	(r325720)
+++ head/sys/kern/kern_event.c	Sat Nov 11 18:04:39 2017	(r325721)
@@ -406,16 +406,15 @@ filt_procattach(struct knote *kn)
 	bool exiting, immediate;
 
 	exiting = immediate = false;
-	p = pfind(kn->kn_id);
-	if (p == NULL && (kn->kn_sfflags & NOTE_EXIT)) {
-		p = zpfind(kn->kn_id);
-		exiting = true;
-	} else if (p != NULL && (p->p_flag & P_WEXIT)) {
-		exiting = true;
-	}
-
+	if (kn->kn_sfflags & NOTE_EXIT)
+		p = pfind_any(kn->kn_id);
+	else
+		p = pfind(kn->kn_id);
 	if (p == NULL)
 		return (ESRCH);
+	if (p->p_flag & P_WEXIT)
+		exiting = true;
+
 	if ((error = p_cansee(curthread, p))) {
 		PROC_UNLOCK(p);
 		return (error);

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Sat Nov 11 18:03:26 2017	(r325720)
+++ head/sys/kern/kern_proc.c	Sat Nov 11 18:04:39 2017	(r325721)
@@ -353,6 +353,23 @@ pfind(pid_t pid)
 	return (p);
 }
 
+/*
+ * Same as pfind but allow zombies.
+ */
+struct proc *
+pfind_any(pid_t pid)
+{
+	struct proc *p;
+
+	sx_slock(&allproc_lock);
+	p = pfind_locked(pid);
+	if (p == NULL)
+		p = zpfind_locked(pid);
+	sx_sunlock(&allproc_lock);
+
+	return (p);
+}
+
 static struct proc *
 pfind_tid_locked(pid_t tid)
 {

Modified: head/sys/kern/kern_sig.c
==============================================================================
--- head/sys/kern/kern_sig.c	Sat Nov 11 18:03:26 2017	(r325720)
+++ head/sys/kern/kern_sig.c	Sat Nov 11 18:04:39 2017	(r325721)
@@ -1765,10 +1765,8 @@ sys_kill(struct thread *td, struct kill_args *uap)
 
 	if (uap->pid > 0) {
 		/* kill single process */
-		if ((p = pfind(uap->pid)) == NULL) {
-			if ((p = zpfind(uap->pid)) == NULL)
-				return (ESRCH);
-		}
+		if ((p = pfind_any(uap->pid)) == NULL)
+			return (ESRCH);
 		AUDIT_ARG_PROCESS(p);
 		error = p_cansignal(td, p, uap->signum);
 		if (error == 0 && uap->signum)

Modified: head/sys/sys/proc.h
==============================================================================
--- head/sys/sys/proc.h	Sat Nov 11 18:03:26 2017	(r325720)
+++ head/sys/sys/proc.h	Sat Nov 11 18:04:39 2017	(r325721)
@@ -954,6 +954,7 @@ extern struct proc *initproc, *pageproc; /* Process sl
 extern struct uma_zone *proc_zone;
 
 struct	proc *pfind(pid_t);		/* Find process by id. */
+struct	proc *pfind_any(pid_t);		/* Find (zombie) process by id. */
 struct	proc *pfind_locked(pid_t pid);
 struct	pgrp *pgfind(pid_t);		/* Find process group by id. */
 struct	proc *zpfind(pid_t);		/* Find zombie process by id. */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711111804.vABI4e6H038060>