[gnome-settings-daemon/gnome-3-6] power: Do not attempt to suspend, dim or blank if running as a virtual machine
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/gnome-3-6] power: Do not attempt to suspend, dim or blank if running as a virtual machine
- Date: Thu, 1 Nov 2012 09:30:14 +0000 (UTC)
commit 6a5156050f445f8cf4b9456d6be5e36c0876cc6c
Author: Richard Hughes <richard hughsie com>
Date: Thu Oct 25 12:12:17 2012 +0100
power: Do not attempt to suspend, dim or blank if running as a virtual machine
Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=684801
plugins/power/gsd-power-manager.c | 62 +++++++++++++++++++++++++++++++++++++
1 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index f2de0f5..1c594d8 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -201,6 +201,7 @@ struct GsdPowerManagerPrivate
guint lid_close_safety_timer_id;
GtkStatusIcon *status_icon;
guint xscreensaver_watchdog_timer_id;
+ gboolean is_virtual_machine;
};
enum {
@@ -2946,6 +2947,13 @@ idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode)
manager->priv->current_idle_mode = mode;
g_debug ("Doing a state transition: %s", idle_mode_to_string (mode));
+ /* don't do any power saving if we're a VM */
+ if (manager->priv->is_virtual_machine) {
+ g_debug ("ignoring state transition to %s as virtual machine",
+ idle_mode_to_string (mode));
+ return;
+ }
+
/* save current brightness, and set dim level */
if (mode == GSD_POWER_IDLE_MODE_DIM) {
@@ -3696,6 +3704,57 @@ disable_builtin_screensaver (gpointer unused)
return TRUE;
}
+static gboolean
+is_hardware_a_virtual_machine (void)
+{
+ const gchar *str;
+ gboolean ret = FALSE;
+ GError *error = NULL;
+ GVariant *inner;
+ GVariant *variant = NULL;
+ GDBusConnection *connection;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
+ NULL,
+ &error);
+ if (connection == NULL) {
+ g_warning ("system bus not available: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ variant = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.DBus.Properties",
+ "Get",
+ g_variant_new ("(ss)",
+ "org.freedesktop.systemd1.Manager",
+ "Virtualization"),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (variant == NULL) {
+ g_debug ("Failed to get property '%s': %s", "Virtualization", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* on bare-metal hardware this is the empty string,
+ * otherwise an identifier such as "kvm", "vmware", etc. */
+ g_variant_get (variant, "(v)", &inner);
+ str = g_variant_get_string (inner, NULL);
+ if (str != NULL && str[0] != '\0')
+ ret = TRUE;
+out:
+ if (connection != NULL)
+ g_object_unref (connection);
+ if (variant != NULL)
+ g_variant_unref (variant);
+ return ret;
+}
+
gboolean
gsd_power_manager_start (GsdPowerManager *manager,
GError **error)
@@ -3856,6 +3915,9 @@ gsd_power_manager_start (GsdPowerManager *manager,
manager->priv->xscreensaver_watchdog_timer_id = g_timeout_add_seconds (XSCREENSAVER_WATCHDOG_TIMEOUT,
disable_builtin_screensaver,
NULL);
+ /* don't blank inside a VM */
+ manager->priv->is_virtual_machine = is_hardware_a_virtual_machine ();
+
gnome_settings_profile_end (NULL);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]