hal: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Tue Mar 20 14:46:35 PDT 2007


 NEWS                                           |    1 
 fdi/policy/10osvendor/10-power-mgmt-policy.fdi |    5 +
 hald/linux/osspec.c                            |   47 +++++++++----
 tools/Makefile.am                              |    7 +
 tools/hal-system-power-pm-is-supported.c       |   88 +++++++++++++++++++++++++
 tools/hal-system-power-suspend-hybrid          |   56 +++++++++++++++
 6 files changed, 189 insertions(+), 15 deletions(-)

New commits:
diff-tree ce6d8df0c1be9518df9187660915890415287e4a (from a48af028e1e48dcd89740153a3da2bfebbec0867)
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Mar 20 17:46:30 2007 -0400

    add support for SuspendHybrid and make use of pm-is-supported

diff --git a/NEWS b/NEWS
index 6fd2204..d16f1a1 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Requirements for HAL 0.5.9 ""
  - parted           == 1.7.1     (optional)
  - cryptsetup-luks  >= 1.0.1     (optional, needs LUKS patches)
  - ConsoleKit       >= git version as of 20070220 (optional)
+ - pm-utils         >= 0.99.2 or newer
 
 ==========
 HAL 0.5.8 "The Skynet Funding Bill is passed."
diff --git a/fdi/policy/10osvendor/10-power-mgmt-policy.fdi b/fdi/policy/10osvendor/10-power-mgmt-policy.fdi
index e0607fd..ec5613f 100644
--- a/fdi/policy/10osvendor/10-power-mgmt-policy.fdi
+++ b/fdi/policy/10osvendor/10-power-mgmt-policy.fdi
@@ -31,6 +31,11 @@
       <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_argnames" type="strlist">num_seconds_to_sleep</append>
       <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_execpaths" type="strlist">hal-system-power-suspend</append>
 
+      <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_names" type="strlist">SuspendHybrid</append>
+      <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_signatures" type="strlist">i</append>
+      <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_argnames" type="strlist">num_seconds_to_sleep</append>
+      <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_execpaths" type="strlist">hal-system-power-suspend-hybrid</append>
+
       <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_names" type="strlist">Hibernate</append>
       <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_signatures" type="strlist"></append>
       <append key="org.freedesktop.Hal.Device.SystemPowerManagement.method_argnames" type="strlist"></append>
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 838ed80..13e943a 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -620,6 +620,7 @@ set_suspend_hibernate_keys (HalDevice *d
 		can_hibernate = TRUE;
 out:
 	hal_device_property_set_bool (d, "power_management.can_suspend", can_suspend);
+	hal_device_property_set_bool (d, "power_management.can_suspend_hybrid", FALSE);
 	hal_device_property_set_bool (d, "power_management.can_hibernate", can_hibernate);
 
 	/* WARNING: These keys are depreciated and power_management.can_suspend
@@ -695,15 +696,37 @@ probe_openfirmware(HalDevice *root) 
 	detect_openfirmware_formfactor(root);
 }
 
+static void
+decode_dmi (HalDevice *d)
+{
+        if (g_file_test ("/usr/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) ||
+            g_file_test ("/bin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) ||
+            g_file_test ("/sbin/dmidecode", G_FILE_TEST_IS_EXECUTABLE) ||
+            g_file_test ("/usr/local/sbin//dmidecode", G_FILE_TEST_IS_EXECUTABLE)) {
+                hald_runner_run (d, "hald-probe-smbios", NULL, HAL_HELPER_TIMEOUT,
+                                 computer_probing_pcbios_helper_done, NULL, NULL);
+        } else {
+                /* no probing */
+                probe_openfirmware (d);
+                computer_probing_helper_done (d);
+        }
+
+}
+
+static void 
+computer_probing_pm_is_supported_helper_done (HalDevice *d, guint32 exit_type, 
+                                              gint return_code, gchar **error, 
+                                              gpointer data1, gpointer data2)
+{
+        HAL_INFO (("In computer_probing_pm_is_supported_helper_done"));
+        decode_dmi (d);
+}
 
 void 
 osspec_probe (void)
 {
 	HalDevice *root;
 	struct utsname un;
-	gboolean should_decode_dmi;
-
-	should_decode_dmi = FALSE;
 
 	hald_runner_set_method_run_notify ((HaldRunnerRunNotify) hotplug_event_process_queue, NULL);
 	root = hal_device_new ();
@@ -729,12 +752,10 @@ osspec_probe (void)
 	HAL_INFO (("Synthesizing powermgmt events..."));
 	if (acpi_synthesize_hotplug_events ()) {
 		HAL_INFO (("ACPI capabilities found"));
-		should_decode_dmi = TRUE;
 	} else if (pmu_synthesize_hotplug_events ()) {
 		HAL_INFO (("PMU capabilities found"));		
 	} else if (apm_synthesize_hotplug_events ()) {
 		HAL_INFO (("APM capabilities found"));		
-		should_decode_dmi = TRUE;
 	} else {
 		HAL_INFO (("No powermgmt capabilities"));		
 	}
@@ -748,14 +769,14 @@ osspec_probe (void)
 	 */
 	set_suspend_hibernate_keys (root);
 
-	if (should_decode_dmi) {
-		hald_runner_run (root, "hald-probe-smbios", NULL, HAL_HELPER_TIMEOUT,
-        	                 computer_probing_pcbios_helper_done, NULL, NULL);
-	} else {
-		/* no probing */
-		probe_openfirmware(root);
-		computer_probing_helper_done (root);
-	}
+        /* Try and set the suspend/hibernate keys using pm-is-supported
+         */
+        if (g_file_test ("/usr/bin/pm-is-supported", G_FILE_TEST_IS_EXECUTABLE)) {
+                hald_runner_run (root, "hal-system-power-pm-is-supported", NULL, HAL_HELPER_TIMEOUT,
+                                 computer_probing_pm_is_supported_helper_done, NULL, NULL);
+        } else {
+                decode_dmi (root);
+        }
 }
 
 DBusHandlerResult
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4909974..492d2f8 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -55,7 +55,8 @@ libexec_PROGRAMS =                      
 	hal-storage-eject	            \
 	hal-storage-closetray	            \
 	hal-storage-cleanup-mountpoint      \
-	hal-storage-cleanup-all-mountpoints
+	hal-storage-cleanup-all-mountpoints \
+	hal-system-power-pm-is-supported
 
 if HAVE_PMU
 libexec_PROGRAMS +=			    \
@@ -74,7 +75,8 @@ hal_acl_tool_SOURCES = hal-acl-tool.c
 hal_acl_tool_LDADD = @GLIB_LIBS@ $(top_builddir)/libhal/libhal.la
 endif
 
-
+hal_system_power_pm_is_supported_SOURCES = hal-system-power-pm-is-supported.c
+hal_system_power_pm_is_supported_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
 
 hal_storage_mount_SOURCES = hal-storage-mount.c hal-storage-shared.c hal-storage-shared.h
 hal_storage_mount_LDADD = @GLIB_LIBS@ @POLKIT_LIBS@ @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la $(top_builddir)/libhal-storage/libhal-storage.la
@@ -111,6 +113,7 @@ script_SCRIPTS =				\
 	hal-luks-teardown                       \
 	hal-luks-remove		                \
 	hal-system-power-suspend		\
+	hal-system-power-suspend-hybrid		\
 	hal-system-power-hibernate		\
 	hal-system-power-shutdown		\
 	hal-system-power-reboot			\
diff --git a/tools/hal-system-power-pm-is-supported.c b/tools/hal-system-power-pm-is-supported.c
new file mode 100644
index 0000000..99c9181
--- /dev/null
+++ b/tools/hal-system-power-pm-is-supported.c
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * hal-storage-mount.c : Mount wrapper
+ *
+ * Copyright (C) 2006 David Zeuthen, <david at fubar.dk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <libhal.h>
+#include <glib.h>
+
+int
+main (int argc, char *argv[])
+{
+        int ret;
+	char *udi;
+	DBusError error;
+	LibHalContext *hal_ctx = NULL;
+        LibHalChangeSet *cs;
+        gboolean can_suspend = FALSE;
+        gboolean can_suspend_hybrid = FALSE;
+        gboolean can_hibernate = FALSE;
+        int exit_status;
+
+        ret = 1;
+
+	udi = getenv ("HAL_PROP_INFO_UDI");
+	if (udi == NULL)
+                goto out;
+
+	dbus_error_init (&error);
+	if ((hal_ctx = libhal_ctx_init_direct (&error)) == NULL) {
+		printf ("Cannot connect to hald\n");
+		if (dbus_error_is_set (&error)) {
+			dbus_error_free (&error);
+		}
+                goto out;
+	}
+
+	cs = libhal_device_new_changeset (udi);
+	if (cs == NULL) {
+		printf ("Cannot initialize changeset\n");
+		goto out;
+	}
+
+        g_spawn_command_line_sync ("/usr/bin/pm-is-supported --suspend", NULL, NULL, &exit_status, NULL);
+        can_suspend = (exit_status == 0);
+        g_spawn_command_line_sync ("/usr/bin/pm-is-supported --suspend-hybrid", NULL, NULL, &exit_status, NULL);
+        can_suspend_hybrid = (exit_status == 0);
+        g_spawn_command_line_sync ("/usr/bin/pm-is-supported --hibernate", NULL, NULL, &exit_status, NULL);
+        can_hibernate = (exit_status == 0);
+
+        libhal_changeset_set_property_bool (cs, "power_management.can_suspend", can_suspend);
+        libhal_changeset_set_property_bool (cs, "power_management.can_suspend_hybrid", can_suspend_hybrid);
+        libhal_changeset_set_property_bool (cs, "power_management.can_hibernate", can_hibernate);
+
+        libhal_device_commit_changeset (hal_ctx, cs, &error);
+        libhal_device_free_changeset (cs);
+
+        ret = 0;
+out:
+	return ret;
+}
diff --git a/tools/hal-system-power-suspend-hybrid b/tools/hal-system-power-suspend-hybrid
new file mode 100755
index 0000000..e851fe8
--- /dev/null
+++ b/tools/hal-system-power-suspend-hybrid
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+PRIVILEGE=hal-power-suspend
+if [ "$HAVE_POLKIT" = "1" ] ; then
+    if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ] ; then
+	RESULT=$(polkit-is-privileged --privilege $PRIVILEGE \
+	    --user $HAL_METHOD_INVOKED_BY_UID \
+	    --system-bus-unique-name $HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME 2>&1)
+	IS_PRIVILEGED=$?
+	if [ "$IS_PRIVILEGED" != "0" ] ; then
+	    echo org.freedesktop.Hal.Device.PermissionDeniedByPolicy >&2
+	    echo $PRIVILEGE refused uid $HAL_METHOD_INVOKED_BY_UID >&2
+	    exit 1
+	fi
+    fi
+fi
+
+alarm_not_supported() {
+	echo org.freedesktop.Hal.Device.SystemPowerManagement.AlarmNotSupported >&2
+	echo Waking the system up is not supported >&2
+	exit 1
+}
+
+unsupported() {
+	echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
+	echo No suspend-hybrid method found >&2
+	exit 1
+}
+
+read seconds_to_sleep
+
+# Make a suitable command line argument so that the tools can do the correct
+# quirks for video resume.
+# Passing the quirks to the tool allows the tool to not depend on HAL for data.
+QUIRKS=""
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_S3_BIOS" = "true" ] && QUIRKS="$QUIRKS --quirk-s3-bios"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_S3_MODE" = "true" ] && QUIRKS="$QUIRKS --quirk-s3-mode"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_DPMS_SUSPEND" = "true" ] && QUIRKS="$QUIRKS --quirk-dpms-suspend"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_DPMS_ON" = "true" ] && QUIRKS="$QUIRKS --quirk-dpms-on"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_VBESTATE_RESTORE" = "true" ] && QUIRKS="$QUIRKS --quirk-vbestate"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_VBEMODE_RESTORE" = "true" ] && QUIRKS="$QUIRKS --quirk-vbemode"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_VGA_MODE_3" = "true" ] && QUIRKS="$QUIRKS --quirk-vga-mode3"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_VBE_POST" = "true" ] && QUIRKS="$QUIRKS --quirk-vbepost"
+[ "$HAL_PROP_POWER_MANAGEMENT_QUIRK_RADEON_OFF" = "true" ] && QUIRKS="$QUIRKS --quirk-radeon-off"
+
+if [ -x "/usr/sbin/pm-suspend-hybrid" ] ; then
+    if [ $seconds_to_sleep != "0" ] ; then
+	alarm_not_supported
+    fi
+    /usr/sbin/pm-suspend-hybrid $QUIRKS
+    RET=$?
+else
+    unsupported
+fi
+
+exit $RET


More information about the hal-commit mailing list