Little hal patches

Sjoerd Simons sjoerd at air.luon.net
Sun Feb 29 16:27:30 EET 2004


Hi,

  Attached are two little patches against hal cvs

  hal-scsi.patch:
    * Add support for scsi tape (not tested)
    * Set the storage.media property. 
      - This fixes media detection and capability detection on my scsi cdrom

  hal-udevinfo.patch:
    * Instead of using udev, udevinfo should be used.
    * Created a little function in linux_common to find the location of
      the udevinfo binary. Maybe a configure option would be better, but
      this was easier.
  
  On the hal website it wasn't mentioned where  to sent patches, is this
  list the preferred location ?

  Sjoerd
-- 
Don't abandon hope.  Your Captain Midnight decoder ring arrives tomorrow.
-------------- next part --------------
Index: hald/linux/linux_class_block.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/linux_class_block.c,v
retrieving revision 1.24
diff -u -r1.24 linux_class_block.c
--- hald/linux/linux_class_block.c	27 Feb 2004 19:47:31 -0000	1.24
+++ hald/linux/linux_class_block.c	29 Feb 2004 14:06:06 -0000
@@ -472,12 +472,23 @@
 				ds_add_capability (d, "storage");
 				ds_property_set_string (d, "info.category",
 							"storage");
+        ds_property_set_string(d, "storage.media", "disk");
+        break;
+      case 1: /* Tape */
+        ds_add_capability (d, "storage");
+        ds_add_capability(d, "storage.removable");
+        ds_property_set_string(d, "info.category", "storage.removable");
+        ds_property_set_string(d, "storage.media", "tape");
+				removable_media = TRUE;
+        break;
 			case 5: /* CD-ROM */
 				ds_add_capability (d, "storage");
 				ds_add_capability (d, "storage.removable");
+        ds_property_set_string(d, "storage.media", "cdrom");
 				ds_property_set_string (d, "info.category",
 							"storage.removable");
 				removable_media = TRUE;
+        break;
 			default:
 				/** @todo add more SCSI types */
 				HAL_WARNING (("Don't know how to handle "
-------------- next part --------------
Index: hald/linux/linux_class_block.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/linux_class_block.c,v
retrieving revision 1.24
diff -u -r1.24 linux_class_block.c
--- hald/linux/linux_class_block.c	27 Feb 2004 19:47:31 -0000	1.24
+++ hald/linux/linux_class_block.c	29 Feb 2004 14:06:06 -0000
@@ -254,7 +254,7 @@
         const char* path;
         int sysfs_mount_path_len;
         char sysfs_path_trunc[SYSFS_NAME_LEN];
-        char* udev_argv[7] = {"/sbin/udev", "-r", "-q", "name", "-p", 
+        char* udev_argv[7] = {udevinfo_path(), "-r", "-q", "name", "-p", 
                               sysfs_path_trunc, NULL};
         char* udev_stdout;
         char* udev_stderr;
@@ -271,8 +271,8 @@
         }
         HAL_INFO(("*** sysfs_path_trunc = '%s'", sysfs_path_trunc));
         
-        /* Now invoke udev */
-        if( g_spawn_sync("/",
+        /* Now invoke udevinfo */
+        if(udev_argv[0] == NULL || g_spawn_sync("/",
                          udev_argv,
                          NULL,
                          0,
@@ -283,13 +283,13 @@
                          &udev_exitcode,
 			 NULL)!=TRUE )
         {
-            HAL_ERROR(("Couldn't invoke /sbin/udev"));
+            HAL_ERROR(("Couldn't invoke udevinfo"));
             goto error;
         }
         
         if( udev_exitcode!=0 )
         {
-            HAL_ERROR(("/sbin/udev returned %d", udev_exitcode));
+            HAL_ERROR(("%s returned %d", udevinfo_path(), udev_exitcode));
             goto error;
         }
         
Index: hald/linux/linux_class_v4l.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/linux_class_v4l.c,v
retrieving revision 1.3
diff -u -r1.3 linux_class_v4l.c
--- hald/linux/linux_class_v4l.c	19 Jan 2004 21:03:40 -0000	1.3
+++ hald/linux/linux_class_v4l.c	29 Feb 2004 14:06:06 -0000
@@ -118,7 +118,7 @@
         int i;
         int sysfs_mount_path_len;
         char sysfs_path_trunc[SYSFS_NAME_LEN];
-        char* udev_argv[7] = {"/sbin/udev", "-r", "-q", "name", "-p",
+        char* udev_argv[7] = {udevinfo_path(), "-r", "-q", "name", "-p",
                               sysfs_path_trunc, NULL};
         char* udev_stdout;
         char* udev_stderr;
@@ -134,7 +134,7 @@
         HAL_INFO(("*** sysfs_path_trunc = '%s'", sysfs_path_trunc));
         
         /* Now invoke udev */
-        if( g_spawn_sync("/",
+        if( udev_argv[0] == NULL || g_spawn_sync("/",
                          udev_argv,
                          NULL,
                          0,
@@ -145,13 +145,13 @@
                          &udev_exitcode,
 			 NULL)!=TRUE )
         {
-            HAL_ERROR(("Couldn't invoke /sbin/udev"));
+            HAL_ERROR(("Couldn't invoke udevinfo"));
             goto error;
         }
         
         if( udev_exitcode!=0 )
         {
-            HAL_ERROR(("/sbin/udev returned %d", udev_exitcode));
+            HAL_ERROR(("udevinfo returned %d", udev_exitcode));
             goto error;
         }
         
Index: hald/linux/linux_common.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/linux_common.c,v
retrieving revision 1.8
diff -u -r1.8 linux_common.c
--- hald/linux/linux_common.c	19 Jan 2004 19:58:10 -0000	1.8
+++ hald/linux/linux_common.c	29 Feb 2004 14:06:06 -0000
@@ -39,6 +39,9 @@
 #include <stdarg.h>
 #include <limits.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include <libhal/libhal.h> /* For HAL_STATE_* */
 
 #include "../logger.h"
@@ -333,6 +336,22 @@
     return s;
 }
 
+/* returns the path of the udevinfo program */
+const char *udevinfo_path(void) {
+  char *possible_paths[] = { "/sbin/udevinfo",
+                          "/usr/sbin/udevinfo",
+                          "/usr/local/sbin/udevinfo" };
+  char *path = NULL;
+  unsigned int i;
+  struct stat s;
+  for (i = 0; i < sizeof(possible_paths)/sizeof(char *) ; i++) {
+    if (stat(possible_paths[i],&s) == 0 && S_ISREG(s.st_mode)) {
+      path = possible_paths[i];
+      break;
+    }
+  }
+  return path;
+}
 
 /** This function takes a temporary device and renames it to a proper
  *  UDI using the supplied bus-specific #naming_func. After renaming
Index: hald/linux/linux_common.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/linux_common.h,v
retrieving revision 1.3
diff -u -r1.3 linux_common.h
--- hald/linux/linux_common.h	2 Jan 2004 12:11:24 -0000	1.3
+++ hald/linux/linux_common.h	29 Feb 2004 14:06:07 -0000
@@ -51,6 +51,9 @@
 
 const char* get_last_element(const char* s);
 
+/* returns the path of the udevinfo program */
+const char *udevinfo_path(void);
+
 /** Type for function to compute the UDI (unique device id) for a given
  *  HAL device.
  *


More information about the xdg mailing list