From: niki Date: Fri, 16 Dec 2005 17:37:31 +0000 (+0000) Subject: cleanup on users module X-Git-Tag: collectd-3.6.0~50 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea69d1db995ef08b02fb8d9acb48be59781deb62;p=collectd.git cleanup on users module --- diff --git a/src/users.c b/src/users.c index 31c936c8..486c7bdf 100644 --- a/src/users.c +++ b/src/users.c @@ -20,104 +20,121 @@ * Sebastian Harl **/ +#include "common.h" +#include "plugin.h" #include "users.h" -#if COLLECT_USERS -#define MODULE_NAME "users" +#if HAVE_UTMPX_H +# include +#else /* !HAVE_UTMPX_H */ +# if HAVE_UTMP_H +# include +# endif /* HAVE_UTMP_H */ +#endif /* HAVE_UTMPX_H */ -#include "plugin.h" -#include "common.h" -#ifdef HAVE_UTMPX_H -#include -#elif defined(HAVE_UTMP_H) -#include -#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 02f23dcd..f67b83f7 100644 --- a/src/users.h +++ b/src/users.h @@ -20,35 +20,10 @@ * Sebastian Harl **/ -#ifndef USERS_H -#define USERS_H 1 +#if !COLLECTD_USERS_H +#define COLLECTD_USERS_H 1 -#if HAVE_CONFIG_H -#include -#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) */