hal: Branch 'master'

Danny Kukawka dkukawka at kemper.freedesktop.org
Wed Oct 1 12:23:12 PDT 2008


 hald/linux/addons/Makefile.am      |    4 +--
 hald/linux/coldplug.c              |    1 
 hald/linux/osspec.c                |    1 
 hald/linux/probing/Makefile.am     |    4 +--
 hald/linux/probing/probe-storage.c |   47 +++++++++++++++++++++++++++++++++++++
 hald/util.c                        |   25 -------------------
 hald/util.h                        |    2 -
 hald/util_helper.c                 |   28 ++++++++++++++++++++++
 hald/util_helper.h                 |    3 ++
 hald/util_helper_priv.h            |    3 --
 10 files changed, 84 insertions(+), 34 deletions(-)

New commits:
commit a7023c197856fc30ef3c25d687c283081e342d87
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Wed Oct 1 21:22:07 2008 +0200

    get storage.model for SCSI via HDIO_GET_IDENTITY instead of sysfs
    
    Get storage.model for SCSI devices via the storage prober from
    the device (via HDIO_GET_IDENTITY ioctl) intead of reading it from
    sysfs.
    
    This should prevent truncated model strings (after 16 chars) if the
    device is a IDE device managed via the SCSI layer.
    
    Moved hal_util_strdup_valid_utf8() from util.[c,h] to util_helper.[c,h]
    to be able to reuse the function in probe-storage.c. Cleaned up
    util_helper_priv.h, removed not implemented functions from the file.

diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index 2e03111..46b41cf 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -76,7 +76,7 @@ endif
 endif
 
 hald_addon_acpi_SOURCES = addon-acpi.c ../../logger.c ../../util_helper.c
-hald_addon_acpi_LDADD = $(top_builddir)/libhal/libhal.la
+hald_addon_acpi_LDADD = @GLIB_LIBS@ $(top_builddir)/libhal/libhal.la
 
 if BUILD_ACPI_TOSHIBA
 hald_addon_acpi_buttons_toshiba_SOURCES = addon-acpi-buttons-toshiba.c ../../logger.c ../../util_helper.c
@@ -90,7 +90,7 @@ hald_addon_input_SOURCES = addon-input.c ../../logger.c ../../util_helper.c
 hald_addon_input_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 
 hald_addon_pmu_SOURCES = addon-pmu.c ../../logger.c ../../util_helper.c
-hald_addon_pmu_LDADD = $(top_builddir)/libhal/libhal.la
+hald_addon_pmu_LDADD = @GLIB_LIBS@ $(top_builddir)/libhal/libhal.la
 
 hald_addon_storage_SOURCES = addon-storage.c ../../logger.c ../../util_helper.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 0ba7182..d22fdd1 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -39,6 +39,7 @@
 #include "../logger.h"
 #include "../osspec.h"
 #include "../util.h"
+#include "../util_helper.h"
 #include "osspec_linux.h"
 #include "hotplug.h"
 #include "coldplug.h"
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index e91a8aa..6d6472b 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -55,6 +55,7 @@
 #include "../logger.h"
 #include "../osspec.h"
 #include "../util.h"
+#include "../util_helper.h"
 #include "../ids.h"
 
 #include "acpi.h"
diff --git a/hald/linux/probing/Makefile.am b/hald/linux/probing/Makefile.am
index 274b870..10bba43 100644
--- a/hald/linux/probing/Makefile.am
+++ b/hald/linux/probing/Makefile.am
@@ -39,8 +39,8 @@ hald_probe_hiddev_LDADD = $(top_builddir)/libhal/libhal.la
 hald_probe_serial_SOURCES = probe-serial.c ../../logger.c
 hald_probe_serial_LDADD = $(top_builddir)/libhal/libhal.la
 
-hald_probe_storage_SOURCES = probe-storage.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h ../../logger.c
-hald_probe_storage_LDADD = $(top_builddir)/libhal/libhal.la $(top_builddir)/partutil/libpartutil.la @GLIB_LIBS@ @VOLUME_ID_LIBS@
+hald_probe_storage_SOURCES = probe-storage.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h ../../util_helper.c ../../logger.c  
+hald_probe_storage_LDADD = @GLIB_LIBS@ @VOLUME_ID_LIBS@ $(top_builddir)/libhal/libhal.la $(top_builddir)/partutil/libpartutil.la 
 
 hald_probe_pc_floppy_SOURCES = probe-pc-floppy.c ../../logger.c
 
diff --git a/hald/linux/probing/probe-storage.c b/hald/linux/probing/probe-storage.c
index f13d015..a8b8d79 100644
--- a/hald/linux/probing/probe-storage.c
+++ b/hald/linux/probing/probe-storage.c
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/kdev_t.h>
+#include <linux/hdreg.h>
 #include <linux/cdrom.h>
 #include <linux/fs.h>
 #include <mntent.h>
@@ -50,6 +51,8 @@
 #include "linux_dvd_rw_utils.h"
 
 #include "../../logger.h"
+#include "../../util_helper.h"
+
 
 static void vid_log(int priority, const char *file, int line, const char *format, ...)
 {
@@ -154,6 +157,49 @@ main (int argc, char *argv[])
 	HAL_DEBUG (("Doing probe-storage for %s (bus %s) (drive_type %s) (udi=%s) (--only-check-for-fs==%d)", 
 	     device_file, bus, drive_type, udi, only_check_for_fs));
 
+	/* get model from SCSI/IDE layer and not via sysfs to prevent truncated strings (see bnc#394390) */
+	if (strcmp (bus, "scsi") == 0){
+		struct hd_driveid id;
+		gchar *model = NULL;
+
+		fd = open(device_file, O_RDONLY|O_NONBLOCK);
+		if (fd < 0) {
+			HAL_WARNING(("unable to open '%s', error: '%s'", device_file, strerror (errno)));
+		} else {
+			if (ioctl(fd, HDIO_GET_IDENTITY, &id)) {
+				HAL_WARNING (("HDIO_GET_IDENTITY unsupported or failed for: '%s' with error: '%s'", device_file, strerror (errno)));
+			} else {
+				char str[41];
+				size_t i, len;
+
+				i = 0;			
+				len = 40; 
+				
+				while (len && isspace(id.model[len-1]))
+			                len--;
+				
+				while (i < len) {
+					str[i] = id.model[i];
+					i++;
+				}
+				str[i] = '\0';
+
+				g_strstrip(str);
+	
+				if ((model = hal_util_strdup_valid_utf8(str)) != NULL) {
+					model = g_strdelimit(model, "/", '_');
+				}
+			}
+			close(fd);
+		}
+		
+		if (model != NULL) {
+			libhal_changeset_set_property_string (cs, "storage.model", model);
+			libhal_changeset_set_property_string (cs, "info.product", model);
+			g_free (model);
+		}
+	}
+
 	/* Get properties for CD-ROM drive */
 	if (strcmp (drive_type, "cdrom") == 0) {
 		int capabilities;
@@ -489,6 +535,7 @@ main (int argc, char *argv[])
 		}
 		close (fd);
 	}
+
 	
 out:
 	if (cs != NULL) {
diff --git a/hald/util.c b/hald/util.c
index 51f5d8a..901e64f 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -1022,31 +1022,6 @@ out:
 	;
 }
 
-gchar *
-hal_util_strdup_valid_utf8 (const char *str)
-{
-	char *endchar;
-	char *newstr;
-	unsigned int count = 0;
-
-	if (str == NULL)
-		return NULL;
-
-	newstr = g_strdup (str);
-
-	while (!g_utf8_validate (newstr, -1, (const char **) &endchar)) {
-		*endchar = '?';
-		count++;
-	}
-	
-	if (strlen(newstr) == count) {
-		g_free (newstr);
-		return NULL;
-	} else {
-		return newstr;
-	}
-}
-
 void
 hal_util_hexdump (const void *mem, unsigned int size)
 {
diff --git a/hald/util.h b/hald/util.h
index e1783e2..510c36c 100644
--- a/hald/util.h
+++ b/hald/util.h
@@ -107,8 +107,6 @@ void hal_util_callout_device_add (HalDevice *d, HalCalloutsDone callback, gpoint
 void hal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
 void hal_util_callout_device_preprobe (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2);
 
-gchar *hal_util_strdup_valid_utf8 (const char *str);
-
 void hal_util_hexdump (const void *buf, unsigned int size);
 
 gboolean hal_util_is_mounted_by_hald (const char *mount_point);
diff --git a/hald/util_helper.c b/hald/util_helper.c
index ee97026..80416b0 100644
--- a/hald/util_helper.c
+++ b/hald/util_helper.c
@@ -35,6 +35,8 @@
 #include <pwd.h>
 #include <unistd.h>
 
+#include <glib.h>
+
 #include "logger.h"
 
 #include "util_helper.h"
@@ -186,3 +188,29 @@ out:
 #endif
 }
 
+gchar *
+hal_util_strdup_valid_utf8 (const char *str)
+{
+        char *endchar;
+        char *newstr;
+        unsigned int count = 0;
+
+        if (str == NULL)
+                return NULL;
+
+        newstr = g_strdup (str);
+
+        while (!g_utf8_validate (newstr, -1, (const char **) &endchar)) {
+                *endchar = '?';
+                count++;
+        }
+
+        if (strlen(newstr) == count) {
+                g_free (newstr);
+                return NULL;
+        } else {
+                return newstr;
+        }
+}
+
+
diff --git a/hald/util_helper.h b/hald/util_helper.h
index b9309f4..99fa584 100644
--- a/hald/util_helper.h
+++ b/hald/util_helper.h
@@ -26,8 +26,11 @@
 #ifndef UTIL_HELPER_H
 #define UTIL_HELPER_H
 
+#include <glib.h>
+
 void drop_privileges (int keep_auxgroups);
 void hal_set_proc_title_init (int argc, char *argv[]);
 void hal_set_proc_title (const char *format, ...);
+gchar *hal_util_strdup_valid_utf8 (const char *str);
 
 #endif /* UTIL_HELPER_H */
diff --git a/hald/util_helper_priv.h b/hald/util_helper_priv.h
index e32bb14..f5e3f9b 100644
--- a/hald/util_helper_priv.h
+++ b/hald/util_helper_priv.h
@@ -28,9 +28,6 @@
 #include <glib.h>
 #include "../libhal/libhal.h"
 
-void drop_privileges (int keep_auxgroups);
-void hal_set_proc_title_init (int argc, char *argv[]);
-void hal_set_proc_title (const char *format, ...);
 gboolean check_priv ( LibHalContext *halctx, DBusConnection *connection, DBusMessage *message, const char *udi, const char *action);
 
 #endif /* UTIL_HELPER_PRIV_H */


More information about the hal-commit mailing list