summaryrefslogtreecommitdiffstats
path: root/usr.bin/systat/mbufs.c
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2000-07-15 16:24:21 +0000
committeralfred <alfred@FreeBSD.org>2000-07-15 16:24:21 +0000
commit5a659df928b74bd2d1ed0a7361ab9514c3c453ba (patch)
treea6da9cad7554be389cb20e1e6ec1e537d91564b5 /usr.bin/systat/mbufs.c
parentd2b1e4c7119240f614a8a42252e6a4a02b86d28c (diff)
downloadFreeBSD-src-5a659df928b74bd2d1ed0a7361ab9514c3c453ba.zip
FreeBSD-src-5a659df928b74bd2d1ed0a7361ab9514c3c453ba.tar.gz
Fix systat to use the kern.ipc.mbtypes sysctl instead of referencing a
structure member that doesn't exist anymore. Use getsysctlbyname for kern.ipc.mbstat instead of sysctl. Use netstat's method of displaying values from mtnames. Submitted by: Ian Dowse <iedowse@maths.tcd.ie> Missed by PR: 19809
Diffstat (limited to 'usr.bin/systat/mbufs.c')
-rw-r--r--usr.bin/systat/mbufs.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/usr.bin/systat/mbufs.c b/usr.bin/systat/mbufs.c
index 5e42861..c4957b9 100644
--- a/usr.bin/systat/mbufs.c
+++ b/usr.bin/systat/mbufs.c
@@ -50,22 +50,19 @@ static const char rcsid[] =
#include "extern.h"
static struct mbstat *mb;
-
-char *mtnames[] = {
- "free",
- "data",
- "headers",
- "sockets",
- "pcbs",
- "routes",
- "hosts",
- "arps",
- "socknames",
- "zombies",
- "sockopts",
- "frags",
- "rights",
- "ifaddrs",
+static u_long *m_mbtypes;
+static int nmbtypes;
+
+static struct mtnames {
+ int mt_type;
+ char *mt_name;
+} mtnames[] = {
+ { MT_DATA, "data"},
+ { MT_HEADER, "headers"},
+ { MT_SONAME, "socknames"},
+ { MT_FTABLE, "frags"},
+ { MT_CONTROL, "control"},
+ { MT_OOBDATA, "oobdata"}
};
#define NNAMES (sizeof (mtnames) / sizeof (mtnames[0]))
@@ -100,6 +97,7 @@ showmbufs()
{
register int i, j, max, index;
char buf[10];
+ char *mtname;
if (mb == 0)
return;
@@ -108,17 +106,24 @@ showmbufs()
for (i = 0; i < wnd->_maxy; i++) {
if (i == MT_FREE)
continue;
- if (mb->m_mtypes[i] > max) {
- max = mb->m_mtypes[i];
+ if (i >= nmbtypes)
+ break;
+ if (m_mbtypes[i] > max) {
+ max = m_mbtypes[i];
index = i;
}
}
if (max == 0)
break;
- if (j > NNAMES)
+
+ mtname = NULL;
+ for (i = 0; i < NNAMES; i++)
+ if (mtnames[i].mt_type == index)
+ mtname = mtnames[i].mt_name;
+ if (mtname == NULL)
mvwprintw(wnd, 1+j, 0, "%10d", index);
else
- mvwprintw(wnd, 1+j, 0, "%-10.10s", mtnames[index]);
+ mvwprintw(wnd, 1+j, 0, "%-10.10s", mtname);
wmove(wnd, 1 + j, 10);
if (max > 60) {
snprintf(buf, sizeof(buf), " %d", max);
@@ -130,8 +135,8 @@ showmbufs()
while (max--)
waddch(wnd, 'X');
wclrtoeol(wnd);
- mb->m_mbufs -= mb->m_mtypes[index];
- mb->m_mtypes[index] = 0;
+ mb->m_mbufs -= m_mbtypes[index];
+ m_mbtypes[index] = 0;
}
if (mb->m_mbufs) {
mvwprintw(wnd, 1+j, 0, "%-10.10s", "free");
@@ -154,14 +159,20 @@ showmbufs()
int
initmbufs()
{
- size_t len;
- int name[3];
+ size_t len, mbtypeslen;
+
+ if (sysctlbyname("kern.ipc.mbtypes", NULL, &mbtypeslen, NULL, 0) < 0) {
+ error("sysctl getting mbtypes size failed");
+ return 0;
+ }
+ if ((m_mbtypes = calloc(1, mbtypeslen)) == NULL) {
+ error("calloc mbtypes failed");
+ return 0;
+ }
+ nmbtypes = mbtypeslen / sizeof(*m_mbtypes);
- name[0] = CTL_KERN;
- name[1] = KERN_IPC;
- name[2] = KIPC_MBSTAT;
len = 0;
- if (sysctl(name, 3, 0, &len, 0, 0) < 0) {
+ if (sysctlbyname("kern.ipc.mbstat", 0, &len, 0, 0) < 0) {
error("sysctl getting mbstat size failed");
return 0;
}
@@ -174,14 +185,13 @@ initmbufs()
void
fetchmbufs()
{
- int name[3];
size_t len;
- name[0] = CTL_KERN;
- name[1] = KERN_IPC;
- name[2] = KIPC_MBSTAT;
len = sizeof *mb;
+ if (sysctlbyname("kern.ipc.mbstat", mb, &len, 0, 0) < 0)
+ printw("sysctl: mbstat: %s", strerror(errno));
- if (sysctl(name, 3, mb, &len, 0, 0) < 0)
- printw("sysctl: %s", strerror(errno));
+ len = nmbtypes * sizeof *m_mbtypes;
+ if (sysctlbyname("kern.ipc.mbtypes", m_mbtypes, &len, 0, 0) < 0)
+ printw("sysctl: mbtypes: %s", strerror(errno));
}
OpenPOWER on IntegriCloud