From d0addcced045e4e4d86e50fa4f82986d21232208 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 15 Jul 2025 16:39:07 +0100 Subject: [PATCH] Work around weird kernel behaviour with negative currents Signed-off-by: Ian Jackson --- cprogs/xbatmon-simple.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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"); -- 2.30.2