summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6e48190)
raw | patch | inline | side by side (parent: 6e48190)
author | octo <octo> | |
Tue, 6 Dec 2005 07:57:44 +0000 (07:57 +0000) | ||
committer | octo <octo> | |
Tue, 6 Dec 2005 07:57:44 +0000 (07:57 +0000) |
configure.in | patch | blob | history | |
src/config.h.in | patch | blob | history | |
src/users.c | patch | blob | history | |
src/users.h | patch | blob | history |
diff --git a/configure.in b/configure.in
index ad43b17d34f8511f8cabdeb264743f3d87418a41..aeda992cd3232190ac195f3619a5b91dcfcf14ba 100644 (file)
--- a/configure.in
+++ b/configure.in
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
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 72bf7e2e999f6979d807e88685eb448d2e5e7a33..975f16e1c99966f38d030f1cf05ed53791ca4cf0 100644 (file)
--- a/src/config.h.in
+++ b/src/config.h.in
/* 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
/* Define to 1 if you have the <utmpx.h> header file. */
#undef HAVE_UTMPX_H
+/* Define to 1 if you have the <utmp.h> 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 36cea0fb4b4618826cdb7e13af49f4f1b9f6daca..96cd6214622b94019aacb8e42f0cdd9f6344743a 100644 (file)
--- a/src/users.c
+++ b/src/users.c
#include "plugin.h"
#include "common.h"
+#ifdef HAVE_UTMPX_H
#include <utmpx.h>
+#elif defined(HAVE_UTMP_H)
+#include <utmp.h>
+#endif
static char *rrd_file = "users.rrd";
void users_read(void)
{
+#ifdef HAVE_GETUTXENT
unsigned int users = 0;
struct utmpx *entry = NULL;
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 f8b95445bcf6c118ab01b3f0f904057c00fd7abf..03306cfba339c867b4e6acbd6a45a0c4725cadae 100644 (file)
--- a/src/users.h
+++ b/src/users.h
#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
void users_submit(unsigned int);
void users_write(char *, char *, char *);
-void module_register(void);
-
#endif /* ! defined(USERS_H) */