return 0;
}
-static int siphash24_compress_device_sysattr(sd_device *dev, const char *attr, struct siphash *state) {
+static int siphash24_compress_device_sysattr(
+ sd_device *dev,
+ const char *attr,
+ struct siphash *state) {
+
const char *x;
int r;
return 0;
}
-static int siphash24_compress_id128(int (*getter)(sd_id128_t*), const char *name, struct siphash *state) {
+static int siphash24_compress_id128(
+ int (*getter)(sd_id128_t *ret),
+ const char *name,
+ struct siphash *state) {
+
sd_id128_t id;
int r;
assert(getter);
+ assert(name);
assert(state);
r = getter(&id);
}
/* Read system and battery identifier from specific location and generate hash of it */
-static int get_system_battery_identifier_hash(sd_device *dev, uint64_t *ret) {
+static uint64_t system_battery_identifier_hash(sd_device *dev) {
struct siphash state;
- assert(ret);
assert(dev);
siphash24_init(&state, BATTERY_DISCHARGE_RATE_HASH_KEY.bytes);
(void) siphash24_compress_id128(sd_id128_get_machine, "machine", &state);
(void) siphash24_compress_id128(id128_get_product, "product", &state);
- *ret = siphash24_finalize(&state);
- return 0;
+ return siphash24_finalize(&state);
}
/* Return success if battery percentage discharge rate per hour is in the range 1–199 */
if (!f)
return log_debug_errno(errno, "Failed to read discharge rate from " DISCHARGE_RATE_FILEPATH ": %m");
- r = get_system_battery_identifier_hash(dev, ¤t_hash_id);
- if (r < 0)
- return log_device_debug_errno(dev, r, "Failed to generate system battery identifier hash: %m");
+ current_hash_id = system_battery_identifier_hash(dev);
for (;;) {
_cleanup_free_ char *stored_hash_id = NULL, *stored_discharge_rate = NULL, *line = NULL;
continue;
}
- r = get_system_battery_identifier_hash(dev, &system_hash_id);
- if (r < 0)
- return log_device_debug_errno(dev, r, "Failed to generate system battery identifier hash: %m");
+ system_hash_id = system_battery_identifier_hash(dev);
log_device_debug(dev,
"%d%% was discharged in %s. Estimating discharge rate...",