summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorcsjp <csjp@FreeBSD.org>2005-09-05 23:13:05 +0000
committercsjp <csjp@FreeBSD.org>2005-09-05 23:13:05 +0000
commitb1c29887f76142f408b1f0c6c42150b789e2f1f3 (patch)
tree145845e3867a22110c726d7c587a964d4c2c52b3 /tools
parent17dd22a407f2b37e2d1bbf9e6aad12e5765e1d4b (diff)
downloadFreeBSD-src-b1c29887f76142f408b1f0c6c42150b789e2f1f3.zip
FreeBSD-src-b1c29887f76142f408b1f0c6c42150b789e2f1f3.tar.gz
Now that the PID is constantly refreshed, introduce a pidname function which
when given a PID consults the kern.proc.pid sysctl variable to pull out the pcomm data.
Diffstat (limited to 'tools')
-rw-r--r--tools/tools/bpfstat/bpfstat.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/tools/tools/bpfstat/bpfstat.c b/tools/tools/bpfstat/bpfstat.c
index d9a69df..8061f3d 100644
--- a/tools/tools/bpfstat/bpfstat.c
+++ b/tools/tools/bpfstat/bpfstat.c
@@ -58,6 +58,24 @@ static void usage(char *);
static void setwidths(struct colwidths *);
static int diglen(double);
+static char *
+pidname(pid_t pid)
+{
+ struct kinfo_proc newkp;
+ int error, mib[4];
+ size_t size;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = pid;
+ size = sizeof(newkp);
+ error = sysctl(mib, 4, &newkp, &size, NULL, 0);
+ if (error < 0)
+ return (strdup("??????"));
+ return (strdup(newkp.ki_comm));
+}
+
static void
setwidths(struct colwidths *c)
{
@@ -129,8 +147,9 @@ static void
bpfd_print_row(struct xbpf_d *bd, struct conf *conf)
{
struct colwidths *c;
- char flagbuf[8];
+ char *pname, flagbuf[8];
+ pname = pidname(bd->bd_pid);
c = &conf->cw;
bpfd_parse_flags(bd, &flagbuf[0]);
printf("%*d %*s %*s %*lu %*lu %*lu %*d %*d %s\n",
@@ -142,7 +161,7 @@ bpfd_print_row(struct xbpf_d *bd, struct conf *conf)
c->fc_width, bd->bd_fcount,
c->sb_width, bd->bd_slen,
c->hb_width, bd->bd_hlen,
- bd->bd_pcomm);
+ pname);
}
static void
@@ -227,9 +246,6 @@ main(int argc, char *argv [])
if (cf.Iflag &&
strcmp(bd->bd_ifname, cf.Iflag) != 0)
continue;
- if (cf.cflag &&
- strcmp(bd->bd_pcomm, cf.cflag) != 0)
- continue;
bpfd_print_row(bd, &cf);
}
cf.lps++;
OpenPOWER on IntegriCloud