From 8cb9fb02319775bd9186c2f90f346acbf41b85f2 Mon Sep 17 00:00:00 2001 From: Kate Hsuan Date: Fri, 22 Mar 2024 20:01:04 +0800 Subject: [PATCH] up-config: The warning message for the risky CriticalPowerAction The warning message will be shown when CriticalPowerAction is "Suspend". One iwarning message is for enabling the risky CriticalPowerAction and the other is to show the potential risk when AllowRiskyCriticalPowerAction is true. --- etc/UPower.conf | 11 +++++++++-- src/up-config.c | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/etc/UPower.conf b/etc/UPower.conf index b9968a9..5e9ad31 100644 --- a/etc/UPower.conf +++ b/etc/UPower.conf @@ -81,6 +81,13 @@ TimeLow=1200 TimeCritical=300 TimeAction=120 +# Enable the risky CriticalPowerAction-Suspend +# This option is not recommended, but it is here for users who +# want to enable the riscky CriticalPowerAction, such as "Suspend" +# to fulfil their needs. +# Default is false +AllowRiskyCriticalPowerAction=false + # The action to take when "TimeAction" or "PercentageAction" above has been # reached for the batteries (UPS or laptop batteries) supplying the computer # @@ -88,9 +95,9 @@ TimeAction=120 # PowerOff # Hibernate # HybridSleep -# Suspend +# Suspend (AllowRiskyCriticalPowerAction should be true to use this option but risky) # -# If Suspend isn't available, HybridSleep will be used +# If Suspend isn't available or AllowRiskyCriticalPowerAction=false, Poweroff will be used # If HybridSleep isn't available, Hibernate will be used # If Hibernate isn't available, PowerOff will be used CriticalPowerAction=HybridSleep diff --git a/src/up-config.c b/src/up-config.c index f842ede..0531883 100644 --- a/src/up-config.c +++ b/src/up-config.c @@ -94,9 +94,11 @@ up_config_class_init (UpConfigClass *klass) static void up_config_init (UpConfig *config) { - gboolean ret; + gboolean allow_risky_critical_action = FALSE; + g_autofree gchar *critical_action = NULL; GError *error = NULL; gchar *filename; + gboolean ret; config->priv = up_config_get_instance_private (config); config->priv->keyfile = g_key_file_new (); @@ -117,6 +119,25 @@ up_config_init (UpConfig *config) g_error_free (error); } + /* Warn for any dangerous configurations */ + critical_action = up_config_get_string (config, "CriticalPowerAction"); + allow_risky_critical_action = up_config_get_boolean (config, "AllowRiskyCriticalPowerAction"); + + if (!g_strcmp0 (critical_action, "Suspend")) { + if (allow_risky_critical_action) { + g_warning ("The \"Suspend\" CriticalPowerAction setting is considered risky:" + " abrupt power loss due to battery exhaustion may lead to data" + " corruption. Use AllowRiskyCriticalPowerAction=false to disable" + " support for risky settings."); + } else { + g_warning ("The \"Suspend\" CriticalPowerAction setting is considered risky:" + " abrupt power loss due to battery exhaustion may lead to data" + " corruption. The system will perform \"HybridSleep\" instead." + " Use AllowRiskyCriticalPowerAction=true to enable support for" + " risky settings."); + } + } + g_free (filename); }