hal/hald device.c, 1.20, 1.21 device.h, 1.13, 1.14 device_info.c, 1.31, 1.32 hald_dbus.c, 1.50, 1.51 hald_runner.c, 1.1, 1.2 property.c, 1.15, 1.16 property.h, 1.9, 1.10

David Zeuthen david at freedesktop.org
Fri Jan 20 22:36:53 PST 2006


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

Modified Files:
	device.c device.h device_info.c hald_dbus.c hald_runner.c 
	property.c property.h 
Log Message:
2006-01-21  David Zeuthen  <davidz at redhat.com>

        * hald-runner/runner.c: Search $PATH before searching allowed dirs;
        this is needed to make e.g. run-hald.sh work - note that passing
        "/bin/sh /path/to/evil/program" will _not_ work as we don't do
        shell-ish stuff. Also, don't force working dir to be "/" for
        same reasons.

        * hald/property.h: Export hal_property_strlist_clear

        * hald/property.c (hal_property_strlist_clear): New function

        * hald/hald_runner.c (hald_runner_start_runner): Pass $PATH to runner

        * hald/hald_dbus.c (hald_exec_method_cb): Fix up indenting

        * hald/device_info.c (handle_clear): New function
        (start): Check for new fdi tag "clear"

        * hald/device.h: Export hal_device_property_strlist_clear

        * hald/device.c (hal_device_property_strlist_clear): New function



Index: device.c
===================================================================
RCS file: /cvs/hal/hal/hald/device.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- device.c	2 Nov 2005 15:38:13 -0000	1.20
+++ device.c	21 Jan 2006 06:36:51 -0000	1.21
@@ -1200,6 +1200,39 @@
 }
 
 gboolean
+hal_device_property_strlist_clear (HalDevice    *device,
+				   const char   *key)
+{
+	HalProperty *prop;
+
+	/* check if property already exists */
+	prop = hal_device_property_find (device, key);
+
+	if (prop == NULL) {
+		prop = hal_property_new_strlist (key);
+
+		device->properties = g_slist_prepend (device->properties, prop);
+
+		g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+			       key, FALSE, TRUE);
+
+		return TRUE;
+	}
+
+	if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
+		return FALSE;
+	
+	if (hal_property_strlist_clear (prop)) {
+		g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+			       key, FALSE, FALSE);
+		return TRUE;
+	}
+	
+	return FALSE;
+}
+
+
+gboolean
 hal_device_property_strlist_add (HalDevice *device,
 				 const char *key,
 				 const char *value)

Index: device.h
===================================================================
RCS file: /cvs/hal/hal/hald/device.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- device.h	2 Nov 2005 15:38:13 -0000	1.13
+++ device.h	21 Jan 2006 06:36:51 -0000	1.14
@@ -165,6 +165,8 @@
 gboolean      hal_device_property_strlist_remove_elem (HalDevice    *device,
 						       const char   *key,
 						       guint index);
+gboolean      hal_device_property_strlist_clear (HalDevice    *device,
+						 const char   *key);
 gboolean      hal_device_property_strlist_add (HalDevice    *device,
 					       const char   *key,
 					       const char *value);

Index: device_info.c
===================================================================
RCS file: /cvs/hal/hal/hald/device_info.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- device_info.c	20 Jan 2006 15:40:03 -0000	1.31
+++ device_info.c	21 Jan 2006 06:36:51 -0000	1.32
@@ -79,24 +79,28 @@
 	/** Processing an append element */
 	CURELEM_APPEND = 4,
 
-	/** Processing an prepend element */
+	/** Processing a prepend element */
 	CURELEM_PREPEND = 5,
 
-	/** Processing an prepend element */
-	CURELEM_REMOVE = 6
+	/** Processing a remove element */
+	CURELEM_REMOVE = 6,
+
+	/** Processing a clear element */
+	CURELEM_CLEAR = 7
 };
 
 /** What and how to merge */
 enum {
-	MERGE_TYPE_UNKNOWN,
-	MERGE_TYPE_STRING,
-	MERGE_TYPE_BOOLEAN,
-	MERGE_TYPE_INT32,
-	MERGE_TYPE_UINT64,
-	MERGE_TYPE_DOUBLE,
-	MERGE_TYPE_COPY_PROPERTY,
-	MERGE_TYPE_STRLIST,
-	MERGE_TYPE_REMOVE
+	MERGE_TYPE_UNKNOWN       = 0,
+	MERGE_TYPE_STRING        = 1,
+	MERGE_TYPE_BOOLEAN       = 2,
+	MERGE_TYPE_INT32         = 3,
+	MERGE_TYPE_UINT64        = 4,
+	MERGE_TYPE_DOUBLE        = 5,
+	MERGE_TYPE_COPY_PROPERTY = 6,
+	MERGE_TYPE_STRLIST       = 7,
+	MERGE_TYPE_REMOVE        = 8,
+	MERGE_TYPE_CLEAR         = 9
 };
 
 /** Parsing Context
@@ -744,7 +748,7 @@
 	return;
 }
 
-/** Called when the append or prepend element begins.
+/** Called when the remove element begins.
  *
  *  @param  pc                  Parsing context
  *  @param  attr                Attribute key/value pairs
@@ -786,6 +790,39 @@
 	return;
 }
 
+/** Called when the clear element begins.
+ *
+ *  @param  pc                  Parsing context
+ *  @param  attr                Attribute key/value pairs
+ */
+static void
+handle_clear (ParsingContext * pc, const char **attr)
+{
+	int num_attrib;
+
+	pc->merge_type = MERGE_TYPE_UNKNOWN;
+
+	for (num_attrib = 0; attr[num_attrib] != NULL; num_attrib++) {
+		;
+	}
+
+	if (num_attrib != 4)
+		return;
+	
+	if (strcmp (attr[0], "key") != 0)
+		return;
+
+
+	if (strcmp (attr[3], "strlist") != 0)
+		return;
+	
+	strncpy (pc->merge_key, attr[1], MAX_KEY_SIZE);
+	
+	pc->merge_type = MERGE_TYPE_CLEAR;
+
+	return;
+}
+
 /** Abort parsing of document
  *
  *  @param  pc                  Parsing context
@@ -914,6 +951,23 @@
 		} else {
 			/*HAL_INFO(("No merge!")); */
 		}
+	} else if (strcmp (el, "clear") == 0) {
+		if (pc->curelem != CURELEM_DEVICE
+		    && pc->curelem != CURELEM_MATCH) {
+			HAL_ERROR (("%s:%d:%d: Element <remove> can only be "
+				    "inside <device> and <match>", 
+				    pc->file, 
+				    XML_GetCurrentLineNumber (pc->parser), 
+				    XML_GetCurrentColumnNumber (pc->parser)));
+			parsing_abort (pc);
+		}
+
+		pc->curelem = CURELEM_CLEAR;
+		if (pc->match_ok) {
+			handle_clear (pc, attr);
+		} else {
+			/*HAL_INFO(("No merge!")); */
+		}
 	} else if (strcmp (el, "device") == 0) {
 		if (pc->curelem != CURELEM_DEVICE_INFO) {
 			HAL_ERROR (("%s:%d:%d: Element <device> can only be "
@@ -1147,6 +1201,10 @@
 				hal_device_property_remove (pc->device, pc->merge_key);
 			}
 		}
+	} else if (pc->curelem == CURELEM_CLEAR && pc->match_ok) {
+		if (pc->merge_type == MERGE_TYPE_CLEAR) {
+			hal_device_property_strlist_clear (pc->device, pc->merge_key);
+		}
 	}
 
 

Index: hald_dbus.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- hald_dbus.c	21 Jan 2006 03:14:18 -0000	1.50
+++ hald_dbus.c	21 Jan 2006 06:36:51 -0000	1.51
@@ -2486,27 +2486,28 @@
 	DBusMessage *reply = NULL;
 	DBusMessage *message;
 	DBusMessageIter iter;
-	message = (DBusMessage *) data1;
-  gchar *exp_name = NULL;
-  gchar *exp_detail = NULL;
+	gchar *exp_name = NULL;
+	gchar *exp_detail = NULL;
 
+	message = (DBusMessage *) data1;
+	
 	if (exit_type == HALD_RUN_SUCCESS && error != NULL) {
-    exp_name = error[0];
-    if (error[0] != NULL) {
-      exp_detail = error[1];
-    }
-    HAL_INFO (("failed with '%s' '%s'", exp_name, exp_detail));
-  }
-
-  if (exit_type != HALD_RUN_SUCCESS) {
+		exp_name = error[0];
+		if (error[0] != NULL) {
+			exp_detail = error[1];
+		}
+		HAL_INFO (("failed with '%s' '%s'", exp_name, exp_detail));
+	}
+	
+	if (exit_type != HALD_RUN_SUCCESS) {
 		reply = dbus_message_new_error (message, "org.freedesktop.Hal.Device.UnknownError", "An unknown error occured");
 		if (dbus_connection != NULL) {
 			if (!dbus_connection_send (dbus_connection, reply, NULL))
 				DIE (("No memory"));
 		}
 		dbus_message_unref (reply);
-  } else if (exp_name != NULL && exp_detail != NULL) {
-    reply = dbus_message_new_error (message, exp_name, exp_detail);
+	} else if (exp_name != NULL && exp_detail != NULL) {
+		reply = dbus_message_new_error (message, exp_name, exp_detail);
 		if (reply == NULL) {
 			/* error name may be invalid - assume caller fucked up and use a generic HAL error name */
 			reply = dbus_message_new_error (message, "org.freedesktop.Hal.Device.UnknownError", "An unknown error occured");

Index: hald_runner.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_runner.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hald_runner.c	21 Jan 2006 02:45:27 -0000	1.1
+++ hald_runner.c	21 Jan 2006 06:36:51 -0000	1.2
@@ -70,13 +70,14 @@
 }
 
 gboolean
-hald_runner_start_runner(gchar *runner_location) {
+hald_runner_start_runner(gchar *runner_location)
+{
   DBusServer *server = NULL;
   DBusError err;
   GError *error = NULL;
   GPid pid;
   char *argv[] = { NULL, NULL};
-  char *env[] =  { NULL, NULL};
+  char *env[] =  { NULL, NULL, NULL};
 
   dbus_error_init(&err);
   server = dbus_server_listen(DBUS_SERVER_ADDRESS, &err);
@@ -97,6 +98,7 @@
   argv[0] = runner_location;
   env[0] = g_strdup_printf("HALD_RUNNER_DBUS_ADDRESS=%s",
              dbus_server_get_address(server));
+  env[1] = g_strdup_printf("PATH=%s", getenv("PATH"));
 
   if (!g_spawn_async(NULL, argv, env, G_SPAWN_DO_NOT_REAP_CHILD, 
         NULL, NULL, &pid, &error)) {
@@ -106,6 +108,7 @@
   }
   g_free(argv[0]);
   g_free(env[0]);
+  g_free(env[1]);
 
   g_child_watch_add(pid, runner_died, NULL);
   while (runner_connection == NULL) {
@@ -294,8 +297,10 @@
   while (dbus_message_iter_next(&iter) &&
     dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
     const char *value;
+    const char *copy;
     dbus_message_iter_get_basic(&iter, &value);
-    g_array_append_vals(error, &value, 1);
+    copy = g_strdup (value);
+    g_array_append_vals(error, &copy, 1);
   }
 
   hb->cb(hb->d, exitt, return_code, 

Index: property.c
===================================================================
RCS file: /cvs/hal/hal/hald/property.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- property.c	2 Nov 2005 15:38:13 -0000	1.15
+++ property.c	21 Jan 2006 06:36:51 -0000	1.16
@@ -471,3 +471,19 @@
 
 	return FALSE;
 }
+
+gboolean 
+hal_property_strlist_clear (HalProperty *prop)
+{
+	GSList *elem;
+
+	g_return_val_if_fail (prop != NULL, FALSE);
+	g_return_val_if_fail (prop->type == HAL_PROPERTY_TYPE_STRLIST, FALSE);
+
+	for (elem = prop->strlist_value; elem != NULL; elem = g_slist_next (elem)) {
+		g_free (elem->data);
+	}
+	g_slist_free (prop->strlist_value);
+
+	return FALSE;
+}

Index: property.h
===================================================================
RCS file: /cvs/hal/hal/hald/property.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- property.h	2 Nov 2005 15:38:13 -0000	1.9
+++ property.h	21 Jan 2006 06:36:51 -0000	1.10
@@ -91,6 +91,7 @@
 					       const char *value);
 gboolean      hal_property_strlist_remove     (HalProperty  *prop,
 					       const char *value);
+gboolean      hal_property_strlist_clear      (HalProperty  *prop);
 
 
 void          hal_property_set_attribute      (HalProperty *prop,




More information about the hal-commit mailing list