Avoid filling the logs with repeated warning saying that no correct voltage value was found for a power device. Improves the situation with bugs https://bugzilla.redhat.com/show_bug.cgi?id=847874 and https://bugzilla.redhat.com/show_bug.cgi?id=863524
Signed-off-by: Timothée Ravier <t...@siosm.fr> --- src/linux/up-device-supply.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index a93d16a..4a015d0 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -376,6 +376,7 @@ up_device_supply_get_design_voltage (const gchar *native_path) { gdouble voltage; gchar *device_type = NULL; + static GHashTable *devices_already_warned = NULL; /* design maximum */ voltage = sysfs_get_double (native_path, "voltage_max_design") / 1000000.0; @@ -413,8 +414,17 @@ up_device_supply_get_design_voltage (const gchar *native_path) goto out; } + /* no valid value found; display a warning the first time for each + * device */ + if (devices_already_warned == NULL) { + devices_already_warned = g_hash_table_new(g_str_hash, g_str_equal); + } + if (g_hash_table_lookup(devices_already_warned, native_path) == NULL) { + g_hash_table_insert(devices_already_warned, (gpointer) native_path, (gpointer) 1); + g_warning ("no valid voltage value found for device: %s", native_path); + g_warning ("using 10V as approximation for device: %s", native_path); + } /* completely guess, to avoid getting zero values */ - g_warning ("no voltage values for device %s, using 10V as approximation", native_path); voltage = 10.0f; out: g_free (device_type); -- 1.8.4 _______________________________________________ devkit-devel mailing list devkit-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/devkit-devel