svn commit: r200953 - head/usr.sbin/bsnmpd/modules/snmp_hostres

Ed Schouten ed at FreeBSD.org
Thu Dec 24 17:55:48 UTC 2009


Author: ed
Date: Thu Dec 24 17:55:47 2009
New Revision: 200953
URL: http://svn.freebsd.org/changeset/base/200953

Log:
  Let the snmp_hostres module use utmpx.
  
  Approved by:	harti

Modified:
  head/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile
  head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c
  head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c

Modified: head/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile
==============================================================================
--- head/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile	Thu Dec 24 17:35:48 2009	(r200952)
+++ head/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile	Thu Dec 24 17:55:47 2009	(r200953)
@@ -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>
 

Modified: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c
==============================================================================
--- head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c	Thu Dec 24 17:35:48 2009	(r200952)
+++ head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c	Thu Dec 24 17:55:47 2009	(r200953)
@@ -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
 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);
 }

Modified: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c
==============================================================================
--- head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c	Thu Dec 24 17:35:48 2009	(r200952)
+++ head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c	Thu Dec 24 17:55:47 2009	(r200953)
@@ -49,7 +49,6 @@
 #include <string.h>
 #include <syslog.h>
 #include <unistd.h>
-#include <utmp.h>
 
 #include "hostres_snmp.h"
 #include "hostres_oid.h"


More information about the svn-src-all mailing list