Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > 26764e702e441b473525f6a16ac25557 > files > 47

hal-0.5.8.1-59.el5.src.rpm

diff --git a/tools/hal_get_property.c b/tools/hal_get_property.c
index ecaa6ce..d31261a 100644
--- a/tools/hal_get_property.c
+++ b/tools/hal_get_property.c
@@ -84,6 +84,7 @@ main (int argc, char *argv[])
 	dbus_bool_t is_hex = FALSE;
 	dbus_bool_t is_verbose = FALSE;
 	dbus_bool_t is_version = FALSE;
+	dbus_bool_t udi_exists;
 	char *str;
 	DBusError error;
 
@@ -168,6 +169,19 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	/* check UDI exists */
+	udi_exists = libhal_device_exists (hal_ctx, udi, &error);
+	if (!udi_exists) {
+		fprintf (stderr, "error: UDI %s does not exist\n", udi);
+		return 1;
+	}
+	if (dbus_error_is_set(&error)) {
+		fprintf (stderr, "error: libhal_device_exists: %s: %s\n", error.name, error.message);
+		LIBHAL_FREE_DBUS_ERROR (&error);
+		return 1;
+	}
+
+	/* get type */
 	type = libhal_device_get_property_type (hal_ctx, udi, key, &error);
 	if (type == LIBHAL_PROPERTY_TYPE_INVALID) {
 		fprintf (stderr, "error: libhal_device_get_property_type: %s: %s\n", error.name, error.message);
diff --git a/tools/hal-device.c b/tools/hal-device.c
index a37d2d6..04266bf 100644
--- a/tools/hal-device.c
+++ b/tools/hal-device.c
@@ -189,6 +189,7 @@ int dump_devices(LibHalContext *hal_ctx, char *arg)
 	char **device_names;
 	DBusError error;
 	char *udi = NULL;
+	dbus_bool_t udi_exists;
 
 	if (arg) {
 		if (*arg == '/') {
@@ -213,6 +214,19 @@ int dump_devices(LibHalContext *hal_ctx, char *arg)
 			return 31;
 		}
 	} else {
+
+		/* check UDI exists */
+		udi_exists = libhal_device_exists (hal_ctx, udi, &error);
+		if (!udi_exists) {
+			fprintf (stderr, "error: UDI %s does not exist\n", udi);
+			return 22;
+		}
+		if (dbus_error_is_set(&error)) {
+			fprintf (stderr, "error: libhal_device_exists: %s: %s\n", error.name, error.message);
+			LIBHAL_FREE_DBUS_ERROR (&error);
+			return 1;
+		}
+
 		device_names = calloc(2, sizeof *device_names);
 		device_names[0] = strdup(udi);
 		num_devices = 1;
diff --git a/tools/hal_set_property.c b/tools/hal_set_property.c
index eaeb7fc..2579c98 100644
--- a/tools/hal_set_property.c
+++ b/tools/hal_set_property.c
@@ -107,6 +107,7 @@ int
 main (int argc, char *argv[])
 {
 	dbus_bool_t rc = 0;
+	dbus_bool_t udi_exists;
 	char *udi = NULL;
 	char *key = NULL;
 	char *str_value = NULL;
@@ -235,6 +236,18 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	/* check UDI exists */
+	udi_exists = libhal_device_exists (hal_ctx, udi, &error);
+	if (!udi_exists) {
+		fprintf (stderr, "error: UDI %s does not exist\n", udi);
+		return 1;
+	}
+	if (dbus_error_is_set(&error)) {
+		fprintf (stderr, "error: libhal_device_exists: %s: %s\n", error.name, error.message);
+		LIBHAL_FREE_DBUS_ERROR (&error);
+		return 1;
+	}
+
 	if (remove) {
 		rc = libhal_device_remove_property (hal_ctx, udi, key, &error);
 		if (!rc) {