summaryrefslogtreecommitdiffstats
path: root/collectors/proc.plugin
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-10-13 08:37:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-10-13 08:38:18 +0000
commitca540a730c0b880922e86074f994a95b8d413bea (patch)
tree1364a1b82cfcc68f51aabf9b2545e6a06059d6bb /collectors/proc.plugin
parentReleasing debian version 1.17.1-1. (diff)
downloadnetdata-ca540a730c0b880922e86074f994a95b8d413bea.tar.xz
netdata-ca540a730c0b880922e86074f994a95b8d413bea.zip
Merging upstream version 1.18.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/proc.plugin')
-rw-r--r--collectors/proc.plugin/proc_mdstat.c2
-rw-r--r--collectors/proc.plugin/sys_block_zram.c8
-rw-r--r--collectors/proc.plugin/sys_class_power_supply.c98
3 files changed, 60 insertions, 48 deletions
diff --git a/collectors/proc.plugin/proc_mdstat.c b/collectors/proc.plugin/proc_mdstat.c
index 5c29d31c..abfd2ff1 100644
--- a/collectors/proc.plugin/proc_mdstat.c
+++ b/collectors/proc.plugin/proc_mdstat.c
@@ -197,7 +197,7 @@ int do_proc_mdstat(int update_every, usec_t dt) {
}
s++;
}
- if(unlikely(str_total[0] == '\0' || str_inuse[0] == '\0')) {
+ if(unlikely(str_total[0] == '\0' || !str_inuse || str_inuse[0] == '\0')) {
error("Cannot read /proc/mdstat raid health status. Unexpected format.");
continue;
}
diff --git a/collectors/proc.plugin/sys_block_zram.c b/collectors/proc.plugin/sys_block_zram.c
index a68a405d..170c7206 100644
--- a/collectors/proc.plugin/sys_block_zram.c
+++ b/collectors/proc.plugin/sys_block_zram.c
@@ -181,10 +181,14 @@ static inline int read_mm_stat(procfile *ff, MM_STAT *stats) {
ff = procfile_readall(ff);
if (!ff)
return -1;
- if (procfile_lines(ff) < 1)
+ if (procfile_lines(ff) < 1) {
+ procfile_close(ff);
return -1;
- if (procfile_linewords(ff, 0) < 7)
+ }
+ if (procfile_linewords(ff, 0) < 7) {
+ procfile_close(ff);
return -1;
+ }
stats->orig_data_size = str2ull(procfile_word(ff, 0));
stats->compr_data_size = str2ull(procfile_word(ff, 1));
diff --git a/collectors/proc.plugin/sys_class_power_supply.c b/collectors/proc.plugin/sys_class_power_supply.c
index 5e37ad5a..c558a384 100644
--- a/collectors/proc.plugin/sys_class_power_supply.c
+++ b/collectors/proc.plugin/sys_class_power_supply.c
@@ -245,67 +245,75 @@ int do_sys_class_power_supply(int update_every, usec_t dt) {
if(unlikely(ps->capacity->fd == -1)) {
error("Cannot open file '%s'", ps->capacity->filename);
power_supply_free(ps);
+ ps = NULL;
}
}
- ssize_t r = read(ps->capacity->fd, buffer, 30);
- if(unlikely(r < 1)) {
- error("Cannot read file '%s'", ps->capacity->filename);
- power_supply_free(ps);
- }
- else {
- buffer[r] = '\0';
- ps->capacity->value = str2ull(buffer);
- }
+ if (ps)
+ {
+ ssize_t r = read(ps->capacity->fd, buffer, 30);
+ if(unlikely(r < 1)) {
+ error("Cannot read file '%s'", ps->capacity->filename);
+ power_supply_free(ps);
+ ps = NULL;
+ }
+ else {
+ buffer[r] = '\0';
+ ps->capacity->value = str2ull(buffer);
- if(unlikely(!keep_fds_open)) {
- close(ps->capacity->fd);
- ps->capacity->fd = -1;
- }
- else if(unlikely(lseek(ps->capacity->fd, 0, SEEK_SET) == -1)) {
- error("Cannot seek in file '%s'", ps->capacity->filename);
- close(ps->capacity->fd);
- ps->capacity->fd = -1;
+ if(unlikely(!keep_fds_open)) {
+ close(ps->capacity->fd);
+ ps->capacity->fd = -1;
+ }
+ else if(unlikely(lseek(ps->capacity->fd, 0, SEEK_SET) == -1)) {
+ error("Cannot seek in file '%s'", ps->capacity->filename);
+ close(ps->capacity->fd);
+ ps->capacity->fd = -1;
+ }
+ }
}
}
// read property files
int read_error = 0;
struct ps_property *pr;
- for(pr = ps->property_root; pr && !read_error; pr = pr->next) {
- struct ps_property_dim *pd;
- for(pd = pr->property_dim_root; pd; pd = pd->next) {
- if(likely(!pd->always_zero)) {
- char buffer[30 + 1];
-
- if(unlikely(pd->fd == -1)) {
- pd->fd = open(pd->filename, O_RDONLY, 0666);
+ if (ps)
+ {
+ for(pr = ps->property_root; pr && !read_error; pr = pr->next) {
+ struct ps_property_dim *pd;
+ for(pd = pr->property_dim_root; pd; pd = pd->next) {
+ if(likely(!pd->always_zero)) {
+ char buffer[30 + 1];
+
if(unlikely(pd->fd == -1)) {
- error("Cannot open file '%s'", pd->filename);
+ pd->fd = open(pd->filename, O_RDONLY, 0666);
+ if(unlikely(pd->fd == -1)) {
+ error("Cannot open file '%s'", pd->filename);
+ read_error = 1;
+ power_supply_free(ps);
+ break;
+ }
+ }
+
+ ssize_t r = read(pd->fd, buffer, 30);
+ if(unlikely(r < 1)) {
+ error("Cannot read file '%s'", pd->filename);
read_error = 1;
power_supply_free(ps);
break;
}
- }
-
- ssize_t r = read(pd->fd, buffer, 30);
- if(unlikely(r < 1)) {
- error("Cannot read file '%s'", pd->filename);
- read_error = 1;
- power_supply_free(ps);
- break;
- }
- buffer[r] = '\0';
- pd->value = str2ull(buffer);
+ buffer[r] = '\0';
+ pd->value = str2ull(buffer);
- if(unlikely(!keep_fds_open)) {
- close(pd->fd);
- pd->fd = -1;
- }
- else if(unlikely(lseek(pd->fd, 0, SEEK_SET) == -1)) {
- error("Cannot seek in file '%s'", pd->filename);
- close(pd->fd);
- pd->fd = -1;
+ if(unlikely(!keep_fds_open)) {
+ close(pd->fd);
+ pd->fd = -1;
+ }
+ else if(unlikely(lseek(pd->fd, 0, SEEK_SET) == -1)) {
+ error("Cannot seek in file '%s'", pd->filename);
+ close(pd->fd);
+ pd->fd = -1;
+ }
}
}
}