X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fipmi.c;h=95b3dbf5625fcd4c09aef04d2a880c5ca85d2ae8;hb=0d5c879672770e3b8a740727fb223a6febdeaa27;hp=105907055824c883dc1b473674cb179cdc3e9f18;hpb=56159e13f4b983a2e8c846b39ca96b2384ec746a;p=collectd.git diff --git a/src/ipmi.c b/src/ipmi.c index 10590705..95b3dbf5 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 @@ -19,6 +20,7 @@ * Authors: * Florian octo Forster * Peter Holik + * Bruno Prémont **/ #include "collectd.h" @@ -111,9 +113,9 @@ static int sensor_list_remove (ipmi_sensor_t *sensor); static void sensor_read_handler (ipmi_sensor_t *sensor, int err, enum ipmi_value_present_e value_present, - unsigned int raw_value, + unsigned int __attribute__((unused)) raw_value, double value, - ipmi_states_t *states, + ipmi_states_t __attribute__((unused)) *states, void *user_data) { value_t values[1]; @@ -234,35 +236,54 @@ 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]; + const char *entity_id_string; char sensor_name[DATA_MAX_NAME_LEN]; char *sensor_name_ptr; - int sensor_type, len; + int sensor_type; const char *type; ipmi_entity_t *ent = ipmi_sensor_get_entity(sensor); sensor_id = ipmi_sensor_convert_to_id (sensor); - memset (sensor_name, 0, sizeof (sensor_name)); - ipmi_sensor_get_name (sensor, sensor_name, sizeof (sensor_name)); - sensor_name[sizeof (sensor_name) - 1] = 0; + memset (buffer, 0, sizeof (buffer)); + ipmi_sensor_get_name (sensor, buffer, sizeof (buffer)); + buffer[sizeof (buffer) - 1] = 0; - len = DATA_MAX_NAME_LEN - strlen(sensor_name); - strncat(sensor_name, " ", len--); - strncat(sensor_name, ipmi_entity_get_entity_id_string(ent), len); + entity_id_string = ipmi_entity_get_entity_id_string (ent); - sensor_name_ptr = strstr (sensor_name, ")."); - if (sensor_name_ptr == NULL) - sensor_name_ptr = sensor_name; + if (entity_id_string == NULL) + sstrncpy (sensor_name, buffer, sizeof (sensor_name)); else - { - char *sensor_name_ptr_id = strstr (sensor_name, "("); - + ssnprintf (sensor_name, sizeof (sensor_name), + "%s %s", buffer, entity_id_string); + + sstrncpy (buffer, sensor_name, sizeof (buffer)); + sensor_name_ptr = strstr (buffer, ")."); + if (sensor_name_ptr != NULL) + { + /* If name is something like "foo (123).bar", + * change that to "bar (123)". + * Both, sensor_name_ptr and sensor_id_ptr point to memory within the + * `buffer' array, which holds a copy of the current `sensor_name'. */ + char *sensor_id_ptr; + + /* `sensor_name_ptr' points to ").bar". */ + sensor_name_ptr[1] = 0; + /* `buffer' holds "foo (123)\0bar\0". */ sensor_name_ptr += 2; - len = DATA_MAX_NAME_LEN - strlen(sensor_name); - strncat(sensor_name, " ", len--); - strncat(sensor_name, sensor_name_ptr_id, - MIN(sensor_name_ptr - sensor_name_ptr_id - 1, len)); + /* `sensor_name_ptr' now points to "bar". */ + + sensor_id_ptr = strstr (buffer, "("); + if (sensor_id_ptr != NULL) + { + /* `sensor_id_ptr' now points to "(123)". */ + ssnprintf (sensor_name, sizeof (sensor_name), + "%s %s", sensor_name_ptr, sensor_id_ptr); + } + /* else: don't touch sensor_name. */ } + sensor_name_ptr = sensor_name; /* Both `ignorelist' and `plugin_instance' may be NULL. */ if (ignorelist_match (ignorelist, sensor_name_ptr) != 0) @@ -459,9 +480,9 @@ static int sensor_list_remove_all (void) * Entity handlers */ static void entity_sensor_update_handler (enum ipmi_update_e op, - ipmi_entity_t *entity, + ipmi_entity_t __attribute__((unused)) *entity, ipmi_sensor_t *sensor, - void *user_data) + void __attribute__((unused)) *user_data) { /* TODO: Ignore sensors we cannot read */ @@ -480,9 +501,9 @@ static void entity_sensor_update_handler (enum ipmi_update_e op, * Domain handlers */ static void domain_entity_update_handler (enum ipmi_update_e op, - ipmi_domain_t *domain, + ipmi_domain_t __attribute__((unused)) *domain, ipmi_entity_t *entity, - void *user_data) + void __attribute__((unused)) *user_data) { int status; @@ -574,7 +595,7 @@ static int thread_init (os_handler_t **ret_os_handler) return (0); } /* int thread_init */ -static void *thread_main (void *user_data) +static void *thread_main (void __attribute__((unused)) *user_data) { int status; os_handler_t *os_handler = NULL; @@ -611,31 +632,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