From: niki Date: Thu, 15 Dec 2005 09:53:31 +0000 (+0000) Subject: cleanup style X-Git-Tag: collectd-3.5.0~1^2~8 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=846dacf75f9b6f3e02039a93c19c893ecfd60d10;p=collectd.git cleanup style --- diff --git a/src/users.c b/src/users.c index 31c936c8..c423a3ee 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" -#include "plugin.h" -#include "common.h" +#if HAVE_UTMPX_H +# include +#else /* !HAVE_UTMPX_H */ +# if HAVE_UTMP_H +# include +# endif /* HAVE_UTMP_H */ +#endif /* HAVE_UTMPX_H */ -#ifdef HAVE_UTMPX_H -#include -#elif defined(HAVE_UTMP_H) -#include -#endif -static char *rrd_file = "users.rrd"; +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; +void +users_init(void) { - char buf[BUFSIZE] = ""; + /* we have nothing to do here :-) */ + return; +} /* void users_init(void) */ - if (snprintf(buf, BUFSIZE, "%u:%u", - (unsigned int)curtime, - users) >= BUFSIZE) - return; +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); +#endif /* 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 */ - 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) */