summaryrefslogtreecommitdiffstats
path: root/sys/miscfs/procfs/procfs_vnops.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-01-24 18:41:41 +0000
committerpeter <peter@FreeBSD.org>1996-01-24 18:41:41 +0000
commit7ce797073148356c22020f07dadba1e726b4f807 (patch)
tree8145e3cd1e1aac0b3dde9729abaeda8149c107ae /sys/miscfs/procfs/procfs_vnops.c
parent372aa68f42770d9c66509d34f90c593eadc9069c (diff)
downloadFreeBSD-src-7ce797073148356c22020f07dadba1e726b4f807.zip
FreeBSD-src-7ce797073148356c22020f07dadba1e726b4f807.tar.gz
Major fixes for procfs..
Implement a "variable" directory structure. Files that do not make sense for the given process do not "appear" and cannot be opened. For example, "system" processes do not have "file", "regs" or "fpregs", because they do not have a user area. "attempt" to fill in the user area of a given process when it is being accessed via /proc/pid/mem (the user struct is just after VM_MAXUSER_ADDRESS in the process address space.) Dont do IO to the U area while it's swapped, hold it in place if possible. Lock off access to the "ctl" file if it's done a setuid like the other pseudo-files in there.
Diffstat (limited to 'sys/miscfs/procfs/procfs_vnops.c')
-rw-r--r--sys/miscfs/procfs/procfs_vnops.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/sys/miscfs/procfs/procfs_vnops.c b/sys/miscfs/procfs/procfs_vnops.c
index 24638fe..df57932 100644
--- a/sys/miscfs/procfs/procfs_vnops.c
+++ b/sys/miscfs/procfs/procfs_vnops.c
@@ -36,7 +36,7 @@
*
* @(#)procfs_vnops.c 8.6 (Berkeley) 2/7/94
*
- * $Id: procfs_vnops.c,v 1.18 1995/11/09 08:16:04 bde Exp $
+ * $Id: procfs_vnops.c,v 1.19 1995/11/16 11:39:11 bde Exp $
*/
/*
@@ -81,21 +81,20 @@ static struct pfsnames {
u_short d_namlen;
char d_name[PROCFS_NAMELEN];
pfstype d_pfstype;
+ int (*d_valid) __P((struct proc *));
} procent[] = {
#define N(s) sizeof(s)-1, s
- /* namlen, nam, type */
- { N("."), Pproc },
- { N(".."), Proot },
-#if 0
- { N("file"), Pfile },
-#endif
- { N("mem"), Pmem },
- { N("regs"), Pregs },
- { N("fpregs"), Pfpregs },
- { N("ctl"), Pctl },
- { N("status"), Pstatus },
- { N("note"), Pnote },
- { N("notepg"), Pnotepg },
+ /* namlen, nam, type validp */
+ { N("."), Pproc, NULL },
+ { N(".."), Proot, NULL },
+ { N("file"), Pfile, procfs_validfile },
+ { N("mem"), Pmem, NULL },
+ { N("regs"), Pregs, procfs_validregs },
+ { N("fpregs"), Pfpregs, procfs_validfpregs },
+ { N("ctl"), Pctl, NULL },
+ { N("status"), Pstatus, NULL },
+ { N("note"), Pnote, NULL },
+ { N("notepg"), Pnotepg, NULL },
#undef N
};
#define Nprocent (sizeof(procent)/sizeof(procent[0]))
@@ -356,6 +355,7 @@ procfs_getattr(ap)
* that only root can gain access.
*/
switch (pfs->pfs_type) {
+ case Pctl:
case Pregs:
case Pfpregs:
if (procp->p_flag & P_SUGID)
@@ -599,7 +599,8 @@ procfs_lookup(ap)
struct pfsnames *dp = &procent[i];
if (cnp->cn_namelen == dp->d_namlen &&
- bcmp(pname, dp->d_name, dp->d_namlen) == 0) {
+ bcmp(pname, dp->d_name, dp->d_namlen) == 0 &&
+ (dp->d_valid == NULL || (*dp->d_valid)(procp))) {
pfs_type = dp->d_pfstype;
goto found;
}
@@ -633,6 +634,16 @@ procfs_lookup(ap)
}
/*
+ * Does this process have a text file?
+ */
+int
+procfs_validfile(p)
+ struct proc *p;
+{
+ return (procfs_findtextvp(p) != NULLVP);
+}
+
+/*
* readdir returns directory entries from pfsnode (vp).
*
* the strategy here with procfs is to generate a single
@@ -676,6 +687,12 @@ procfs_readdir(ap)
* from the procent[] table (top of this file).
*/
case Pproc: {
+ struct proc *p;
+
+ p = PFIND(pfs->pfs_pid);
+ if (p == NULL)
+ break;
+
while (uio->uio_resid >= UIO_MX) {
struct pfsnames *dt;
@@ -684,6 +701,12 @@ procfs_readdir(ap)
dt = &procent[i];
+ /* see if we should show this one. */
+ if (dt->d_valid && (*dt->d_valid)(p) == 0) {
+ i++;
+ continue;
+ }
+
dp->d_reclen = UIO_MX;
dp->d_fileno = PROCFS_FILENO(pfs->pfs_pid, dt->d_pfstype);
dp->d_type = DT_REG;
OpenPOWER on IntegriCloud