From 5c7a83ed1d5d7923aa3874179e372a483a274f52 Mon Sep 17 00:00:00 2001 From: des Date: Thu, 6 Jun 2002 18:39:53 +0000 Subject: Factor out some code in preparation for un-kmeming fstat(1). Sponsored by: DARPA, NAI Labs --- usr.bin/fstat/fstat.c | 61 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'usr.bin/fstat') diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 97e4707..3a08f64 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -136,8 +136,11 @@ int maxfiles; maxfiles = (d); \ } +char *memf, *nlistf; kvm_t *kd; +static void fstat_kvm(int, int); +static void fstat_sysctl(int, int); void dofiles(struct kinfo_proc *kp); void dommap(struct kinfo_proc *kp); void vtrans(struct vnode *vp, int i, int flag); @@ -158,11 +161,7 @@ main(argc, argv) char **argv; { struct passwd *passwd; - struct kinfo_proc *p, *plast; int arg, ch, what; - char *memf, *nlistf; - char buf[_POSIX2_LINE_MAX]; - int cnt; arg = 0; what = KERN_PROC_ALL; @@ -219,8 +218,6 @@ main(argc, argv) exit(1); } - ALLOC_OFILES(256); /* reserve space for file pointers */ - if (fsflg && !checkfile) { /* -f with no files means use wd */ if (getfname(".") == 0) @@ -228,6 +225,38 @@ main(argc, argv) checkfile = 1; } + if (memf != NULL) + fstat_kvm(what, arg); + else + fstat_sysctl(what, arg); + exit(0); +} + +static void +print_header(void) +{ + + if (nflg) + printf("%s", +"USER CMD PID FD DEV INUM MODE SZ|DV R/W"); + else + printf("%s", +"USER CMD PID FD MOUNT INUM MODE SZ|DV R/W"); + if (checkfile && fsflg == 0) + printf(" NAME\n"); + else + putchar('\n'); +} + +static void +fstat_kvm(int what, int arg) +{ + struct kinfo_proc *p, *plast; + char buf[_POSIX2_LINE_MAX]; + int cnt; + + ALLOC_OFILES(256); /* reserve space for file pointers */ + /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. @@ -244,17 +273,6 @@ main(argc, argv) #endif if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); - if (nflg) - printf("%s", -"USER CMD PID FD DEV INUM MODE SZ|DV R/W"); - else - printf("%s", -"USER CMD PID FD MOUNT INUM MODE SZ|DV R/W"); - if (checkfile && fsflg == 0) - printf(" NAME\n"); - else - putchar('\n'); - for (plast = &p[cnt]; p < plast; ++p) { if (p->ki_stat == SZOMB) continue; @@ -262,7 +280,14 @@ main(argc, argv) if (mflg) dommap(p); } - exit(0); +} + +static void +fstat_sysctl(int what, int arg) +{ + + /* not yet implemented */ + fstat_kvm(what, arg); } const char *Uname, *Comm; -- cgit v1.1