[gnome-settings-daemon] power: Move is_hardware_a_virtual_machine() to gpm-common
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Move is_hardware_a_virtual_machine() to gpm-common
- Date: Wed, 16 Jan 2013 13:48:55 +0000 (UTC)
commit 205f4b5e54d6bc0e769c3b1416a9add31aa0b114
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jan 16 13:07:13 2013 +0100
power: Move is_hardware_a_virtual_machine() to gpm-common
plugins/power/gpm-common.c | 96 +++++++++++++++++++++++++++++++++++++
plugins/power/gpm-common.h | 4 ++
plugins/power/gsd-power-manager.c | 95 +------------------------------------
3 files changed, 101 insertions(+), 94 deletions(-)
---
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index 5e4b3ae..a9d8792 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -21,6 +21,9 @@
#include "config.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/wait.h>
#include <math.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -956,3 +959,96 @@ gpm_device_to_localised_string (UpDevice *device)
return gpm_device_kind_to_localised_string (kind, 1);
}
+
+static gboolean
+parse_vm_kernel_cmdline (gboolean *is_virtual_machine)
+{
+ gboolean ret = FALSE;
+ GRegex *regex;
+ GMatchInfo *match;
+ char *contents;
+ char *word;
+ const char *arg;
+
+ if (!g_file_get_contents ("/proc/cmdline", &contents, NULL, NULL))
+ return ret;
+
+ regex = g_regex_new ("gnome.is_vm=(\\S+)", 0, G_REGEX_MATCH_NOTEMPTY, NULL);
+ if (!g_regex_match (regex, contents, G_REGEX_MATCH_NOTEMPTY, &match))
+ goto out;
+
+ word = g_match_info_fetch (match, 0);
+ g_debug ("Found command-line match '%s'", word);
+ arg = word + strlen ("gnome.is_vm=");
+ if (*arg != '0' && *arg != '1') {
+ g_warning ("Invalid value '%s' for gnome.is_vm passed in kernel command line.\n", arg);
+ } else {
+ *is_virtual_machine = atoi (arg);
+ ret = TRUE;
+ }
+ g_free (word);
+
+out:
+ g_match_info_free (match);
+ g_regex_unref (regex);
+ g_free (contents);
+
+ if (ret)
+ g_debug ("Kernel command-line parsed to %d", *is_virtual_machine);
+
+ return ret;
+}
+
+gboolean
+gsd_power_is_hardware_a_vm (void)
+{
+ const gchar *str;
+ gboolean ret = FALSE;
+ GError *error = NULL;
+ GVariant *inner;
+ GVariant *variant = NULL;
+ GDBusConnection *connection;
+
+ if (parse_vm_kernel_cmdline (&ret))
+ return ret;
+
+ 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;
+}
diff --git a/plugins/power/gpm-common.h b/plugins/power/gpm-common.h
index d8a4758..1117308 100644
--- a/plugins/power/gpm-common.h
+++ b/plugins/power/gpm-common.h
@@ -27,6 +27,7 @@
G_BEGIN_DECLS
+/* UPower helpers */
gchar *gpm_get_timestring (guint time);
const gchar *gpm_device_to_localised_string (UpDevice *device);
const gchar *gpm_device_kind_to_localised_string (UpDeviceKind kind,
@@ -39,6 +40,9 @@ GIcon *gpm_upower_get_device_icon (UpDevice *device,
gchar *gpm_upower_get_device_summary (UpDevice *device);
gchar *gpm_upower_get_device_description (UpDevice *device);
+/* Power helpers */
+gboolean gsd_power_is_hardware_a_vm (void);
+
G_END_DECLS
#endif /* __GPMCOMMON_H */
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 205562d..5d13750 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -3973,99 +3973,6 @@ logind_proxy_signal_cb (GDBusProxy *proxy,
}
}
-static gboolean
-parse_vm_kernel_cmdline (gboolean *is_virtual_machine)
-{
- gboolean ret = FALSE;
- GRegex *regex;
- GMatchInfo *match;
- char *contents;
- char *word;
- const char *arg;
-
- if (!g_file_get_contents ("/proc/cmdline", &contents, NULL, NULL))
- return ret;
-
- regex = g_regex_new ("gnome.is_vm=(\\S+)", 0, G_REGEX_MATCH_NOTEMPTY, NULL);
- if (!g_regex_match (regex, contents, G_REGEX_MATCH_NOTEMPTY, &match))
- goto out;
-
- word = g_match_info_fetch (match, 0);
- g_debug ("Found command-line match '%s'", word);
- arg = word + strlen ("gnome.is_vm=");
- if (*arg != '0' && *arg != '1') {
- g_warning ("Invalid value '%s' for gnome.is_vm passed in kernel command line.\n", arg);
- } else {
- *is_virtual_machine = atoi (arg);
- ret = TRUE;
- }
- g_free (word);
-
-out:
- g_match_info_free (match);
- g_regex_unref (regex);
- g_free (contents);
-
- if (ret)
- g_debug ("Kernel command-line parsed to %d", *is_virtual_machine);
-
- return ret;
-}
-
-static gboolean
-is_hardware_a_virtual_machine (void)
-{
- const gchar *str;
- gboolean ret = FALSE;
- GError *error = NULL;
- GVariant *inner;
- GVariant *variant = NULL;
- GDBusConnection *connection;
-
- if (parse_vm_kernel_cmdline (&ret))
- return ret;
-
- 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)
@@ -4244,7 +4151,7 @@ gsd_power_manager_start (GsdPowerManager *manager,
disable_builtin_screensaver,
NULL);
/* don't blank inside a VM */
- manager->priv->is_virtual_machine = is_hardware_a_virtual_machine ();
+ manager->priv->is_virtual_machine = gsd_power_is_hardware_a_vm ();
gnome_settings_profile_end (NULL);
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]