From 0dd872f5bb0d15bd0dab92b2eabd330fbc901d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 9 Sep 2003 08:19:06 +0000 Subject: [PATCH] Add cwd, root and statm (modeled on a 2.4.20 kernel). De-obfuscate linprocfs_init() a little and remove some gratuitous whitespace. --- sys/compat/linprocfs/linprocfs.c | 113 ++++++++++++++++++++++++++----- 1 file changed, 96 insertions(+), 17 deletions(-) diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 89d60cb30d84..f0c34e1207b7 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -546,6 +547,37 @@ linprocfs_doprocstat(PFS_FILL_ARGS) return (0); } +/* + * Filler function for proc/pid/statm + */ +static int +linprocfs_doprocstatm(PFS_FILL_ARGS) +{ + struct kinfo_proc kp; + segsz_t lsize; + + PROC_LOCK(p); + fill_kinfo_proc(p, &kp); + PROC_UNLOCK(p); + + /* + * See comments in linprocfs_doprocstatus() regarding the + * computation of lsize. + */ + /* size resident share trs drs lrs dt */ + sbuf_printf(sb, "%ju ", B2P((uintmax_t)kp.ki_size)); + sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_rssize); + sbuf_printf(sb, "%ju ", (uintmax_t)0); /* XXX */ + sbuf_printf(sb, "%ju ", (uintmax_t)kp.ki_tsize); + sbuf_printf(sb, "%ju ", (uintmax_t)(kp.ki_dsize + kp.ki_ssize)); + lsize = B2P(kp.ki_size) - kp.ki_dsize - + kp.ki_ssize - kp.ki_tsize - 1; + sbuf_printf(sb, "%ju ", (uintmax_t)lsize); + sbuf_printf(sb, "%ju\n", (uintmax_t)0); /* XXX */ + + return (0); +} + /* * Filler function for proc/pid/status */ @@ -682,6 +714,41 @@ linprocfs_doprocstatus(PFS_FILL_ARGS) return (0); } + +/* + * Filler function for proc/pid/cwd + */ +static int +linprocfs_doproccwd(PFS_FILL_ARGS) +{ + char *fullpath = "unknown"; + char *freepath = NULL; + + vn_fullpath(td, p->p_fd->fd_cdir, &fullpath, &freepath); + sbuf_printf(sb, "%s", fullpath); + if (freepath) + free(freepath, M_TEMP); + return (0); +} + +/* + * Filler function for proc/pid/root + */ +static int +linprocfs_doprocroot(PFS_FILL_ARGS) +{ + struct vnode *rvp; + char *fullpath = "unknown"; + char *freepath = NULL; + + rvp = jailed(p->p_ucred) ? p->p_fd->fd_jdir : p->p_fd->fd_rdir; + vn_fullpath(td, rvp, &fullpath, &freepath); + sbuf_printf(sb, "%s", fullpath); + if (freepath) + free(freepath, M_TEMP); + return (0); +} + /* * Filler function for proc/pid/cmdline */ @@ -835,47 +902,59 @@ linprocfs_init(PFS_INIT_ARGS) root = pi->pi_root; -#define PFS_CREATE_FILE(name) \ - pfs_create_file(root, #name, &linprocfs_do##name, NULL, NULL, PFS_RD) - PFS_CREATE_FILE(cmdline); - PFS_CREATE_FILE(cpuinfo); + /* /proc/* */ + pfs_create_file(root, "cmdline", &linprocfs_docmdline, + NULL, NULL, PFS_RD); + pfs_create_file(root, "cpuinfo", &linprocfs_docpuinfo, + NULL, NULL, PFS_RD); #if 0 - PFS_CREATE_FILE(devices); + pfs_create_file(root, "devices", &linprocfs_dodevices, + NULL, NULL, PFS_RD); #endif - PFS_CREATE_FILE(loadavg); - PFS_CREATE_FILE(meminfo); + pfs_create_file(root, "loadavg", &linprocfs_doloadavg, + NULL, NULL, PFS_RD); + pfs_create_file(root, "meminfo", &linprocfs_domeminfo, + NULL, NULL, PFS_RD); #if 0 - PFS_CREATE_FILE(modules); + pfs_create_file(root, "modules", &linprocfs_domodules, + NULL, NULL, PFS_RD); #endif - PFS_CREATE_FILE(mtab); - PFS_CREATE_FILE(stat); - PFS_CREATE_FILE(uptime); - PFS_CREATE_FILE(version); -#undef PFS_CREATE_FILE + pfs_create_file(root, "mtab", &linprocfs_domtab, + NULL, NULL, PFS_RD); pfs_create_link(root, "self", &procfs_docurproc, NULL, NULL, 0); + pfs_create_file(root, "stat", &linprocfs_dostat, + NULL, NULL, PFS_RD); + pfs_create_file(root, "uptime", &linprocfs_douptime, + NULL, NULL, PFS_RD); + pfs_create_file(root, "version", &linprocfs_doversion, + NULL, NULL, PFS_RD); + /* /proc/net/* */ dir = pfs_create_dir(root, "net", NULL, NULL, 0); pfs_create_file(dir, "dev", &linprocfs_donetdev, NULL, NULL, PFS_RD); + /* /proc//* */ dir = pfs_create_dir(root, "pid", NULL, NULL, PFS_PROCDEP); pfs_create_file(dir, "cmdline", &linprocfs_doproccmdline, NULL, NULL, PFS_RD); - + pfs_create_link(dir, "cwd", &linprocfs_doproccwd, + NULL, NULL, 0); pfs_create_file(dir, "environ", &linprocfs_doprocenviron, NULL, NULL, PFS_RD); - pfs_create_link(dir, "exe", &procfs_doprocfile, NULL, &procfs_notsystem, 0); - pfs_create_file(dir, "maps", &linprocfs_doprocmaps, NULL, NULL, PFS_RD); - pfs_create_file(dir, "mem", &procfs_doprocmem, &procfs_attr, &procfs_candebug, PFS_RDWR|PFS_RAW); + pfs_create_link(dir, "root", &linprocfs_doprocroot, + NULL, NULL, 0); pfs_create_file(dir, "stat", &linprocfs_doprocstat, NULL, NULL, PFS_RD); + pfs_create_file(dir, "statm", &linprocfs_doprocstatm, + NULL, NULL, PFS_RD); pfs_create_file(dir, "status", &linprocfs_doprocstatus, NULL, NULL, PFS_RD);