diff --git a/src/ppd-driver-platform-profile.c b/src/ppd-driver-platform-profile.c index 8111251f3f507c0329d2a8be3eee73371bec7693..79820a3230e88c699e9dd16f83fa443c02df54b1 100644 --- a/src/ppd-driver-platform-profile.c +++ b/src/ppd-driver-platform-profile.c @@ -29,6 +29,9 @@ struct _PpdDriverPlatformProfile GFileMonitor *lapmode_mon; GFileMonitor *acpi_platform_profile_mon; guint acpi_platform_profile_changed_id; + + gboolean can_taint; + gboolean tainted; }; G_DEFINE_TYPE (PpdDriverPlatformProfile, ppd_driver_platform_profile, PPD_TYPE_DRIVER) @@ -174,6 +177,9 @@ update_acpi_platform_profile_state (PpdDriverPlatformProfile *self) { PpdProfile new_profile; + if (self->can_taint && !self->tainted) + self->tainted = ppd_utils_try_taint (); + new_profile = read_platform_profile (); if (new_profile == PPD_PROFILE_UNSET || new_profile == self->acpi_platform_profile) @@ -291,6 +297,9 @@ ppd_driver_platform_profile_probe (PpdDriver *driver) return self->probe_result; } + /* Check for customisation that would invalidate our work */ + self->can_taint = ppd_utils_can_taint (); + /* Lenovo-specific proximity sensor */ self->device = ppd_utils_find_device ("platform", (GCompareFunc) find_dytc, diff --git a/src/ppd-utils.c b/src/ppd-utils.c index 553a1e0894f2606019bbe0a5d6c0fd4cd2481526..ac8c7d93c85933fcd26bdb308c6b3655c1ae2dc9 100644 --- a/src/ppd-utils.c +++ b/src/ppd-utils.c @@ -115,3 +115,38 @@ ppd_utils_find_device (const char *subsystem, return ret; } + +/* Custom fan curves used in asus-wmi module */ +#define ENABLED_FAN_CURVE_PROFILES "/sys/devices/platform/asus-nb-wmi/enabled_fan_curve_profiles" + +gboolean +ppd_utils_can_taint (void) +{ + g_autofree char *fan_curves_file = NULL; + gboolean ret; + + fan_curves_file = ppd_utils_get_sysfs_path (ENABLED_FAN_CURVE_PROFILES); + ret = g_file_test (fan_curves_file, G_FILE_TEST_IS_REGULAR); + g_debug ("%s %s: %s taint", ret ? "Detected" : "Didn't detect", + ENABLED_FAN_CURVE_PROFILES, ret ? "can" : "cannot"); + return ret; +} + +gboolean +ppd_utils_try_taint (void) +{ + g_autofree char *fan_curves_file = NULL; + g_autofree char *contents = NULL; + g_autoptr(GError) error = NULL; + + fan_curves_file = ppd_utils_get_sysfs_path (ENABLED_FAN_CURVE_PROFILES); + if (g_file_get_contents (fan_curves_file, &contents, NULL, &error)) { + if (g_strcmp0 (g_strchomp (contents), "") != 0) { + g_warning ("Custom fan curves are in use, please revert to defaults before reporting any problems"); + return TRUE; + } + } else { + g_debug ("Failed to open %s: %s", ENABLED_FAN_CURVE_PROFILES, error->message); + } + return FALSE; +} diff --git a/src/ppd-utils.h b/src/ppd-utils.h index 9b12e5b897cdba51e784abdc9b54066958da328d..3e32fc36bb017cd3f23bc9addaf0b3afba4e0547 100644 --- a/src/ppd-utils.h +++ b/src/ppd-utils.h @@ -26,3 +26,6 @@ GFileMonitor *ppd_utils_monitor_sysfs_attr (GUdevDevice *device, GUdevDevice *ppd_utils_find_device (const char *subsystem, GCompareFunc func, gpointer user_data); + +gboolean ppd_utils_can_taint (void); +gboolean ppd_utils_try_taint (void); diff --git a/tests/integration-test.py b/tests/integration-test.py index a073e6ef5e4f7d85f3e0e2ca866c28c76b3f5bf6..969deab61b18e1969022b1798fdf786c289f596b 100755 --- a/tests/integration-test.py +++ b/tests/integration-test.py @@ -778,6 +778,43 @@ class Tests(dbusmock.DBusTestCase): self.stop_daemon() + def test_tainting(self): + '''check that custom fan curves throw a tainting warning''' + + self.create_platform_profile() + fan_curves_dir = os.path.join(self.testbed.get_root_dir(), "sys/devices/platform/asus-nb-wmi/") + os.makedirs(fan_curves_dir) + fan_curves_path = os.path.join(fan_curves_dir, "enabled_fan_curve_profiles") + with open(fan_curves_path, 'w') as curves: + curves.write("profile here\n") + + self.start_daemon() + self.assertEventually(lambda: self.have_text_in_log('Custom fan curves are in use')) + self.stop_daemon() + + os.remove(fan_curves_path) + os.removedirs(fan_curves_dir) + self.remove_platform_profile() + + def test_not_tainting(self): + '''check that fan curves don't throw a tainting warning if unset''' + + self.create_platform_profile() + fan_curves_dir = os.path.join(self.testbed.get_root_dir(), "sys/devices/platform/asus-nb-wmi/") + os.makedirs(fan_curves_dir) + fan_curves_path = os.path.join(fan_curves_dir, "enabled_fan_curve_profiles") + with open(fan_curves_path, 'w') as curves: + curves.write("\n") + + self.start_daemon() + self.assertEqual(self.get_dbus_property('ActiveProfile'), 'balanced') + self.assertEqual(self.count_text_in_log('Custom fan curves are in use'), 0) + self.stop_daemon() + + os.remove(fan_curves_path) + os.removedirs(fan_curves_dir) + self.remove_platform_profile() + # # Helper methods #