From owner-p4-projects@FreeBSD.ORG Sun Jan 18 15:50:45 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AE3751065676; Sun, 18 Jan 2009 15:50:44 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6990E1065672 for ; Sun, 18 Jan 2009 15:50:44 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 3BE9D8FC1D for ; Sun, 18 Jan 2009 15:50:44 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0IFoiJY083106 for ; Sun, 18 Jan 2009 15:50:44 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0IFohGJ083104 for perforce@freebsd.org; Sun, 18 Jan 2009 15:50:43 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sun, 18 Jan 2009 15:50:43 GMT Message-Id: <200901181550.n0IFohGJ083104@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 156334 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Jan 2009 15:50:47 -0000 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 #include #include +#include #include #include #include @@ -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 */