[Midnightbsd-cvs] src [7804] trunk/sys/sys/proc.h: In pget(9), if PGET_NOTWEXIT flag is not specified, also search the
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Mon Sep 5 22:56:10 EDT 2016
Revision: 7804
http://svnweb.midnightbsd.org/src/?rev=7804
Author: laffer1
Date: 2016-09-05 22:56:10 -0400 (Mon, 05 Sep 2016)
Log Message:
-----------
In pget(9), if PGET_NOTWEXIT flag is not specified, also search the
zombie list for the pid. This allows several kern.proc sysctls to
report useful information for zombies.
Hold the allproc_lock around all searches instead of relocking it.
Remove private pfind_locked() from the new nfs client code.
Look for zombie process only if we were given process id.
Obtained from: FreeBSD
Modified Paths:
--------------
trunk/sys/fs/nfsclient/nfs_clport.c
trunk/sys/kern/kern_proc.c
trunk/sys/sys/proc.h
Property Changed:
----------------
trunk/sys/fs/nfsclient/nfs.h
trunk/sys/fs/nfsclient/nfs_clbio.c
trunk/sys/fs/nfsclient/nfs_clcomsubs.c
trunk/sys/fs/nfsclient/nfs_clkdtrace.c
trunk/sys/fs/nfsclient/nfs_clkrpc.c
trunk/sys/fs/nfsclient/nfs_clnfsiod.c
trunk/sys/fs/nfsclient/nfs_clnode.c
trunk/sys/fs/nfsclient/nfs_clport.c
Index: trunk/sys/fs/nfsclient/nfs.h
===================================================================
--- trunk/sys/fs/nfsclient/nfs.h 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs.h 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs.h
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Index: trunk/sys/fs/nfsclient/nfs_clbio.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clbio.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clbio.c 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs_clbio.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Index: trunk/sys/fs/nfsclient/nfs_clcomsubs.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clcomsubs.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clcomsubs.c 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs_clcomsubs.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Index: trunk/sys/fs/nfsclient/nfs_clkdtrace.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clkdtrace.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clkdtrace.c 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs_clkdtrace.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Index: trunk/sys/fs/nfsclient/nfs_clkrpc.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clkrpc.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clkrpc.c 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs_clkrpc.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Index: trunk/sys/fs/nfsclient/nfs_clnfsiod.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clnfsiod.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clnfsiod.c 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs_clnfsiod.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Index: trunk/sys/fs/nfsclient/nfs_clnode.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clnode.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clnode.c 2016-09-06 02:56:10 UTC (rev 7804)
Property changes on: trunk/sys/fs/nfsclient/nfs_clnode.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Modified: trunk/sys/fs/nfsclient/nfs_clport.c
===================================================================
--- trunk/sys/fs/nfsclient/nfs_clport.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/fs/nfsclient/nfs_clport.c 2016-09-06 02:56:10 UTC (rev 7804)
@@ -1150,31 +1150,6 @@
}
/*
- * Locate a process by number; return only "live" processes -- i.e., neither
- * zombies nor newly born but incompletely initialized processes. By not
- * returning processes in the PRS_NEW state, we allow callers to avoid
- * testing for that condition to avoid dereferencing p_ucred, et al.
- * Identical to pfind() in kern_proc.c, except it assume the list is
- * already locked.
- */
-static struct proc *
-pfind_locked(pid_t pid)
-{
- struct proc *p;
-
- LIST_FOREACH(p, PIDHASH(pid), p_hash)
- if (p->p_pid == pid) {
- PROC_LOCK(p);
- if (p->p_state == PRS_NEW) {
- PROC_UNLOCK(p);
- p = NULL;
- }
- break;
- }
- return (p);
-}
-
-/*
* Check to see if the process for this owner exists. Return 1 if it doesn't
* and 0 otherwise.
*/
Property changes on: trunk/sys/fs/nfsclient/nfs_clport.c
___________________________________________________________________
Deleted: cvs2svn:cvs-rev
## -1 +0,0 ##
-1.2
\ No newline at end of property
Modified: trunk/sys/kern/kern_proc.c
===================================================================
--- trunk/sys/kern/kern_proc.c 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/kern/kern_proc.c 2016-09-06 02:56:10 UTC (rev 7804)
@@ -136,6 +136,7 @@
static int proc_init(void *mem, int size, int flags);
static void proc_fini(void *mem, int size);
static void pargs_free(struct pargs *pa);
+static struct proc *zpfind_locked(pid_t pid);
/*
* Other process lists
@@ -283,20 +284,13 @@
return (1);
}
-/*
- * Locate a process by number; return only "live" processes -- i.e., neither
- * zombies nor newly born but incompletely initialized processes. By not
- * returning processes in the PRS_NEW state, we allow callers to avoid
- * testing for that condition to avoid dereferencing p_ucred, et al.
- */
struct proc *
-pfind(pid)
- register pid_t pid;
+pfind_locked(pid_t pid)
{
- register struct proc *p;
+ struct proc *p;
- sx_slock(&allproc_lock);
- LIST_FOREACH(p, PIDHASH(pid), p_hash)
+ sx_assert(&allproc_lock, SX_LOCKED);
+ LIST_FOREACH(p, PIDHASH(pid), p_hash) {
if (p->p_pid == pid) {
PROC_LOCK(p);
if (p->p_state == PRS_NEW) {
@@ -305,17 +299,34 @@
}
break;
}
+ }
+ return (p);
+}
+
+/*
+ * Locate a process by number; return only "live" processes -- i.e., neither
+ * zombies nor newly born but incompletely initialized processes. By not
+ * returning processes in the PRS_NEW state, we allow callers to avoid
+ * testing for that condition to avoid dereferencing p_ucred, et al.
+ */
+struct proc *
+pfind(pid_t pid)
+{
+ struct proc *p;
+
+ sx_slock(&allproc_lock);
+ p = pfind_locked(pid);
sx_sunlock(&allproc_lock);
return (p);
}
static struct proc *
-pfind_tid(pid_t tid)
+pfind_tid_locked(pid_t tid)
{
struct proc *p;
struct thread *td;
- sx_slock(&allproc_lock);
+ sx_assert(&allproc_lock, SX_LOCKED);
FOREACH_PROC_IN_SYSTEM(p) {
PROC_LOCK(p);
if (p->p_state == PRS_NEW) {
@@ -329,7 +340,6 @@
PROC_UNLOCK(p);
}
found:
- sx_sunlock(&allproc_lock);
return (p);
}
@@ -363,12 +373,17 @@
struct proc *p;
int error;
- if (pid <= PID_MAX)
- p = pfind(pid);
- else if ((flags & PGET_NOTID) == 0)
- p = pfind_tid(pid);
- else
+ sx_slock(&allproc_lock);
+ if (pid <= PID_MAX) {
+ p = pfind_locked(pid);
+ if (p == NULL && (flags & PGET_NOTWEXIT) == 0)
+ p = zpfind_locked(pid);
+ } else if ((flags & PGET_NOTID) == 0) {
+ p = pfind_tid_locked(pid);
+ } else {
p = NULL;
+ }
+ sx_sunlock(&allproc_lock);
if (p == NULL)
return (ESRCH);
if ((flags & PGET_CANSEE) != 0) {
@@ -1049,6 +1064,21 @@
free(ps, M_SUBPROC);
}
+static struct proc *
+zpfind_locked(pid_t pid)
+{
+ struct proc *p;
+
+ sx_assert(&allproc_lock, SX_LOCKED);
+ LIST_FOREACH(p, &zombproc, p_list) {
+ if (p->p_pid == pid) {
+ PROC_LOCK(p);
+ break;
+ }
+ }
+ return (p);
+}
+
/*
* Locate a zombie process by number
*/
@@ -1058,11 +1088,7 @@
struct proc *p;
sx_slock(&allproc_lock);
- LIST_FOREACH(p, &zombproc, p_list)
- if (p->p_pid == pid) {
- PROC_LOCK(p);
- break;
- }
+ p = zpfind_locked(pid);
sx_sunlock(&allproc_lock);
return (p);
}
Modified: trunk/sys/sys/proc.h
===================================================================
--- trunk/sys/sys/proc.h 2016-09-06 02:50:18 UTC (rev 7803)
+++ trunk/sys/sys/proc.h 2016-09-06 02:56:10 UTC (rev 7804)
@@ -832,6 +832,7 @@
extern struct uma_zone *proc_zone;
struct proc *pfind(pid_t); /* Find 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. */
More information about the Midnightbsd-cvs
mailing list