X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbattery.c;h=fbc64f473646aa52ea8fd14015c2a168540a71c6;hb=fa82af13503a1195e1bfaef597ac33a3dc71a758;hp=3e6d7bda9de2a088e5763f7518af1bf1f1b072a7;hpb=806091e395886da83acf2435e90648bdf2cf2ed5;p=collectd.git diff --git a/src/battery.c b/src/battery.c index 3e6d7bda..fbc64f47 100644 --- a/src/battery.c +++ b/src/battery.c @@ -78,14 +78,10 @@ static _Bool query_statefs = 0; static void battery_submit2 (char const *plugin_instance, /* {{{ */ char const *type, char const *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "battery", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, type, sizeof (vl.type)); @@ -392,47 +388,17 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */ char const *basename, char *buffer, size_t buffer_size) { - int status; - FILE *fp; char filename[PATH_MAX]; + int status; ssnprintf (filename, sizeof (filename), "%s/%s/%s", dir, power_supply, basename); - /* No file isn't the end of the world -- not every system will be - * reporting the same set of statistics */ - if (access (filename, R_OK) != 0) - return ENOENT; - - fp = fopen (filename, "r"); - if (fp == NULL) - { - status = errno; - if (status != ENOENT) - { - char errbuf[1024]; - WARNING ("battery plugin: fopen (%s) failed: %s", filename, - sstrerror (status, errbuf, sizeof (errbuf))); - } + status = (int) read_file_contents (filename, buffer, buffer_size); + if (status < 0) return status; - } - - if (fgets (buffer, buffer_size, fp) == NULL) - { - status = errno; - if (status != ENODEV) - { - char errbuf[1024]; - WARNING ("battery plugin: fgets (%s) failed: %s", filename, - sstrerror (status, errbuf, sizeof (errbuf))); - } - fclose (fp); - return status; - } strstripnewline (buffer); - - fclose (fp); return 0; } /* }}} int sysfs_file_to_buffer */ @@ -802,7 +768,7 @@ static int battery_read (void) /* {{{ */ if (status == 0) return (0); - ERROR ("battery plugin: Add available input methods failed."); + ERROR ("battery plugin: All available input methods failed."); return (-1); } /* }}} int battery_read */ #endif /* KERNEL_LINUX */