X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fipmi.c;h=ad62299e3390bba91aedf9c5656f711643962e44;hb=4d370741101aeb037ae52f3529a4a0869e0dc08a;hp=44fae3550eae95a05dea5658cf939e85a0bb1040;hpb=6e419a825c50f9c97471aba7d50521bfc7e19828;p=collectd.git diff --git a/src/ipmi.c b/src/ipmi.c index 44fae355..ad62299e 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -1,7 +1,8 @@ /** * collectd - src/ipmi.c - * Copyright (C) 2008 Florian octo Forster - * Copyright (C) 2008 Peter Holik + * Copyright (C) 2008-2009 Florian octo Forster + * Copyright (C) 2008 Peter Holik + * Copyright (C) 2009 Bruno Prémont * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -17,17 +18,17 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Authors: - * Florian octo Forster + * Florian octo Forster * Peter Holik + * Bruno Prémont **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_ignorelist.h" -#include - #include #include #include @@ -80,9 +81,7 @@ static int c_ipmi_nofiy_notpresent = 0; */ static void c_ipmi_error (const char *func, int status) { - char errbuf[4096]; - - memset (errbuf, 0, sizeof (errbuf)); + char errbuf[4096] = { 0 }; if (IPMI_IS_OS_ERR (status)) { @@ -134,7 +133,7 @@ static void sensor_read_handler (ipmi_sensor_t *sensor, if (c_ipmi_nofiy_notpresent) { - notification_t n = { NOTIF_WARNING, time(NULL), "", "", "ipmi", + notification_t n = { NOTIF_WARNING, cdtime (), "", "", "ipmi", "", "", "", NULL }; sstrncpy (n.host, hostname_g, sizeof (n.host)); @@ -188,7 +187,7 @@ static void sensor_read_handler (ipmi_sensor_t *sensor, if (c_ipmi_nofiy_notpresent) { - notification_t n = { NOTIF_OKAY, time(NULL), "", "", "ipmi", + notification_t n = { NOTIF_OKAY, cdtime (), "", "", "ipmi", "", "", "", NULL }; sstrncpy (n.host, hostname_g, sizeof (n.host)); @@ -234,7 +233,7 @@ static int sensor_list_add (ipmi_sensor_t *sensor) c_ipmi_sensor_list_t *list_item; c_ipmi_sensor_list_t *list_prev; - char buffer[DATA_MAX_NAME_LEN]; + char buffer[DATA_MAX_NAME_LEN] = { 0 }; const char *entity_id_string; char sensor_name[DATA_MAX_NAME_LEN]; char *sensor_name_ptr; @@ -244,7 +243,6 @@ static int sensor_list_add (ipmi_sensor_t *sensor) sensor_id = ipmi_sensor_convert_to_id (sensor); - memset (buffer, 0, sizeof (buffer)); ipmi_sensor_get_name (sensor, buffer, sizeof (buffer)); buffer[sizeof (buffer) - 1] = 0; @@ -277,7 +275,7 @@ static int sensor_list_add (ipmi_sensor_t *sensor) { /* `sensor_id_ptr' now points to "(123)". */ ssnprintf (sensor_name, sizeof (sensor_name), - "%s %s", sensor_name_ptr, sensor_id_ptr); + "%s %s", sensor_name_ptr, sensor_id_ptr); } /* else: don't touch sensor_name. */ } @@ -361,7 +359,7 @@ static int sensor_list_add (ipmi_sensor_t *sensor) if (c_ipmi_nofiy_add && (c_ipmi_init_in_progress == 0)) { - notification_t n = { NOTIF_OKAY, time(NULL), "", "", "ipmi", + notification_t n = { NOTIF_OKAY, cdtime (), "", "", "ipmi", "", "", "", NULL }; sstrncpy (n.host, hostname_g, sizeof (n.host)); @@ -415,7 +413,7 @@ static int sensor_list_remove (ipmi_sensor_t *sensor) if (c_ipmi_nofiy_remove && c_ipmi_active) { - notification_t n = { NOTIF_WARNING, time(NULL), "", "", + notification_t n = { NOTIF_WARNING, cdtime (), "", "", "ipmi", "", "", "", NULL }; sstrncpy (n.host, hostname_g, sizeof (n.host)); @@ -434,11 +432,9 @@ static int sensor_list_remove (ipmi_sensor_t *sensor) static int sensor_list_read_all (void) { - c_ipmi_sensor_list_t *list_item; - pthread_mutex_lock (&sensor_list_lock); - for (list_item = sensor_list; + for (c_ipmi_sensor_list_t *list_item = sensor_list; list_item != NULL; list_item = list_item->next) { @@ -550,12 +546,11 @@ static void domain_connection_change_handler (ipmi_domain_t *domain, static int thread_init (os_handler_t **ret_os_handler) { os_handler_t *os_handler; - ipmi_open_option_t open_option[1]; ipmi_con_t *smi_connection = NULL; ipmi_domain_id_t domain_id; int status; - os_handler = ipmi_posix_thread_setup_os_handler (SIGUSR2); + os_handler = ipmi_posix_thread_setup_os_handler (SIGIO); if (os_handler == NULL) { ERROR ("ipmi plugin: ipmi_posix_thread_setup_os_handler failed."); @@ -574,9 +569,12 @@ static int thread_init (os_handler_t **ret_os_handler) return (-1); } - memset (open_option, 0, sizeof (open_option)); - open_option[0].option = IPMI_OPEN_OPTION_ALL; - open_option[0].ival = 1; + ipmi_open_option_t open_option[1] = { + [0] = { + .option = IPMI_OPEN_OPTION_ALL, + { .ival = 1 } + } + }; status = ipmi_open_domain ("mydomain", &smi_connection, /* num_con = */ 1, domain_connection_change_handler, /* user data = */ NULL, @@ -630,31 +628,23 @@ static int c_ipmi_config (const char *key, const char *value) else if (strcasecmp ("IgnoreSelected", key) == 0) { int invert = 1; - if ((strcasecmp ("True", value) == 0) - || (strcasecmp ("Yes", value) == 0) - || (strcasecmp ("On", value) == 0)) + if (IS_TRUE (value)) invert = 0; ignorelist_set_invert (ignorelist, invert); } else if (strcasecmp ("NotifySensorAdd", key) == 0) { - if ((strcasecmp ("True", value) == 0) - || (strcasecmp ("Yes", value) == 0) - || (strcasecmp ("On", value) == 0)) + if (IS_TRUE (value)) c_ipmi_nofiy_add = 1; } else if (strcasecmp ("NotifySensorRemove", key) == 0) { - if ((strcasecmp ("True", value) == 0) - || (strcasecmp ("Yes", value) == 0) - || (strcasecmp ("On", value) == 0)) + if (IS_TRUE (value)) c_ipmi_nofiy_remove = 1; } else if (strcasecmp ("NotifySensorNotPresent", key) == 0) { - if ((strcasecmp ("True", value) == 0) - || (strcasecmp ("Yes", value) == 0) - || (strcasecmp ("On", value) == 0)) + if (IS_TRUE (value)) c_ipmi_nofiy_notpresent = 1; } else @@ -670,11 +660,12 @@ static int c_ipmi_init (void) int status; /* Don't send `ADD' notifications during startup (~ 1 minute) */ - c_ipmi_init_in_progress = 1 + (60 / interval_g); + time_t iv = CDTIME_T_TO_TIME_T (plugin_get_interval ()); + c_ipmi_init_in_progress = 1 + (60 / iv); c_ipmi_active = 1; - status = pthread_create (&thread_id, /* attr = */ NULL, thread_main, + status = plugin_thread_create (&thread_id, /* attr = */ NULL, thread_main, /* user data = */ NULL); if (status != 0) {