* options are not supported, but other code is still left in place for
* now.
*/
-static const char short_options[] = "bd:f:gip:s:vV";
+static const char short_options[] = "bd:f:gip:s:uvV";
/*
* Just duplicate per dev options.
*/
static int use_stderr;
static int debug;
static int hotplug_mode;
+static int reformat_serial;
void log_message (int level, const char *format, ...)
{
strncat(target, optarg, MAX_NAME_LEN);
break;
+ case 'u':
+ reformat_serial = 1;
+ break;
+
case 'v':
debug++;
break;
return retval;
}
+/*
+ * format_serial: replace to whitespaces by underscores for calling
+ * programs that use the serial for device naming (multipath, Suse
+ * naming, etc...)
+ */
+static void format_serial(char *serial)
+{
+ char *p = serial;
+
+ while (*p != '\0') {
+ if (isspace(*p))
+ *p = '_';
+ p++;
+ }
+ return;
+}
+
/*
* scsi_id: try to get an id, if one is found, printf it to stdout.
* returns a value passed to exit() - 0 if printed an id, else 1. This
{
int retval;
int dev_type = 0;
- char serial[MAX_SERIAL_LEN];
+ char *serial, *unaligned_buf;
struct sysfs_class_device *class_dev; /* of target_path */
struct sysfs_class_device *class_dev_parent; /* for partitions */
struct sysfs_device *scsi_dev; /* the scsi_device */
dprintf("per dev options: good %d; page code 0x%x; callout '%s'\n",
good_dev, page_code, callout);
+#define ALIGN 512
+ unaligned_buf = malloc(MAX_SERIAL_LEN + ALIGN);
+ serial = (char*) (((unsigned long) unaligned_buf + (ALIGN - 1))
+ & ~(ALIGN - 1));
+ dprintf("buffer unaligned 0x%p; aligned 0x%p\n", unaligned_buf, serial);
+#undef ALIGN
+
if (!good_dev) {
retval = 1;
} else if (callout[0] != '\0') {
retval = 0;
}
if (!retval) {
+ if (reformat_serial)
+ 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;
}
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",
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;
-
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);
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);
- }
if (!sys_specified) {
log_message(LOG_WARNING, "-s must be specified\n");