diff options
author | robert <robert@FreeBSD.org> | 2003-01-31 15:16:52 +0000 |
---|---|---|
committer | robert <robert@FreeBSD.org> | 2003-01-31 15:16:52 +0000 |
commit | 4a93c6295ede957930be19d780d8d9f5c66a85b2 (patch) | |
tree | 18dac6bb6bc9d0b9ae96976fd9aaa03167e2b5ac /usr.sbin | |
parent | c3a292768544d6dbd48ecda64065fe873955e134 (diff) | |
download | FreeBSD-src-4a93c6295ede957930be19d780d8d9f5c66a85b2.zip FreeBSD-src-4a93c6295ede957930be19d780d8d9f5c66a85b2.tar.gz |
- Modernize the format of the open file showing mode output:
. Print the column headers centered (except for the left-aligned
TYPE header) using a different header for architectures where
sizeof(uintptr_t) is not four.
. Consistently do not print a '0x' prefix for hexadecimal values.
. Separate columns by a single space character.
. Pad the columns presenting an address or offset enough to hold
their respective largest value.
. Do not restrict the output to unknown file types, inodes and
sockets; allow displaying of pipes, fifos, kqueues and crypto file
descriptors too.
- Shorten an overly long line by removing a cast of printf's return
value to void.
PR: alpha/45240
Tested on: i386, sparc64, alpha
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pstat/pstat.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index e6a3f2b..a147aae 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -199,6 +199,14 @@ usage(void) exit (1); } +static const char fhdr32[] = + " LOC TYPE FLG CNT MSG DATA OFFSET\n"; +/* c0000000 ------ RWAI 123 123 c0000000 1000000000000000 */ + +static const char fhdr64[] = + " LOC TYPE FLG CNT MSG DATA OFFSET\n"; +/* c000000000000000 ------ RWAI 123 123 c000000000000000 1000000000000000 */ + static const char hdr[] = " LINE RAW CAN OUT IHIWT ILOWT OHWT LWT COL STATE SESS PGID DISC\n"; @@ -334,7 +342,7 @@ ttyprt(struct xtty *xt) errx(1, "struct xtty size mismatch"); if (usenumflag || xt->xt_dev == 0 || (name = devname(xt->xt_dev, S_IFCHR)) == NULL) - (void)printf(" %2d,%-2d", major(xt->xt_dev), minor(xt->xt_dev)); + printf(" %2d,%-2d", major(xt->xt_dev), minor(xt->xt_dev)); else (void)printf("%7s ", name); (void)printf("%2ld %3ld ", xt->xt_rawcc, xt->xt_cancc); @@ -376,8 +384,10 @@ filemode(void) char *buf, flagbuf[16], *fbp; int maxf, openf; size_t len; - static char *dtypes[] = { "???", "inode", "socket" }; + static char *dtypes[] = { "???", "inode", "socket", "pipe", + "fifo", "kqueue", "crypto" }; int i; + int wid; if (kd != NULL) { if (kvm_read(kd, nl[NL_MAXFILES].n_value, @@ -399,13 +409,15 @@ filemode(void) if (getfiles(&buf, &len) == -1) return; openf = len / sizeof *fp; + (void)printf("%d/%d open files\n", openf, maxf); - (void)printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n"); + printf(sizeof(uintptr_t) == 4 ? fhdr32 : fhdr64); + wid = (int)sizeof(uintptr_t) * 2; for (fp = (struct xfile *)buf, i = 0; i < openf; ++fp, ++i) { - if ((unsigned)fp->xf_type > DTYPE_SOCKET) + if ((size_t)fp->xf_type >= sizeof(dtypes) / sizeof(dtypes[0])) continue; - (void)printf("%8jx ", (uintmax_t)(uintptr_t)fp->xf_file); - (void)printf("%-8.8s", dtypes[fp->xf_type]); + (void)printf("%*jx", wid, (uintmax_t)(uintptr_t)fp->xf_file); + (void)printf(" %-6.6s", dtypes[fp->xf_type]); fbp = flagbuf; if (fp->xf_flag & FREAD) *fbp++ = 'R'; @@ -416,10 +428,11 @@ filemode(void) if (fp->xf_flag & FASYNC) *fbp++ = 'I'; *fbp = '\0'; - (void)printf("%6s %3d", flagbuf, fp->xf_count); - (void)printf(" %3d", fp->xf_msgcount); - (void)printf(" %p", fp->xf_data); - (void)printf(" %jx\n", (uintmax_t)fp->xf_offset); + (void)printf(" %4s %3d", flagbuf, fp->xf_count); + (void)printf(" %3d", fp->xf_msgcount); + (void)printf(" %*jx", wid, (uintmax_t)(uintptr_t)fp->xf_data); + (void)printf(" %*jx\n", (int)sizeof(fp->xf_offset) * 2, + (uintmax_t)fp->xf_offset); } free(buf); } |