summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 56a554e)
raw | patch | inline | side by side (parent: 56a554e)
author | niki <niki> | |
Fri, 16 Dec 2005 17:37:31 +0000 (17:37 +0000) | ||
committer | niki <niki> | |
Fri, 16 Dec 2005 17:37:31 +0000 (17:37 +0000) |
src/users.c | patch | blob | history | |
src/users.h | patch | blob | history |
diff --git a/src/users.c b/src/users.c
index 31c936c84d9ab018cb23756c74358677d2711d73..486c7bdf24bfe44339212d726578611ea469e5f7 100644 (file)
--- a/src/users.c
+++ b/src/users.c
* Sebastian Harl <sh at tokkee.org>
**/
+#include "common.h"
+#include "plugin.h"
#include "users.h"
-#if COLLECT_USERS
-#define MODULE_NAME "users"
+#if HAVE_UTMPX_H
+# include <utmpx.h>
+#else /* !HAVE_UTMPX_H */
+# if HAVE_UTMP_H
+# include <utmp.h>
+# endif /* HAVE_UTMP_H */
+#endif /* HAVE_UTMPX_H */
-#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";
+#define MODULE_NAME "users"
+static char *rrd_file = "users.rrd";
static char *ds_def[] = {
- "DS:users:GAUGE:25:0:65535",
- NULL
+ "DS:users:GAUGE:25:0:65535",
+ NULL
};
static int ds_num = 1;
-void users_init(void)
-{
- /* we have nothing to do here :-) */
- return;
-}
-void users_read(void)
-{
-#ifdef HAVE_GETUTXENT
- unsigned int users = 0;
- struct utmpx *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 */
- setutxent();
+static void users_submit(unsigned int users);
+static void users_init(void);
+static void users_read(void);
+static void users_write(char *host, char *inst, char *val);
- while (NULL != (entry = getutxent()))
- if (USER_PROCESS == entry->ut_type)
- ++users;
- endutxent();
- users_submit(users);
-/* #endif HAVE_GETUTXENT */
-#elif defined(HAVE_GETUTENT)
- unsigned int users = 0;
- struct utmp *entry = NULL;
+/* I don't like this temporary macro definition - well it's used everywhere
+ else in the collectd-sources, so I will just stick with it... */
+#define BUFSIZE 256
+static void
+users_submit(unsigned int users)
+{
+ char buf[BUFSIZE] = "";
- /* 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();
+ if (snprintf(buf, BUFSIZE, "%u:%u",
+ (unsigned int)curtime, users) >= BUFSIZE)
+ {
+ return;
+ }
- while (NULL != (entry = getutent()))
- if (USER_PROCESS == entry->ut_type)
- ++users;
- endutent();
+ plugin_submit(MODULE_NAME, NULL, buf);
+ return;
+} /* static void users_submit(unsigned int users) */
+#undef BUFSIZE
- users_submit(users);
-#endif
- return;
-}
-/* I don't like this temporary macro definition - well it's used everywhere
- * else in the collectd-sources, so I will just stick with it... */
-#define BUFSIZE 256
-void users_submit(users)
- unsigned int users;
+static void
+users_init(void)
{
- char buf[BUFSIZE] = "";
+ /* we have nothing to do here :-) */
+ return;
+} /* static void users_init(void) */
- if (snprintf(buf, BUFSIZE, "%u:%u",
- (unsigned int)curtime,
- users) >= BUFSIZE)
- return;
+static void
+users_read(void)
+{
+#if HAVE_GETUTXENT
+ unsigned int users = 0;
+ struct utmpx *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 */
+ setutxent();
+
+ while (NULL != (entry = getutxent())) {
+ if (USER_PROCESS == entry->ut_type) {
+ ++users;
+ }
+ }
+ endutxent();
+
+ users_submit(users);
+#else /* !HAVE_GETUTXENT */
+# if 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 /* HAVE_GETUTENT */
+#endif /* HAVE_GETUTXENT */
- plugin_submit(MODULE_NAME, NULL, buf);
- return;
-}
-#undef BUFSIZE
+ return;
+} /* static void users_read(void) */
-void users_write(host, inst, val)
- char *host;
- char *inst;
- char *val;
+static void
+users_write(char *host, char *inst, char *val)
{
- rrd_update_file(host, rrd_file, val, ds_def, ds_num);
- return;
-}
+ rrd_update_file(host, rrd_file, val, ds_def, ds_num);
+ return;
+} /* static void users_write(char *host, char *inst, char *val) */
-void module_register(void)
-{
- plugin_register(MODULE_NAME, users_init, users_read, users_write);
- return;
-}
-#undef MODULE_NAME
-#endif /* COLLECT_USERS */
+
+void
+module_register(void)
+{
+ plugin_register(MODULE_NAME, users_init, users_read, users_write);
+ return;
+} /* void module_register(void) */
diff --git a/src/users.h b/src/users.h
index 02f23dcdc27147cc58d6dd8866dbd6756dbde0a5..f67b83f78ef496b877796e5fa9116453b5bcf9d8 100644 (file)
--- a/src/users.h
+++ b/src/users.h
* Sebastian Harl <sh at tokkee.org>
**/
-#ifndef USERS_H
-#define USERS_H 1
+#if !COLLECTD_USERS_H
+#define COLLECTD_USERS_H 1
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
+void module_register(void);
-#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_UTMP_H)
-#define COLLECT_USERS 1
-#else
-#define COLLECT_USERS 0
-#endif
-#endif /* ! defined(COLLECT_USERS) */
-
-void users_init(void);
-void users_read(void);
-void users_submit(unsigned int);
-void users_write(char *, char *, char *);
-
-#endif /* ! defined(USERS_H) */
+#endif /* !COLLECTD_USERS_H) */