From 23253ce0b022470a047eb6b512fb85beaf884388 Mon Sep 17 00:00:00 2001 From: vg Date: Fri, 5 Oct 2018 09:54:15 +0200 Subject: make parsing more robust with explicit split/strip --- scripts/critical_hibernate.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/critical_hibernate.py b/scripts/critical_hibernate.py index f7128e2..a51a97c 100755 --- a/scripts/critical_hibernate.py +++ b/scripts/critical_hibernate.py @@ -39,8 +39,9 @@ try: batfd = os.open(sysfs_path, os.O_RDONLY) print('monitoring %s (threshold %d%%)' % (sysfs_path, threshold)) while True: - uevent_dict = dict((e.split(b'=') - for e in os.pread(batfd, 1024, 0).split())) + uevent_dict = dict((tuple(x.strip() for x in e.split(b'=')) + for e in os.pread(batfd, 1024, 0).split(b'\n') + if e)) capacity = int(uevent_dict[b'POWER_SUPPLY_CAPACITY']) status = uevent_dict[b'POWER_SUPPLY_STATUS'] if status == b'Discharging' and capacity <= threshold: -- cgit v1.2.3