diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-06-03 15:49:32 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-06-03 15:49:32 +0000 |
commit | 429c40207453992810de55f3e82b81d92adf71da (patch) | |
tree | a5247890b7af5a879228b3b4b8a0626b09771b46 /usr.sbin | |
parent | 37bc4e9f11204196119a0114467eb848afa91ba0 (diff) |
sysctl of KERN_FILE returns a list of mis-aligned file structs; compensate
by copying to private space... since changing the kernel API will be difficult.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pstat/pstat.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index 4af2546403c..e2632235746 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pstat.c,v 1.19 1999/05/22 21:43:52 weingart Exp $ */ +/* $OpenBSD: pstat.c,v 1.20 1999/06/03 15:49:31 deraadt Exp $ */ /* $NetBSD: pstat.c,v 1.27 1996/10/23 22:50:06 cgd Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 from: static char sccsid[] = "@(#)pstat.c 8.9 (Berkeley) 2/16/94"; #else -static char *rcsid = "$OpenBSD: pstat.c,v 1.19 1999/05/22 21:43:52 weingart Exp $"; +static char *rcsid = "$OpenBSD: pstat.c,v 1.20 1999/06/03 15:49:31 deraadt Exp $"; #endif #endif /* not lint */ @@ -828,7 +828,7 @@ ttyprt(tp) void filemode() { - register struct file *fp; + struct file fp, *ffp; struct file *addr; char *buf, flagbuf[16], *fbp; int len, maxfile, nfile; @@ -848,39 +848,41 @@ filemode() * derivable from the previous entry). */ addr = ((struct filelist *)buf)->lh_first; - fp = (struct file *)(buf + sizeof(struct filelist)); + ffp = (struct file *)(buf + sizeof(struct filelist)); nfile = (len - sizeof(struct filelist)) / sizeof(struct file); (void)printf("%d/%d open files\n", nfile, maxfile); (void)printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n"); - for (; (char *)fp < buf + len; addr = fp->f_list.le_next, fp++) { - if ((unsigned)fp->f_type > DTYPE_SOCKET) + for (; (char *)ffp < buf + len; addr = ffp->f_list.le_next, ffp++) { + memmove(&fp, ffp, sizeof fp); + if ((unsigned)fp.f_type > DTYPE_SOCKET) continue; (void)printf("%lx ", (long)addr); - (void)printf("%-8.8s", dtypes[fp->f_type]); + (void)printf("%-8.8s", dtypes[fp.f_type]); fbp = flagbuf; - if (fp->f_flag & FREAD) + if (fp.f_flag & FREAD) *fbp++ = 'R'; - if (fp->f_flag & FWRITE) + if (fp.f_flag & FWRITE) *fbp++ = 'W'; - if (fp->f_flag & FAPPEND) + if (fp.f_flag & FAPPEND) *fbp++ = 'A'; #ifdef FSHLOCK /* currently gone */ - if (fp->f_flag & FSHLOCK) + if (fp.f_flag & FSHLOCK) *fbp++ = 'S'; - if (fp->f_flag & FEXLOCK) + if (fp.f_flag & FEXLOCK) *fbp++ = 'X'; #endif - if (fp->f_flag & FASYNC) + if (fp.f_flag & FASYNC) *fbp++ = 'I'; *fbp = '\0'; - (void)printf("%6s %3ld", flagbuf, fp->f_count); - (void)printf(" %3ld", fp->f_msgcount); - (void)printf(" %8.1lx", (long)fp->f_data); - if (fp->f_offset < 0) - (void)printf(" %qx\n", fp->f_offset); + (void)printf("%6s %3ld", flagbuf, fp.f_count); + (void)printf(" %3ld", fp.f_msgcount); + (void)printf(" %8.1lx", (long)fp.f_data); + + if (fp.f_offset < 0) + (void)printf(" %qx\n", fp.f_offset); else - (void)printf(" %qd\n", fp->f_offset); + (void)printf(" %qd\n", fp.f_offset); } free(buf); } |