PERFORCE change 156334 for review
Robert Watson
rwatson at FreeBSD.org
Sun Jan 18 07:50:47 PST 2009
http://perforce.freebsd.org/chv.cgi?CH=156334
Change 156334 by rwatson at 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 */
More information about the p4-projects
mailing list