diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-10-13 08:37:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-10-13 08:38:18 +0000 |
commit | ca540a730c0b880922e86074f994a95b8d413bea (patch) | |
tree | 1364a1b82cfcc68f51aabf9b2545e6a06059d6bb /collectors/proc.plugin/sys_class_power_supply.c | |
parent | Releasing debian version 1.17.1-1. (diff) | |
download | netdata-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/sys_class_power_supply.c')
-rw-r--r-- | collectors/proc.plugin/sys_class_power_supply.c | 98 |
1 files changed, 53 insertions, 45 deletions
diff --git a/collectors/proc.plugin/sys_class_power_supply.c b/collectors/proc.plugin/sys_class_power_supply.c index 5e37ad5ab..c558a384d 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; + } } } } |