From owner-svn-src-head@FreeBSD.ORG Thu Dec 24 17:55:47 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CE1FA106566C; Thu, 24 Dec 2009 17:55:47 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B37A08FC14; Thu, 24 Dec 2009 17:55:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBOHtlxW037123; Thu, 24 Dec 2009 17:55:47 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBOHtluJ037119; Thu, 24 Dec 2009 17:55:47 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912241755.nBOHtluJ037119@svn.freebsd.org> From: Ed Schouten Date: Thu, 24 Dec 2009 17:55:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200953 - head/usr.sbin/bsnmpd/modules/snmp_hostres X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 17:55:48 -0000 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 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 #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 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 #include #include -#include #include "hostres_snmp.h" #include "hostres_oid.h"