module/battery: handle 'manufacturer' and 'model_name' not being present

This commit is contained in:
Daniel Eklöf 2020-06-05 13:29:38 +02:00
parent d108cce689
commit cc9c5109e9
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -3,6 +3,7 @@
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <poll.h>
@ -159,23 +160,25 @@ initialize(struct private *m)
{
int fd = openat(base_dir_fd, "manufacturer", O_RDONLY);
if (fd == -1) {
LOG_ERRNO("/sys/class/power_supply/%s/manufacturer", m->battery);
goto err;
LOG_WARN("/sys/class/power_supply/%s/manufacturer: %s",
m->battery, strerror(errno));
m->manufacturer = NULL;
} else {
m->manufacturer = strdup(readline_from_fd(fd));
close(fd);
}
m->manufacturer = strdup(readline_from_fd(fd));
close(fd);
}
{
int fd = openat(base_dir_fd, "model_name", O_RDONLY);
if (fd == -1) {
LOG_ERRNO("/sys/class/power_supply/%s/model_name", m->battery);
goto err;
LOG_WARN("/sys/class/power_supply/%s/model_name: %s",
m->battery, strerror(errno));
m->model = NULL;
} else {
m->model = strdup(readline_from_fd(fd));
close(fd);
}
m->model = strdup(readline_from_fd(fd));
close(fd);
}
{