From: Ian Jackson Date: Tue, 15 Jul 2025 15:39:07 +0000 (+0100) Subject: Work around weird kernel behaviour with negative currents X-Git-Tag: archive/debian/8.0.1~2 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=d0addcced045e4e4d86e50fa4f82986d21232208;p=chiark-utils.git Work around weird kernel behaviour with negative currents Signed-off-by: Ian Jackson --- diff --git a/cprogs/xbatmon-simple.c b/cprogs/xbatmon-simple.c index 8dc6793..69b07d9 100644 --- a/cprogs/xbatmon-simple.c +++ b/cprogs/xbatmon-simple.c @@ -244,8 +244,13 @@ static int parse_value(const fileinfo *cfile, const batinfo_field *field) { if (!field->enumarray[0]) { + // Some kernels present a negative number for POWER_SUPPLY_CURRENT_NOW + // #1109342, #1109344 + const char *usevalue = batlinevalue; + if (*usevalue == '-') usevalue++; + char *ep; - *field->valuep= strtoull(batlinevalue,&ep,10); + *field->valuep= strtoull(usevalue,&ep,10); if (*ep) return batfailf("value number syntax incorrect");