hal/hald/linux2 Makefile.am, 1.3, 1.4 acpi.c, 1.2, 1.3 acpi.h, 1.2, 1.3 coldplug.c, 1.5, 1.6 hotplug.c, 1.5, 1.6 hotplug.h, 1.2, 1.3 osspec.c, 1.5, 1.6 util.c, 1.4, 1.5

David Zeuthen david at freedesktop.org
Wed Feb 2 16:21:53 PST 2005


Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv15452/hald/linux2

Modified Files:
	Makefile.am acpi.c acpi.h coldplug.c hotplug.c hotplug.h 
	osspec.c util.c 
Log Message:
2005-02-02  David Zeuthen  <davidz at redhat.com>

	* hald/linux2/apm.[ch]: New files

	* hald/linux2/util.c (helper_invoke): Remember to initialize the
	error object to NULL

	* hald/linux2/osspec.c (osspec_probe): Only try APM if ACPI fails

	* hald/linux2/hotplug.c (hotplug_event_begin_apm): New function
	(hotplug_event_begin): Handle APM
	(hotplug_rescan_device): Handle APM
	(hotplug_reprobe_generate_remove_events): Handle APM
	(hotplug_reprobe_generate_add_events): Handle APM

	* hald/linux2/acpi.c (acpi_synthesize): Remember to set error to
	NULL and don't leak the error object
	(acpi_generate_remove_hotplug_event): Make this function return
	a boolean to say whether ACPI capabilities were detected

	* doc/spec/hal-spec.xml.in: Update the spec a bit more on battery.*



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile.am	1 Feb 2005 05:17:55 -0000	1.3
+++ Makefile.am	3 Feb 2005 00:21:50 -0000	1.4
@@ -21,6 +21,7 @@
 	blockdev.h		blockdev.c			\
 	util.h			util.c				\
 	acpi.h			acpi.c				\
+	apm.h			apm.c				\
 	ids.h			ids.c				\
 	pcmcia_utils.h		pcmcia_utils.c
 

Index: acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- acpi.c	2 Feb 2005 20:44:25 -0000	1.2
+++ acpi.c	3 Feb 2005 00:21:51 -0000	1.3
@@ -165,11 +165,12 @@
 {
 	const gchar *f;
 	GDir *dir;
-	GError *error;
+	GError *error = NULL;
 
 	dir = g_dir_open (path, 0, &error);
 	if (dir == NULL) {
-		HAL_ERROR (("Couldn't open %s", path));
+		HAL_ERROR (("Couldn't open %s: %s", path, error->message));
+		g_error_free (error);
 		goto out;
 	}
 
@@ -198,16 +199,24 @@
 
 /** Scan the data structures exported by the kernel and add hotplug
  *  events for adding ACPI objects.
+ *
+ *  @param                      TRUE if, and only if, ACPI capabilities
+ *                              were detected
  */
-void
+gboolean
 acpi_synthesize_hotplug_events (void)
 {
+	gboolean ret;
 	HalDevice *computer;
 	gchar path[HAL_PATH_MAX];
 
+	ret = FALSE;
+
 	if (!g_file_test ("/proc/acpi/info", G_FILE_TEST_EXISTS))
 		goto out;
 
+	ret = TRUE;
+
 	if ((computer = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer")) == NULL) {
 		HAL_ERROR (("No computer object?"));
 		goto out;
@@ -236,7 +245,7 @@
 	acpi_synthesize (path, ACPI_TYPE_BUTTON);
 
 out:
-	;
+	return ret;
 }
 
 static HalDevice *

Index: acpi.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- acpi.h	2 Feb 2005 20:44:25 -0000	1.2
+++ acpi.h	3 Feb 2005 00:21:51 -0000	1.3
@@ -26,7 +26,7 @@
 #include "../hald.h"
 #include "hotplug.h"
 
-void acpi_synthesize_hotplug_events (void);
+gboolean acpi_synthesize_hotplug_events (void);
 
 void hotplug_event_begin_add_acpi (const gchar *acpi_path, int acpi_type, HalDevice *parent, void *end_token);
 

Index: coldplug.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/coldplug.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- coldplug.c	2 Feb 2005 20:44:25 -0000	1.5
+++ coldplug.c	3 Feb 2005 00:21:51 -0000	1.6
@@ -365,7 +365,7 @@
 			       GHashTable *sysfs_to_class_in_devices_map)
 {
 	gchar *bus;
-	GError *err;
+	GError *err = NULL;
 	GDir *dir;
 	const gchar *f;
 	/*HStringPair *pair;*/

Index: hotplug.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/hotplug.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hotplug.c	2 Feb 2005 20:44:25 -0000	1.5
+++ hotplug.c	3 Feb 2005 00:21:51 -0000	1.6
@@ -55,7 +55,7 @@
 #include "classdev.h"
 #include "blockdev.h"
 #include "acpi.h"
-
+#include "apm.h"
 
 /** Queue of ordered hotplug events */
 GQueue *hotplug_event_queue;
@@ -272,6 +272,21 @@
 }
 
 static void
+hotplug_event_begin_apm (HotplugEvent *hotplug_event)
+{
+	if (hotplug_event->is_add) {
+		hotplug_event_begin_add_apm (hotplug_event->apm.apm_path, 
+					     hotplug_event->apm.apm_type,
+					     NULL,
+					     (void *) hotplug_event);
+	} else {
+		hotplug_event_begin_remove_apm (hotplug_event->apm.apm_path, 
+						hotplug_event->apm.apm_type,
+						(void *) hotplug_event);
+	}
+}
+
+static void
 hotplug_event_begin (HotplugEvent *hotplug_event)
 {
 	switch (hotplug_event->type) {
@@ -288,6 +303,10 @@
 		hotplug_event_begin_acpi (hotplug_event);
 		break;
 
+	case HOTPLUG_EVENT_APM:
+		hotplug_event_begin_apm (hotplug_event);
+		break;
+
 	default:
 		HAL_ERROR (("Unknown hotplug event type %d", hotplug_event->type));
 		hotplug_event_end ((void *) hotplug_event);
@@ -354,6 +373,10 @@
 		ret = acpi_rescan_device (d);
 		break;
 
+	case HOTPLUG_EVENT_APM:
+		ret = acpi_rescan_device (d);
+		break;
+
 	default:
 		HAL_INFO (("Unknown hotplug type for udi=%s", d->udi));
 		ret = FALSE;
@@ -398,6 +421,10 @@
 		e = acpi_generate_remove_hotplug_event (d);
 		break;
 
+	case HOTPLUG_EVENT_APM:
+		e = acpi_generate_remove_hotplug_event (d);
+		break;
+
 	default:
 		e = NULL;
 		HAL_INFO (("Unknown hotplug type for udi=%s", d->udi));
@@ -435,6 +462,10 @@
 		e = acpi_generate_add_hotplug_event (d);
 		break;
 
+	case HOTPLUG_EVENT_APM:
+		e = acpi_generate_add_hotplug_event (d);
+		break;
+
 	default:
 		e = NULL;
 		HAL_INFO (("Unknown hotplug type for udi=%s", d->udi));

Index: hotplug.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/hotplug.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hotplug.h	2 Feb 2005 20:44:25 -0000	1.2
+++ hotplug.h	3 Feb 2005 00:21:51 -0000	1.3
@@ -36,7 +36,8 @@
 	HOTPLUG_EVENT_SYSFS_BUS   = 1,
 	HOTPLUG_EVENT_SYSFS_CLASS = 2,
 	HOTPLUG_EVENT_SYSFS_BLOCK = 3,
-	HOTPLUG_EVENT_ACPI        = 4
+	HOTPLUG_EVENT_ACPI        = 4,
+	HOTPLUG_EVENT_APM         = 5
 } HotplugEventType;
 
 /** Data structure representing a hotplug event; also used for
@@ -66,6 +67,11 @@
 			int  acpi_type;                         /**< Type of ACPI object; see acpi.c */
 			char acpi_path[HAL_PATH_MAX];           /**< Path into procfs, e.g. /proc/acpi/battery/BAT0/ */
 		} acpi;
+
+		struct {
+			int  apm_type;                          /**< Type of ACPI object; see apm.c */
+			char apm_path[HAL_PATH_MAX];            /**< Path into procfs, e.g. /proc/apm */
+		} apm;
 	};
 
 } HotplugEvent;

Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/osspec.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- osspec.c	2 Feb 2005 20:44:25 -0000	1.5
+++ osspec.c	3 Feb 2005 00:21:51 -0000	1.6
@@ -80,6 +80,7 @@
 #include "ids.h"
 
 #include "acpi.h"
+#include "apm.h"
 
 char hal_sysfs_path [HAL_PATH_MAX];
 char hal_proc_path [HAL_PATH_MAX];
@@ -470,8 +471,11 @@
 	/* will enqueue hotplug events for entire system */
 	HAL_INFO (("Synthesizing sysfs events..."));
 	coldplug_synthesize_events ();
-	HAL_INFO (("Synthesizing acpi events..."));
-	acpi_synthesize_hotplug_events ();
+	HAL_INFO (("Synthesizing ACPI events..."));
+	if (!acpi_synthesize_hotplug_events ()) {
+		HAL_INFO (("No ACPI capabilities found; checking for APM"));
+		apm_synthesize_hotplug_events ();
+	}
 	HAL_INFO (("Done synthesizing events"));
 
 	/* start processing events */

Index: util.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/util.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- util.c	1 Feb 2005 05:50:40 -0000	1.4
+++ util.c	3 Feb 2005 00:21:51 -0000	1.5
@@ -638,7 +638,7 @@
 	gchar *argv[] = {(gchar *) path, NULL};
 	gchar **envp;
 	gchar **ienvp;
-	GError *err;
+	GError *err = NULL;
 	guint num_env_vars;
 	guint i;
 	guint num_properties;
@@ -671,7 +671,6 @@
 		envp[i++] = g_strdup ("HALD_SHUTDOWN=1");
 	envp[i++] = NULL;
 
-	
 	err = NULL;
 	if (!g_spawn_async (NULL, 
 			    argv, 




More information about the hal-commit mailing list