From 86e6aea152b61c5e9d9799127f54b0ef740d457d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 20 Jun 2020 11:02:57 +0200 Subject: [PATCH 1/2] module/battery: poll-interval = 0 now disables polling --- doc/yambar-modules.5.scd | 2 +- modules/battery.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/yambar-modules.5.scd b/doc/yambar-modules.5.scd index 00359c4..b9e1875 100644 --- a/doc/yambar-modules.5.scd +++ b/doc/yambar-modules.5.scd @@ -258,7 +258,7 @@ uses *udev* to monitor for changes. | poll-interval : int : no -: How often, in seconds, to poll for capacity changes (default=*60*) +: How often, in seconds, to poll for capacity changes (default=*60*). Set to `0` to disable polling (*warning*: many batteries do not support asynchronous reporting). ## EXAMPLES diff --git a/modules/battery.c b/modules/battery.c index 564d917..20eaad0 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -337,7 +337,7 @@ run(struct module *mod) {.fd = mod->abort_fd, .events = POLLIN}, {.fd = udev_monitor_get_fd(mon), .events = POLLIN}, }; - poll(fds, 2, m->poll_interval * 1000); + poll(fds, 2, m->poll_interval > 0 ? m->poll_interval * 1000 : -1); if (fds[0].revents & POLLIN) { ret = 0; From ae871853ca76a112de47064676d5812bc65c597f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 20 Jun 2020 11:21:44 +0200 Subject: [PATCH 2/2] module/battery: don't crash if 'sysname' in udev event is NULL --- modules/battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/battery.c b/modules/battery.c index 20eaad0..d394f94 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -348,7 +348,7 @@ run(struct module *mod) struct udev_device *dev = udev_monitor_receive_device(mon); const char *sysname = udev_device_get_sysname(dev); - bool is_us = strcmp(sysname, m->battery) == 0; + bool is_us = sysname != NULL && strcmp(sysname, m->battery) == 0; udev_device_unref(dev); if (!is_us)