From 079b8fb0b14ce6006366cde20f6e4a8249ea31ad Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 24 Dec 2009 17:55:47 +0000 Subject: Let the snmp_hostres module use utmpx. Approved by: harti --- usr.sbin/bsnmpd/modules/snmp_hostres/Makefile | 4 +-- .../bsnmpd/modules/snmp_hostres/hostres_scalars.c | 34 +++++----------------- .../bsnmpd/modules/snmp_hostres/hostres_snmp.c | 1 - 3 files changed, 9 insertions(+), 30 deletions(-) (limited to 'usr.sbin/bsnmpd') diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile b/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile index 2922f45..3e9e05f 100644 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile +++ b/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile @@ -69,8 +69,8 @@ MAN= snmp_hostres.3 DEFS= ${MOD}_tree.def BMIBS= BEGEMOT-HOSTRES-MIB.txt -DPADD= ${LIBKVM} ${LIBDEVINFO} ${LIBM} ${LIBGEOM} ${LIBMEMSTAT} -LDADD= -lkvm -ldevinfo -lm -lgeom -lmemstat +DPADD= ${LIBKVM} ${LIBDEVINFO} ${LIBM} ${LIBGEOM} ${LIBMEMSTAT} ${LIBULOG} +LDADD= -lkvm -ldevinfo -lm -lgeom -lmemstat -lulog .include diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c index 945a9bd..8cf648b 100644 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c +++ b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c @@ -41,15 +41,13 @@ #include #include #include -#include +#define _ULOG_POSIX_NAMES +#include #include "hostres_snmp.h" #include "hostres_oid.h" #include "hostres_tree.h" -/* file pointer to keep an open instance of utmp */ -static FILE *utmp_fp; - /* boot timestamp in centi-seconds */ static uint64_t kernel_boot; @@ -70,9 +68,6 @@ fini_scalars(void) { free(boot_line); - - if (utmp_fp != NULL) - (void)fclose(utmp_fp); } /** @@ -220,30 +215,15 @@ OS_getSystemInitialLoadParameters(u_char **params) static int OS_getSystemNumUsers(uint32_t *nu) { - struct utmp utmp; - static int first_time = 1; - - if (utmp_fp == NULL) { - if (!first_time) - return (SNMP_ERR_GENERR); - first_time = 0; - if ((utmp_fp = fopen(_PATH_UTMP, "r")) == NULL) { - syslog(LOG_ERR, "fopen(%s) failed: %m", _PATH_UTMP); - return (SNMP_ERR_GENERR); - } - } - - /* start with the begining of the utmp file */ - (void)rewind(utmp_fp); + struct utmpx *utmp; + setutxent(); *nu = 0; - while (fread(&utmp, sizeof(utmp), 1, utmp_fp) == 1) { - if (utmp.ut_name[0] != '\0' && utmp.ut_line[0] != '\0') { - if (getpwnam(utmp.ut_name) == NULL) - continue; + while ((utmp = getutxent()) != NULL) { + if (utmp->ut_type == USER_PROCESS) (*nu)++; - } } + endutxent(); return (SNMP_ERR_NOERROR); } diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c index 47112da..c2a06db 100644 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c +++ b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c @@ -49,7 +49,6 @@ #include #include #include -#include #include "hostres_snmp.h" #include "hostres_oid.h" -- cgit v1.1