Let the snmp_hostres module use utmpx.

Approved by:	harti
This commit is contained in:
Ed Schouten 2009-12-24 17:55:47 +00:00
parent 4a3c1bd27f
commit 71713ba2e1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=200953
3 changed files with 9 additions and 30 deletions

View File

@ -69,8 +69,8 @@ MAN= snmp_hostres.3
DEFS= ${MOD}_tree.def DEFS= ${MOD}_tree.def
BMIBS= BEGEMOT-HOSTRES-MIB.txt BMIBS= BEGEMOT-HOSTRES-MIB.txt
DPADD= ${LIBKVM} ${LIBDEVINFO} ${LIBM} ${LIBGEOM} ${LIBMEMSTAT} DPADD= ${LIBKVM} ${LIBDEVINFO} ${LIBM} ${LIBGEOM} ${LIBMEMSTAT} ${LIBULOG}
LDADD= -lkvm -ldevinfo -lm -lgeom -lmemstat LDADD= -lkvm -ldevinfo -lm -lgeom -lmemstat -lulog
.include <bsd.snmpmod.mk> .include <bsd.snmpmod.mk>

View File

@ -41,15 +41,13 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <syslog.h> #include <syslog.h>
#include <utmp.h> #define _ULOG_POSIX_NAMES
#include <ulog.h>
#include "hostres_snmp.h" #include "hostres_snmp.h"
#include "hostres_oid.h" #include "hostres_oid.h"
#include "hostres_tree.h" #include "hostres_tree.h"
/* file pointer to keep an open instance of utmp */
static FILE *utmp_fp;
/* boot timestamp in centi-seconds */ /* boot timestamp in centi-seconds */
static uint64_t kernel_boot; static uint64_t kernel_boot;
@ -70,9 +68,6 @@ fini_scalars(void)
{ {
free(boot_line); free(boot_line);
if (utmp_fp != NULL)
(void)fclose(utmp_fp);
} }
/** /**
@ -220,30 +215,15 @@ OS_getSystemInitialLoadParameters(u_char **params)
static int static int
OS_getSystemNumUsers(uint32_t *nu) OS_getSystemNumUsers(uint32_t *nu)
{ {
struct utmp utmp; struct utmpx *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);
setutxent();
*nu = 0; *nu = 0;
while (fread(&utmp, sizeof(utmp), 1, utmp_fp) == 1) { while ((utmp = getutxent()) != NULL) {
if (utmp.ut_name[0] != '\0' && utmp.ut_line[0] != '\0') { if (utmp->ut_type == USER_PROCESS)
if (getpwnam(utmp.ut_name) == NULL)
continue;
(*nu)++; (*nu)++;
}
} }
endutxent();
return (SNMP_ERR_NOERROR); return (SNMP_ERR_NOERROR);
} }

View File

@ -49,7 +49,6 @@
#include <string.h> #include <string.h>
#include <syslog.h> #include <syslog.h>
#include <unistd.h> #include <unistd.h>
#include <utmp.h>
#include "hostres_snmp.h" #include "hostres_snmp.h"
#include "hostres_oid.h" #include "hostres_oid.h"