From 82d65d8766709d99edac10c46078ab2766341f62 Mon Sep 17 00:00:00 2001 From: octo Date: Tue, 6 Dec 2005 07:57:44 +0000 Subject: [PATCH] Added backwards compatibility to `users.c', so I can use `utmp' too if `utmpx' is not found. --- configure.in | 3 ++- src/config.h.in | 6 ++++++ src/users.c | 25 ++++++++++++++++++++++++- src/users.h | 14 +++++++++++--- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/configure.in b/configure.in index ad43b17d..aeda992c 100644 --- a/configure.in +++ b/configure.in @@ -36,6 +36,7 @@ AC_CHECK_HEADERS(netinet/in.h) AC_CHECK_HEADERS(netdb.h) AC_CHECK_HEADERS(syslog.h) AC_CHECK_HEADERS(dlfcn.h) +AC_CHECK_HEADERS(utmp.h) AC_CHECK_HEADERS(utmpx.h) dnl Checking for libraries @@ -54,7 +55,7 @@ AC_CHECK_FUNCS(socket, , AC_CHECK_LIB(socket, socket)) AC_CHECK_FUNCS(gethostbyname, , AC_CHECK_LIB(nsl, gethostbyname)) AC_CHECK_FUNCS(strchr memcpy strstr strcmp strncmp strncpy strlen) AC_CHECK_FUNCS(strncasecmp strcasecmp strncmp) -AC_CHECK_FUNCS(getutxent) +AC_CHECK_FUNCS(getutent getutxent) AC_MSG_CHECKING([for kernel type ($host_os)]) case $host_os in diff --git a/src/config.h.in b/src/config.h.in index 72bf7e2e..975f16e1 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -63,6 +63,9 @@ /* Define to 1 if you have the `gettimeofday' function. */ #undef HAVE_GETTIMEOFDAY +/* Define to 1 if you have the `getutent' function. */ +#undef HAVE_GETUTENT + /* Define to 1 if you have the `getutxent' function. */ #undef HAVE_GETUTXENT @@ -207,6 +210,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UTMPX_H +/* Define to 1 if you have the header file. */ +#undef HAVE_UTMP_H + /* True if program is to be compiled for a Linux kernel */ #undef KERNEL_LINUX diff --git a/src/users.c b/src/users.c index 36cea0fb..96cd6214 100644 --- a/src/users.c +++ b/src/users.c @@ -30,7 +30,11 @@ #include "plugin.h" #include "common.h" +#ifdef HAVE_UTMPX_H #include +#elif defined(HAVE_UTMP_H) +#include +#endif static char *rrd_file = "users.rrd"; @@ -50,6 +54,7 @@ void users_init(void) void users_read(void) { +#ifdef HAVE_GETUTXENT unsigned int users = 0; struct utmpx *entry = NULL; @@ -63,7 +68,25 @@ void users_read(void) endutxent(); users_submit(users); - return; +/* #endif HAVE_GETUTXENT */ + +#elif defined(HAVE_GETUTENT) + unsigned int users = 0; + struct utmp *entry = NULL; + + /* according to the *utent(3) man page none of the functions sets errno in + * case of an error, so we cannot do any error-checking here */ + setutent(); + + while (NULL != (entry = getutent())) + if (USER_PROCESS == entry->ut_type) + ++users; + endutent(); + + users_submit(users); +#endif + + return; } /* I don't like this temporary macro definition - well it's used everywhere diff --git a/src/users.h b/src/users.h index f8b95445..03306cfb 100644 --- a/src/users.h +++ b/src/users.h @@ -27,8 +27,18 @@ #include "config.h" +#if !defined(HAVE_UTMPX_H) || !defined(HAVE_GETUTXENT) +#undef HAVE_UTMPX_H +#undef HAVE_GETUTXENT +#endif + +#if !defined(HAVE_UTMP_H) || !defined(HAVE_GETUTENT) +#undef HAVE_UTMPX_H +#undef HAVE_GETUTXENT +#endif + #ifndef COLLECT_USERS -#if defined(HAVE_UTMPX_H) && defined(HAVE_GETUTXENT) +#if defined(HAVE_UTMPX_H) || defined(HAVE_UTMP_H) #define COLLECT_USERS 1 #else #define COLLECT_USERS 0 @@ -40,7 +50,5 @@ void users_read(void); void users_submit(unsigned int); void users_write(char *, char *, char *); -void module_register(void); - #endif /* ! defined(USERS_H) */ -- 2.30.2