Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Apr 2012 13:44:04 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r234844 - in stable/8/sys: kern sys
Message-ID:  <201204301344.q3UDi4Sx068392@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Mon Apr 30 13:44:04 2012
New Revision: 234844
URL: http://svn.freebsd.org/changeset/base/234844

Log:
  MFC r234616:
  Allow for the process information sysctls to accept a thread id in addition
  to the process id.

Modified:
  stable/8/sys/kern/kern_proc.c
  stable/8/sys/sys/proc.h
Directory Properties:
  stable/8/sys/   (props changed)

Modified: stable/8/sys/kern/kern_proc.c
==============================================================================
--- stable/8/sys/kern/kern_proc.c	Mon Apr 30 13:37:07 2012	(r234843)
+++ stable/8/sys/kern/kern_proc.c	Mon Apr 30 13:44:04 2012	(r234844)
@@ -301,6 +301,30 @@ pfind(pid)
 	return (p);
 }
 
+static struct proc *
+pfind_tid(pid_t tid)
+{
+	struct proc *p;
+	struct thread *td;
+
+	sx_slock(&allproc_lock);
+	FOREACH_PROC_IN_SYSTEM(p) {
+		PROC_LOCK(p);
+		if (p->p_state == PRS_NEW) {
+			PROC_UNLOCK(p);
+			continue;
+		}
+		FOREACH_THREAD_IN_PROC(p, td) {
+			if (td->td_tid == tid)
+				goto found;
+		}
+		PROC_UNLOCK(p);
+	}
+found:
+	sx_sunlock(&allproc_lock);
+	return (p);
+}
+
 /*
  * Locate a process group by number.
  * The caller must hold proctree_lock.
@@ -331,7 +355,12 @@ pget(pid_t pid, int flags, struct proc *
 	struct proc *p;
 	int error;
 
-	p = pfind(pid);
+	if (pid <= PID_MAX)
+		p = pfind(pid);
+	else if ((flags & PGET_NOTID) == 0)
+		p = pfind_tid(pid);
+	else
+		p = NULL;
 	if (p == NULL)
 		return (ESRCH);
 	if ((flags & PGET_CANSEE) != 0) {

Modified: stable/8/sys/sys/proc.h
==============================================================================
--- stable/8/sys/sys/proc.h	Mon Apr 30 13:37:07 2012	(r234843)
+++ stable/8/sys/sys/proc.h	Mon Apr 30 13:44:04 2012	(r234844)
@@ -816,6 +816,7 @@ struct	proc *zpfind(pid_t);		/* Find zom
 #define	PGET_ISCURRENT	0x00008	/* Check that the found process is current. */
 #define	PGET_NOTWEXIT	0x00010	/* Check that the process is not in P_WEXIT. */
 #define	PGET_NOTINEXEC	0x00020	/* Check that the process is not in P_INEXEC. */
+#define	PGET_NOTID	0x00040	/* Do not assume tid if pid > PID_MAX. */
 
 #define	PGET_WANTREAD	(PGET_HOLD | PGET_CANDEBUG | PGET_NOTWEXIT)
 



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