mirror of
https://github.com/collectd/collectd.git
synced 2026-02-09 04:09:15 +08:00
turbostat: Fix parsing warnings
Fix warnings generated by the turbostat plugin due to trailing characters while picking out the first number in a range. ChangeLog: turbostat plugin: Fix parsing warnings. PR: #2365 Signed-off-by: Ryan McCabe <rmccabe@redhat.com> Signed-off-by: Florian Forster <octo@collectd.org>
This commit is contained in:
committed by
Florian Forster
parent
454fd81f51
commit
fe7335d14c
@@ -1042,7 +1042,11 @@ static int __attribute__((format(printf, 1, 2)))
|
||||
parse_int_file(const char *fmt, ...) {
|
||||
va_list args;
|
||||
char path[PATH_MAX];
|
||||
char buf[256];
|
||||
int len;
|
||||
value_t v;
|
||||
char *c;
|
||||
FILE *fp;
|
||||
|
||||
va_start(args, fmt);
|
||||
len = vsnprintf(path, sizeof(path), fmt, args);
|
||||
@@ -1052,8 +1056,29 @@ parse_int_file(const char *fmt, ...) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
value_t v;
|
||||
if (parse_value_file(path, &v, DS_TYPE_DERIVE) != 0) {
|
||||
fp = fopen(path, "r");
|
||||
if (fp == NULL) {
|
||||
ERROR("turbostat plugin: unable to open: '%s': %s", path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fgets(buf, sizeof(buf), fp) == NULL) {
|
||||
ERROR("turbostat plugin: unable to read: '%s': %s", path, strerror(errno));
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
/* We only care about the first integer in the range */
|
||||
c = strchr(buf, '-');
|
||||
if (c != NULL)
|
||||
*c = '\0';
|
||||
c = strchr(buf, ',');
|
||||
if (c != NULL)
|
||||
*c = '\0';
|
||||
strstripnewline(buf);
|
||||
|
||||
if (parse_value(buf, &v, DS_TYPE_DERIVE) != 0) {
|
||||
ERROR("turbostat plugin: Parsing \"%s\" failed.", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user