summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsnmpd
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-12-24 17:55:47 +0000
committered <ed@FreeBSD.org>2009-12-24 17:55:47 +0000
commit079b8fb0b14ce6006366cde20f6e4a8249ea31ad (patch)
treeb2f608f2349c5b6411f9302d1cbfb86625ccaa81 /usr.sbin/bsnmpd
parent62c83b51a2772a9837f294776c965e4c30408c67 (diff)
downloadFreeBSD-src-079b8fb0b14ce6006366cde20f6e4a8249ea31ad.zip
FreeBSD-src-079b8fb0b14ce6006366cde20f6e4a8249ea31ad.tar.gz
Let the snmp_hostres module use utmpx.
Approved by: harti
Diffstat (limited to 'usr.sbin/bsnmpd')
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hostres/Makefile4
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c34
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c1
3 files changed, 9 insertions, 30 deletions
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 <bsd.snmpmod.mk>
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 <stdint.h>
#include <string.h>
#include <syslog.h>
-#include <utmp.h>
+#define _ULOG_POSIX_NAMES
+#include <ulog.h>
#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 <string.h>
#include <syslog.h>
#include <unistd.h>
-#include <utmp.h>
#include "hostres_snmp.h"
#include "hostres_oid.h"
OpenPOWER on IntegriCloud