summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c')
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c34
1 files changed, 7 insertions, 27 deletions
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);
}
OpenPOWER on IntegriCloud