Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Jan 2009 15:50:43 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 156334 for review
Message-ID:  <200901181550.n0IFohGJ083104@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=156334

Change 156334 by rwatson@rwatson_freebsd_capabilities on 2009/01/18 15:50:26

	Update comments, implement a weak procdesc_stat() function that
	leaves quite a bit to be desired.

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/sys/kern/sys_procdesc.c#5 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/sys_procdesc.c#5 (text+ko) ====

@@ -45,9 +45,9 @@
  * - At most one process descriptor will exist for any process, although
  *   references to that descriptor may be held from many processes (or even
  *   be in flight between processes over a local domain socket).
- * - Closing the process descriptor will terminate the process using SIGKILL
- *   and reparent it to init so that there's a process to reap it when it's
- *   done exiting.
+ * - Last close on the process descriptor will terminate the process using
+ *   SIGKILL and reparent it to init so that there's a process to reap it
+ *   when it's done exiting.
  * - If the process exits before the descriptor is closed, it will not
  *   generate SIGCHLD on termination, or be picked up by waitpid().
  * - The pdkill(2) system call may be used to deliver a signal to the process
@@ -58,7 +58,7 @@
  * Open questions:
  *
  * - How to handle ptrace(2)?
- * - Will we want to add a pidtoprocdesc(2) system call to allow procee
+ * - Will we want to add a pidtoprocdesc(2) system call to allow process
  *   descriptors to be created for processes without pfork(2)?
  */
 
@@ -78,6 +78,7 @@
 #include <sys/poll.h>
 #include <sys/proc.h>
 #include <sys/procdesc.h>
+#include <sys/stat.h>
 #include <sys/sysproto.h>
 #include <sys/sysctl.h>
 #include <sys/systm.h>
@@ -414,8 +415,26 @@
 procdesc_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
     struct thread *td)
 {
+	struct procdesc *pd;
 
-	return (EOPNOTSUPP);
+	/*
+	 * XXXRW: Perhaps we should cache some more information from the
+	 * process so that we can return it reliably here even after it has
+	 * died.  For example, caching its credential data.
+	 */
+	bzero(sb, sizeof(*sb));
+	pd = (struct procdesc *)fp->f_data;
+	sx_slock(&proctree_lock);
+	if (pd->pd_proc != NULL) {
+		sb->st_mode = S_IFREG | S_IRWXU;
+		PROC_LOCK(pd->pd_proc);
+		sb->st_uid = pd->pd_proc->p_ucred->cr_ruid;
+		sb->st_gid = pd->pd_proc->p_ucred->cr_rgid;
+		PROC_UNLOCK(pd->pd_proc);
+	} else
+		sb->st_mode = S_IFREG;
+	sx_sunlock(&proctree_lock);
+	return (0);
 }
 
 #else /* !PROCDESC */



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