X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fshared%2Fbattery-util.c;h=37b3f6a6ea35767fa92c6920ddca4d593ba6b928;hb=HEAD;hp=43d72f9db751303b928109d80d5a8fa5d35ff4e4;hpb=18cad4ebda691981d3517f2e9bd61baa4d4bdce4;p=thirdparty%2Fsystemd.git diff --git a/src/shared/battery-util.c b/src/shared/battery-util.c index 43d72f9db75..37b3f6a6ea3 100644 --- a/src/shared/battery-util.c +++ b/src/shared/battery-util.c @@ -12,7 +12,7 @@ static int device_is_power_sink(sd_device *device) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool found_source = false, found_sink = false; - sd_device *parent, *d; + sd_device *parent; int r; assert(device); @@ -109,7 +109,6 @@ static bool battery_is_discharging(sd_device *d) { int on_ac_power(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool found_ac_online = false, found_discharging_battery = false; - sd_device *d; int r; r = sd_device_enumerator_new(&e); @@ -225,7 +224,7 @@ int battery_read_capacity_percentage(sd_device *dev) { return log_device_debug_errno(dev, r, "Failed to read/parse POWER_SUPPLY_CAPACITY: %m"); if (battery_capacity < 0 || battery_capacity > 100) - return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ERANGE), "Invalid battery capacity"); + return log_device_debug_errno(dev, SYNTHETIC_ERRNO(ERANGE), "Invalid battery capacity: %d", battery_capacity); return battery_capacity; } @@ -234,7 +233,6 @@ int battery_read_capacity_percentage(sd_device *dev) { int battery_is_discharging_and_low(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool unsure = false, found_low = false; - sd_device *dev; int r; /* We have not used battery capacity_level since value is set to full @@ -243,13 +241,13 @@ int battery_is_discharging_and_low(void) { r = on_ac_power(); if (r < 0) - log_debug_errno(r, "Failed to check if the system is running on AC, assuming it is not: %m"); + log_warning_errno(r, "Failed to check if the system is running on AC, assuming it is not: %m"); if (r > 0) return false; r = battery_enumerator_new(&e); if (r < 0) - return log_debug_errno(r, "Failed to initialize battery enumerator: %m"); + return log_error_errno(r, "Failed to initialize battery enumerator: %m"); FOREACH_DEVICE(e, dev) { int level; @@ -260,15 +258,23 @@ int battery_is_discharging_and_low(void) { continue; } - if (level > BATTERY_LOW_CAPACITY_LEVEL) /* Found a charged battery */ + if (level > BATTERY_LOW_CAPACITY_LEVEL) { /* Found a charged battery */ + log_device_full(dev, + found_low ? LOG_INFO : LOG_DEBUG, + "Found battery with capacity above threshold (%d%% > %d%%).", + level, BATTERY_LOW_CAPACITY_LEVEL); return false; + } + log_device_info(dev, + "Found battery with capacity below threshold (%d%% <= %d%%).", + level, BATTERY_LOW_CAPACITY_LEVEL); found_low = true; } /* If we found a battery whose state we couldn't read, don't assume we are in low battery state */ if (unsure) { - log_debug("Found battery with unreadable state, assuming not in low battery state."); + log_notice("Found battery with unreadable state, assuming not in low battery state."); return false; }