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