chiark / gitweb /
[PATCH] scsi_id changes for use with udev %N and %p
authorpatmans@us.ibm.com <patmans@us.ibm.com>
Sat, 12 Feb 2005 02:30:01 +0000 (18:30 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:35:15 +0000 (23:35 -0700)
Changes to scsi_id to support the udev %N and %p substitutions:

- Update version from .7 to .8

- change TMP_DIR back to /tmp

- if DEVPATH is set assume hotplug_mode (use syslog for logging, and does
  not output some warnings)

- Always output a newline after the id is printed

- Allow command line options to override settings when hotplug_mode is set

- update man page

- update generator script to use the %N and %p substitutions.

extras/scsi_id/Makefile
extras/scsi_id/gen_scsi_id_udev_rules.sh
extras/scsi_id/scsi_id.8
extras/scsi_id/scsi_id.c

index 610faac4b70227c2b5958ab6fe3bc8701f21fd1e..e832102e302a8dbf0d56b587a3b358bd31f6c55d 100644 (file)
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
-SCSI_ID_VERSION=0.7
+SCSI_ID_VERSION=0.8
 
 prefix =
 etcdir =        ${prefix}/etc
 
 prefix =
 etcdir =        ${prefix}/etc
index 874e94e8bba939331c776d6eee57a88f7b279522..92fde5df1bb2fc9dd6ff89939dcd2938c247e7c1 100644 (file)
@@ -60,7 +60,7 @@ do
        if [ $first_line = "yes" ]
        then
                first_line=no
        if [ $first_line = "yes" ]
        then
                first_line=no
-               echo "BUS=\"scsi\", PROGRAM=\"${scsi_id}\", RESULT=\"${id}\", NAME=\"${prefix}${name}%n\""
+               echo "BUS=\"scsi\", PROGRAM=\"${scsi_id} -d %N -s %p\", RESULT=\"${id}\", NAME=\"${prefix}${name}%n\""
                echo
                echo "# Further RESULT keys use the result of the last PROGRAM rule."
                echo "# Be careful not to add any rules containing PROGRAM key between here"
                echo
                echo "# Further RESULT keys use the result of the last PROGRAM rule."
                echo "# Be careful not to add any rules containing PROGRAM key between here"
index 591bb79366a03bad8769fcdf45b84800cf66175a..68d4a1c041a65a6867e9dd54c28e2ff86e89846f 100644 (file)
@@ -53,9 +53,10 @@ identifier starts with the NAA value of 6):
 .SH OPTIONS
 .TP
 .BI subsystem
 .SH OPTIONS
 .TP
 .BI subsystem
-When called with only a single argument without a leading \-, runs in a hotplug
-mode, and expects the environment variable DEVPATH to specify the
-corresponding sysfs device. See section below on usage with \fBudev\fP.
+Deprecated method: when called with only a single argument without a
+leading \-, runs in a hotplug mode, and expects the environment variable
+DEVPATH to specify the corresponding sysfs device. See section below on
+usage with \fBudev\fP.
 .TP
 .BI \-b
 The default behaviour \- treat the device as black listed, and do nothing
 .TP
 .BI \-b
 The default behaviour \- treat the device as black listed, and do nothing
@@ -66,6 +67,8 @@ Instead
 of determining and creating a device node based on a sysfs dev
 entry as done for the \fB\-s\fP, send SG_IO commands to 
 \fBdevice\fP, such as \fB/dev/sdc\fP.
 of determining and creating a device node based on a sysfs dev
 entry as done for the \fB\-s\fP, send SG_IO commands to 
 \fBdevice\fP, such as \fB/dev/sdc\fP.
+This argument should also be used when invoked via udev to avoid problems
+with creation of temporary files on not-yet writable directories.
 .TP
 .BI \-f "\| config\-file"
 Read configuration and black/white list entries from
 .TP
 .BI \-f "\| config\-file"
 Read configuration and black/white list entries from
@@ -106,15 +109,15 @@ Display version number and exit.
 .RE
 
 .SH USAGE WITH UDEV 
 .RE
 
 .SH USAGE WITH UDEV 
+
 If \fBscsi_id\fP is invoked with one argument without a leading \-, it
 assumes it is called for a hotplug event, and looks for the sysfs device
 If \fBscsi_id\fP is invoked with one argument without a leading \-, it
 assumes it is called for a hotplug event, and looks for the sysfs device
-in the DEVPATH environment variable. 
-
-This mode is used when run via the \fBudev\fP PROGRAM key. Passing any
-arguments or options as part of the PROGRAM rule breaks this assumption,
-and the results will likely not be as expected.
+in the DEVPATH environment variable. This mode is deprecated, but
+available for backwards compatibility.
 
 
-When in this mode, all errors and warnings are sent via syslog.
+If the DEVPATH environment variable is set, scsi_id assumes it has been
+invoked via udev (or some other hotplug program), and all errors or
+warnings are sent using syslog.
 
 To determine the specific value needed in a RESULT key, use the \-s option,
 for example:
 
 To determine the specific value needed in a RESULT key, use the \-s option,
 for example:
@@ -131,7 +134,7 @@ of 312345:
 
 .sp
 .nf
 
 .sp
 .nf
-BUS="scsi", PROGRAM="/sbin/scsi_id", RESULT="312345", NAME="disk%n"
+BUS="scsi", PROGRAM="/sbin/scsi_id -d %N -s %p", RESULT="312345", NAME="disk%n"
 .fi
 .P
 
 .fi
 .P
 
index f45563d1b3b9ed328318ff8f909051e92d144188..507fa27766fe2d5fd02055a8d05dd3d2fff96a0a 100644 (file)
@@ -44,8 +44,8 @@
 /*
  * temporary names for mknod.
  */
 /*
  * temporary names for mknod.
  */
-#define TMP_DIR        "/dev"
-#define TMP_PREFIX "tmp-scsi"
+#define TMP_DIR        "/tmp"
+#define TMP_PREFIX "scsi"
 
 /*
  * XXX Note the 'e' (send output to stderr in all cases), and 'c' (callout)
 
 /*
  * XXX Note the 'e' (send output to stderr in all cases), and 'c' (callout)
@@ -736,9 +736,7 @@ static int scsi_id(const char *target_path, char *maj_min_dev)
                        format_serial(serial);
                if (display_bus_id)
                        printf("%s: ", scsi_dev->name);
                        format_serial(serial);
                if (display_bus_id)
                        printf("%s: ", scsi_dev->name);
-               printf("%s", serial);
-               if (!hotplug_mode)
-                       printf("\n");
+               printf("%s\n", serial);
                dprintf("%s\n", serial);
                retval = 0;
        }
                dprintf("%s\n", serial);
                retval = 0;
        }
@@ -762,11 +760,6 @@ int main(int argc, char **argv)
        if (getenv("DEBUG"))
                debug++;
 
        if (getenv("DEBUG"))
                debug++;
 
-       if ((argc == 2) && (argv[1][0] != '-')) {
-               hotplug_mode = 1;
-               dprintf("hotplug assumed\n");
-       }
-
        dprintf("argc is %d\n", argc);
        if (sysfs_get_mnt_path(sysfs_mnt_path, MAX_NAME_LEN)) {
                log_message(LOG_WARNING, "sysfs_get_mnt_path failed: %s\n",
        dprintf("argc is %d\n", argc);
        if (sysfs_get_mnt_path(sysfs_mnt_path, MAX_NAME_LEN)) {
                log_message(LOG_WARNING, "sysfs_get_mnt_path failed: %s\n",
@@ -774,27 +767,19 @@ int main(int argc, char **argv)
                exit(1);
        }
 
                exit(1);
        }
 
-       if (hotplug_mode) {
+       devpath = getenv("DEVPATH");
+       if (devpath) {
                /*
                /*
-                * There is a kernel race creating attributes, if called
-                * directly, uncomment the sleep.
+                * This implies that we were invoked via udev or hotplug.
                 */
                 */
-               /* sleep(1); */
-
-               devpath = getenv("DEVPATH");
-               if (!devpath) {
-                       log_message(LOG_WARNING, "DEVPATH is not set\n");
-                       exit(1);
-               }
+               hotplug_mode = 1;
                sys_specified = 1;
                sys_specified = 1;
-
                strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN);
                strncat(target_path, devpath, MAX_NAME_LEN);
        }
 
        /*
                strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN);
                strncat(target_path, devpath, MAX_NAME_LEN);
        }
 
        /*
-        * Override any command line options set via the config file. This
-        * is the only way to set options when in hotplug mode.
+        * Get config file options.
         */
        newargv = NULL;
        retval = get_file_options(NULL, NULL, &newargc, &newargv);
         */
        newargv = NULL;
        retval = get_file_options(NULL, NULL, &newargc, &newargv);
@@ -806,11 +791,13 @@ int main(int argc, char **argv)
                        exit(1);
                free(newargv);
        }
                        exit(1);
                free(newargv);
        }
-       if (!hotplug_mode) {
-               if (set_options(argc, argv, short_options, target_path,
-                               maj_min_dev) < 0)
+       /*
+        * Get command line options (overriding any config file or DEVPATH
+        * settings).
+        */
+       if (set_options(argc, argv, short_options, target_path,
+                       maj_min_dev) < 0)
                exit(1);
                exit(1);
-       }
 
        if (!sys_specified) {
                log_message(LOG_WARNING, "-s must be specified\n");
 
        if (!sys_specified) {
                log_message(LOG_WARNING, "-s must be specified\n");