hal: Branch 'master' - 4 commits
David Zeuthen
david at kemper.freedesktop.org
Mon Mar 19 17:07:21 PDT 2007
hald/hald_dbus.c | 15 ++++++------
hald/linux/device.c | 50 +++++++++++++++++++++---------------------
hald/util.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
hald/util.h | 2 +
4 files changed, 96 insertions(+), 32 deletions(-)
New commits:
diff-tree ca868fc31b6bad489b34cf6c66f023db94909f4d (from f038b39e6eddb393c6793b3932eb978346fa528b)
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Mar 19 20:07:13 2007 -0400
fix up memory handling of exp_detail and remove dead code
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index b5f0a03..17b7f14 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -3286,7 +3286,7 @@ hald_exec_method_cb (HalDevice *d, guint
error[0] != NULL && error[1] != NULL) {
exp_name = error[0];
if (error[0] != NULL) {
- exp_detail = error[1];
+ exp_detail = g_strdup (error[1]);
}
HAL_INFO (("failed with '%s' '%s'", exp_name, exp_detail));
}
@@ -3300,16 +3300,12 @@ hald_exec_method_cb (HalDevice *d, guint
dbus_message_unref (reply);
} else if (exp_name != NULL && exp_detail != NULL) {
if (!is_valid_interface_name (exp_name)) {
- exp_detail = g_strconcat (exp_name, " \n ", exp_detail, NULL);
+ exp_detail = g_strconcat (exp_name, " \n ", exp_detail, NULL);
exp_name = "org.freedesktop.Hal.Device.UnknownError";
}
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");
- if (reply == NULL) {
- DIE (("No memory"));
- }
+ if (reply == NULL) {
+ DIE (("No memory"));
}
if (conn != NULL) {
if (!dbus_connection_send (conn, reply, NULL))
diff-tree f038b39e6eddb393c6793b3932eb978346fa528b (from c84928ec1c799e58dfe6c39bd9c3f2400249077c)
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Mon Mar 19 19:48:21 2007 -0400
validate error D-Bus names returned on stderror
Attached a patch to validate the error name and workaround the problem in HAL.
Because there is no funtion in the D-Bus libraries to check if a interface or
error name is valid, I adapted the D-Bus internal funtion for util.h. If the
check fail and the error name is not valid the patch set the error name to:
org.freedesktop.Hal.Device.UnknownError
The invalid error name get prepend to the error message to avoid lost information.
Maybe we should change the error name to:
org.freedesktop.Hal.Device.MalformedError
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 07612c5..b5f0a03 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -3299,6 +3299,10 @@ hald_exec_method_cb (HalDevice *d, guint
}
dbus_message_unref (reply);
} else if (exp_name != NULL && exp_detail != NULL) {
+ if (!is_valid_interface_name (exp_name)) {
+ exp_detail = g_strconcat (exp_name, " \n ", exp_detail, NULL);
+ exp_name = "org.freedesktop.Hal.Device.UnknownError";
+ }
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 */
@@ -3331,6 +3335,7 @@ hald_exec_method_cb (HalDevice *d, guint
dbus_message_unref (reply);
}
+ g_free(exp_detail);
dbus_message_unref (message);
}
diff --git a/hald/util.c b/hald/util.c
index 0356943..3179277 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -54,6 +54,26 @@
#include "util.h"
+/**
+ * Determine wether the given character is valid as the first character
+ * in a name.
+ */
+#define VALID_INITIAL_NAME_CHARACTER(c) \
+ ( ((c) >= 'A' && (c) <= 'Z') || \
+ ((c) >= 'a' && (c) <= 'z') || \
+ ((c) == '_') )
+
+/**
+ * Determine wether the given character is valid as a second or later
+ * character in a name
+ */
+#define VALID_NAME_CHARACTER(c) \
+ ( ((c) >= '0' && (c) <= '9') || \
+ ((c) >= 'A' && (c) <= 'Z') || \
+ ((c) >= 'a' && (c) <= 'z') || \
+ ((c) == '_') )
+
+
gboolean
hal_util_remove_trailing_slash (gchar *path)
{
@@ -1203,3 +1223,44 @@ hal_util_readlink (const char *link)
return path_buffer;
}
+
+gboolean
+is_valid_interface_name (const char *name) {
+
+ const char *end;
+ const char *last_dot;
+
+ last_dot = NULL;
+
+ if (strlen(name) == 0)
+ return FALSE;
+
+ end = name + strlen(name);
+
+ if (*name == '.') /* disallow starting with a . */
+ return FALSE;
+ else if (!VALID_INITIAL_NAME_CHARACTER (*name))
+ return FALSE;
+ else
+ ++name;
+
+ while (name != end) {
+ if (*name == '.') {
+ if ((name + 1) == end)
+ return FALSE;
+ else if (!VALID_INITIAL_NAME_CHARACTER (*(name + 1)))
+ return FALSE;
+ last_dot = name;
+ ++name; /* we just validated the next char, so skip two */
+ }
+ else if (!VALID_NAME_CHARACTER (*name)) {
+ return FALSE;
+ }
+ ++name;
+ }
+ if (last_dot == NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
diff --git a/hald/util.h b/hald/util.h
index 5265b6d..27ad0d5 100644
--- a/hald/util.h
+++ b/hald/util.h
@@ -112,4 +112,6 @@ gboolean hal_util_is_mounted_by_hald (co
char *hal_util_readlink (const char *link);
+gboolean is_valid_interface_name (const char *name);
+
#endif /* UTIL_H */
diff-tree c84928ec1c799e58dfe6c39bd9c3f2400249077c (from parents)
Merge: 769c604d617e6daa3e7e9ee4f76376c1a6559970 7f278b8a9d38a5c0851f20f12a4709684571d3d1
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Mar 19 19:43:31 2007 -0400
Merge branch 'master' of ssh://david@git.freedesktop.org/git/hal
diff-tree 769c604d617e6daa3e7e9ee4f76376c1a6559970 (from c9cde9a767168fe9151695142baaae06d5e0827b)
Author: David Zeuthen <davidz at redhat.com>
Date: Mon Mar 19 19:43:23 2007 -0400
avoid setting pci.vendor, pci.product, usb.vendor to useless "Unknown (XXX)"
diff --git a/hald/linux/device.c b/hald/linux/device.c
index 74e440b..f90248b 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -1361,7 +1361,6 @@ pci_add (const gchar *sysfs_path, const
} else {
g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)",
hal_device_property_get_int (d, "pci.vendor_id"));
- hal_device_property_set_string (d, "pci.vendor", buf);
hal_device_property_set_string (d, "info.vendor", buf);
}
@@ -1371,24 +1370,14 @@ pci_add (const gchar *sysfs_path, const
} else {
g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)",
hal_device_property_get_int (d, "pci.product_id"));
- hal_device_property_set_string (d, "pci.product", buf);
hal_device_property_set_string (d, "info.product", buf);
}
if (subsys_vendor_name != NULL) {
hal_device_property_set_string (d, "pci.subsys_vendor", subsys_vendor_name);
- } else {
- g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)",
- hal_device_property_get_int (d, "pci.subsys_vendor_id"));
- hal_device_property_set_string (d, "pci.subsys_vendor", buf);
- }
-
+ }
if (subsys_product_name != NULL) {
hal_device_property_set_string (d, "pci.subsys_product", subsys_product_name);
- } else {
- g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)",
- hal_device_property_get_int (d, "pci.subsys_product_id"));
- hal_device_property_set_string (d, "pci.subsys_product", buf);
}
}
@@ -1522,29 +1511,35 @@ usb_add (const gchar *sysfs_path, const
if (vendor_name != NULL) {
hal_device_property_set_string (d, "usb_device.vendor", vendor_name);
+ hal_device_property_set_string (d, "info.vendor", vendor_name);
} else {
if (!hal_util_set_string_from_file (d, "usb_device.vendor",
sysfs_path, "manufacturer")) {
g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)",
hal_device_property_get_int (d, "usb_device.vendor_id"));
- hal_device_property_set_string (d, "usb_device.vendor", buf);
- }
+ hal_device_property_set_string (d, "info.vendor", buf);
+ } else {
+ hal_device_property_set_string (
+ d, "info.vendor",
+ hal_device_property_get_string (d, "usb_device.vendor"));
+ }
}
- hal_device_property_set_string (d, "info.vendor",
- hal_device_property_get_string (d, "usb_device.vendor"));
if (product_name != NULL) {
hal_device_property_set_string (d, "usb_device.product", product_name);
+ hal_device_property_set_string (d, "info.product", product_name);
} else {
if (!hal_util_set_string_from_file (d, "usb_device.product",
sysfs_path, "product")) {
g_snprintf (buf, sizeof (buf), "Unknown (0x%04x)",
hal_device_property_get_int (d, "usb_device.product_id"));
- hal_device_property_set_string (d, "usb_device.product", buf);
- }
+ hal_device_property_set_string (d, "info.product", buf);
+ } else {
+ hal_device_property_set_string (
+ d, "info.product",
+ hal_device_property_get_string (d, "usb_device.product"));
+ }
}
- hal_device_property_set_string (d, "info.product",
- hal_device_property_get_string (d, "usb_device.product"));
}
hal_util_set_int_from_file (d, "usb_device.device_revision_bcd", sysfs_path, "bcdDevice", 16);
@@ -1865,6 +1860,7 @@ pcmcia_add (const gchar *sysfs_path, con
/* Provide best-guess of vendor, goes in Vendor property */
if (prod_id1 != NULL) {
+ hal_device_property_set_string (d, "pcmcia.vendor", prod_id1);
hal_device_property_set_string (d, "info.vendor", prod_id1);
} else {
char buf[50];
@@ -1874,6 +1870,7 @@ pcmcia_add (const gchar *sysfs_path, con
/* Provide best-guess of name, goes in Product property */
if (prod_id2 != NULL) {
+ hal_device_property_set_string (d, "pcmcia.product", prod_id1);
hal_device_property_set_string (d, "info.product", prod_id2);
} else {
char buf[50];
@@ -2031,20 +2028,23 @@ mmc_add (const gchar *sysfs_path, const
}
if (!hal_util_set_string_from_file (d, "info.product", sysfs_path, "name")) {
- if (scr != NULL)
+ if (scr != NULL) {
hal_device_property_set_string (d, "info.product", "SD Card");
- else
- hal_device_property_set_string (d, "info.product", "MMC Card");
+ hal_device_property_set_string (d, "mmc.product", "SD Card");
+ } else {
+ hal_device_property_set_string (d, "mmc.product", "MMC Card");
+ }
}
if (hal_util_get_int_from_file (sysfs_path, "manfid", &manfid, 16)) {
- /* Here we should have a mapping to a name */
+ /* TODO: Here we should have a mapping to a name */
char vendor[256];
snprintf(vendor, 256, "Unknown (%d)", manfid);
hal_device_property_set_string (d, "info.vendor", vendor);
+ hal_device_property_set_string (d, "mmc.vendor", vendor);
}
if (hal_util_get_int_from_file (sysfs_path, "oemid", &oemid, 16)) {
- /* Here we should have a mapping to a name */
+ /* TODO: Here we should have a mapping to a name */
char oem[256];
snprintf(oem, 256, "Unknown (%d)", oemid);
hal_device_property_set_string (d, "mmc.oem", oem);
More information about the hal-commit
mailing list