chiark / gitweb /
75a342bb1265c10c896f291b231ae45ef4bdb01f
[elogind.git] / extras / scsi_id / scsi_id.c
1 /*
2  * scsi_id.c
3  *
4  * Main section of the scsi_id program
5  *
6  * Copyright (C) IBM Corp. 2003
7  *
8  *  This library is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU Lesser General Public License as
10  *  published by the Free Software Foundation; either version 2.1 of the
11  *  License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful, but
14  *  WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  *  USA
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <signal.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <syslog.h>
32 #include <stdarg.h>
33 #include <ctype.h>
34 #include <sys/stat.h>
35 #ifdef __KLIBC__
36 /*
37  * Assume built under udev with KLIBC
38  */
39 #include <libsysfs.h>
40 #else
41 #include <sysfs/libsysfs.h>
42 #endif
43 #include "scsi_id_version.h"
44 #include "scsi_id.h"
45
46 #ifndef SCSI_ID_VERSION
47 #warning No version
48 #define SCSI_ID_VERSION "unknown"
49 #endif
50
51 /*
52  * temporary names for mknod.
53  */
54 #define TMP_DIR "/tmp"
55 #define TMP_PREFIX "scsi"
56
57 static const char short_options[] = "bc:d:ef:gip:s:vV";
58 /*
59  * Just duplicate per dev options.
60  */
61 static const char dev_short_options[] = "bc:gp:";
62
63 char sysfs_mnt_path[SYSFS_PATH_MAX];
64
65 static int all_good;
66 static char *default_callout;
67 static int dev_specified;
68 static int sys_specified;
69 static char config_file[MAX_NAME_LEN] = SCSI_ID_CONFIG_FILE;
70 static int display_bus_id;
71 static int default_page_code;
72 static int use_stderr;
73 static int debug;
74 static int hotplug_mode;
75
76 void log_message (int level, const char *format, ...)
77 {
78         va_list args;
79
80         if (!debug && level == LOG_DEBUG)
81                 return;
82
83         va_start (args, format);
84         if (!hotplug_mode || use_stderr) {
85                 vfprintf(stderr, format, args);
86         } else {
87                 static int logging_init = 0;
88                 static unsigned char logname[32];
89                 if (!logging_init) {
90                         /*
91                          * klibc does not have LOG_PID.
92                          */
93                         snprintf(logname, 32, "scsi_id[%d]", getpid());
94                         openlog (logname, 0, LOG_DAEMON);
95                         logging_init = 1;
96                 }
97
98                 vsyslog(level, format, args);
99         }
100         va_end (args);
101         return;
102 }
103
104 int sysfs_get_attr(const char *devpath, const char *attr, char *value,
105                    size_t bufsize)
106 {
107         char attr_path[SYSFS_PATH_MAX];
108
109         strncpy(attr_path, devpath, SYSFS_PATH_MAX);
110         strncat(attr_path, "/", SYSFS_PATH_MAX);
111         strncat(attr_path, attr,  SYSFS_PATH_MAX);
112         dprintf("%s\n", attr_path);
113         return sysfs_read_attribute_value(attr_path, value, SYSFS_NAME_LEN);
114 }
115
116 static int sysfs_get_actual_dev(const char *sysfs_path, char *dev, int len)
117 {
118         dprintf("%s\n", sysfs_path);
119         strncpy(dev, sysfs_path, len);
120         strncat(dev, "/device", len);
121         if (sysfs_get_link(dev, dev, len)) {
122                 if (!hotplug_mode)
123                         log_message(LOG_WARNING, "%s: %s\n", dev,
124                                     strerror(errno));
125                 return -1;
126         }
127         return 0;
128 }
129
130 /*
131  * sysfs_is_bus: Given the sysfs_path to a device, return 1 if sysfs_path
132  * is on bus, 0 if not on bus, and < 0 on error
133  */
134 static int sysfs_is_bus(const char *sysfs_path, const char *bus)
135 {
136         char bus_dev_name[SYSFS_PATH_MAX];
137         char bus_id[SYSFS_NAME_LEN];
138         struct stat stat_buf;
139         ino_t dev_inode;
140
141         dprintf("%s\n", sysfs_path);
142
143         if (sysfs_get_name_from_path(sysfs_path, bus_id, SYSFS_NAME_LEN))
144                 return -1;
145
146         snprintf(bus_dev_name, MAX_NAME_LEN, "%s/%s/%s/%s/%s", sysfs_mnt_path,
147                  SYSFS_BUS_NAME, bus, SYSFS_DEVICES_NAME, bus_id);
148
149         if (stat(sysfs_path, &stat_buf))
150                 return -1;
151         dev_inode = stat_buf.st_ino;
152
153         if (stat(bus_dev_name, &stat_buf)) {
154                 if (errno == ENOENT)
155                         return 0;
156                 else
157                         return -1;
158         }
159         if (dev_inode == stat_buf.st_ino)
160                 return 1;
161         else
162                 return 0;
163 }
164
165 static int get_major_minor(const char *devpath, int *major, int *minor)
166 {
167         char dev_value[MAX_ATTR_LEN];
168
169         if (sysfs_get_attr(devpath, "dev", dev_value, MAX_ATTR_LEN)) {
170                 /*
171                  * XXX This happens a lot, since sg has no dev attr.
172                  * And now sysfsutils does not set a meaningful errno
173                  * value. Someday change this back to a LOG_WARNING.
174                  * And if sysfsutils changes, check for ENOENT and handle
175                  * it separately.
176                  */
177                 log_message(LOG_DEBUG, "%s could not get dev attribute: %s\n",
178                         devpath, strerror(errno));
179                 return -1;
180         }
181
182         dprintf("dev value %s", dev_value); /* dev_value has a trailing \n */
183         if (sscanf(dev_value, "%u:%u", major, minor) != 2) {
184                 log_message(LOG_WARNING, "%s: invalid dev major/minor\n",
185                             devpath);
186                 return -1;
187         }
188
189         return 0;
190 }
191
192 static int create_tmp_dev(const char *devpath, char *tmpdev, int dev_type)
193 {
194         int major, minor;
195
196         dprintf("(%s)\n", devpath);
197
198         if (get_major_minor(devpath, &major, &minor))
199                 return -1;
200         snprintf(tmpdev, MAX_NAME_LEN, "%s/%s-maj%d-min%d-%u",
201                  TMP_DIR, TMP_PREFIX, major, minor, getpid());
202
203         dprintf("tmpdev '%s'\n", tmpdev);
204
205         if (mknod(tmpdev, 0600 | dev_type, makedev(major, minor))) {
206                 log_message(LOG_WARNING, "mknod failed: %s\n", strerror(errno));
207                 return -1;
208         }
209         return 0;
210 }
211
212 static int has_sysfs_prefix(const char *path, const char *prefix)
213 {
214         char match[MAX_NAME_LEN];
215
216         strncpy(match, sysfs_mnt_path, MAX_NAME_LEN);
217         strncat(match, prefix, MAX_NAME_LEN);
218         if (strncmp(path, match, strlen(match)) == 0)
219                 return 1;
220         else
221                 return 0;
222 }
223
224 /*
225  * get_value:
226  *
227  * buf points to an '=' followed by a quoted string ("foo") or a string ending
228  * with a space or ','.
229  *
230  * Return a pointer to the NUL terminated string, returns NULL if no
231  * matches.
232  */
233 static char *get_value(char **buffer)
234 {
235         static char *quote_string = "\"\n";
236         static char *comma_string = ",\n";
237         char *val;
238         char *end;
239
240         if (**buffer == '"') {
241                 /*
242                  * skip leading quote, terminate when quote seen
243                  */
244                 (*buffer)++;
245                 end = quote_string;
246         } else {
247                 end = comma_string;
248         }
249         val = strsep(buffer, end);
250         if (val && end == quote_string)
251                 /*
252                  * skip trailing quote
253                  */
254                 (*buffer)++;
255
256         while (isspace(**buffer))
257                 (*buffer)++;
258
259         return val;
260 }
261
262 static int argc_count(char *opts)
263 {
264         int i = 0;
265         while (*opts != '\0')
266                 if (*opts++ == ' ')
267                         i++;
268         return i;
269 }
270
271 /*
272  * get_file_options:
273  *
274  * If vendor == NULL, find a line in the config file with only "OPTIONS=";
275  * if vendor and model are set find the first OPTIONS line in the config
276  * file that matches. Set argc and argv to match the OPTIONS string.
277  *
278  * vendor and model can end in '\n'.
279  */
280 static int get_file_options(char *vendor, char *model, int *argc,
281                             char ***newargv)
282 {
283         char *buffer;
284         FILE *fd;
285         char *buf;
286         char *str1;
287         char *vendor_in, *model_in, *options_in; /* read in from file */
288         int lineno;
289         int c;
290         int retval = 0;
291
292         dprintf("vendor='%s'; model='%s'\n", vendor, model);
293         fd = fopen(config_file, "r");
294         if (fd == NULL) {
295                 dprintf("can't open %s\n", config_file);
296                 if (errno == ENOENT) {
297                         return 1;
298                 } else {
299                         log_message(LOG_WARNING, "can't open %s: %s\n",
300                                 config_file, strerror(errno));
301                         return -1;
302                 }
303         }
304
305         /*
306          * Allocate a buffer rather than put it on the stack so we can
307          * keep it around to parse any options (any allocated newargv
308          * points into this buffer for its strings).
309          */
310         buffer = malloc(MAX_BUFFER_LEN);
311         if (!buffer) {
312                 log_message(LOG_WARNING, "Can't allocate memory.\n");
313                 return -1;
314         }
315
316         *newargv = NULL;
317         lineno = 0;
318         while (1) {
319                 vendor_in = model_in = options_in = NULL;
320
321                 buf = fgets(buffer, MAX_BUFFER_LEN, fd);
322                 if (buf == NULL)
323                         break;
324                 lineno++;
325                 if (buf[strlen(buffer) - 1] != '\n') {
326                         log_message(LOG_WARNING,
327                                     "Config file line %d too long.\n", lineno);
328                         break;
329                 }
330
331                 while (isspace(*buf))
332                         buf++;
333
334                 if (*buf == '\0')
335                         /*
336                          * blank or all whitespace line
337                          */
338                         continue;
339
340                 if (*buf == '#')
341                         /*
342                          * comment line
343                          */
344                         continue;
345
346 #ifdef LOTS
347                 dprintf("lineno %d: '%s'\n", lineno, buf);
348 #endif
349                 str1 = strsep(&buf, "=");
350                 if (str1 && strcasecmp(str1, "VENDOR") == 0) {
351                         str1 = get_value(&buf);
352                         if (!str1) {
353                                 retval = -1;
354                                 break;
355                         }
356                         vendor_in = str1;
357
358                         str1 = strsep(&buf, "=");
359                         if (str1 && strcasecmp(str1, "MODEL") == 0) {
360                                 str1 = get_value(&buf);
361                                 if (!str1) {
362                                         retval = -1;
363                                         break;
364                                 }
365                                 model_in = str1;
366                                 str1 = strsep(&buf, "=");
367                         }
368                 }
369
370                 if (str1 && strcasecmp(str1, "OPTIONS") == 0) {
371                         str1 = get_value(&buf);
372                         if (!str1) {
373                                 retval = -1;
374                                 break;
375                         }
376                         options_in = str1;
377                 }
378                 dprintf("config file line %d:"
379                         " vendor '%s'; model '%s'; options '%s'\n",
380                         lineno, vendor_in, model_in, options_in);
381                 /*
382                  * Only allow: [vendor=foo[,model=bar]]options=stuff
383                  */
384                 if (!options_in || (!vendor_in && model_in)) {
385                         log_message(LOG_WARNING,
386                                     "Error parsing config file line %d '%s'\n",
387                                     lineno, buffer);
388                         retval = -1;
389                         break;
390                 }
391                 if (vendor == NULL) {
392                         if (vendor_in == NULL) {
393                                 dprintf("matched global option\n");
394                                 break;
395                         }
396                 } else if ((vendor_in && strncmp(vendor, vendor_in,
397                                                  strlen(vendor_in)) == 0) &&
398                            (!model_in || (strncmp(model, model_in,
399                                                   strlen(model_in)) == 0))) {
400                                 /*
401                                  * Matched vendor and optionally model.
402                                  *
403                                  * Note: a short vendor_in or model_in can
404                                  * give a partial match (that is FOO
405                                  * matches FOOBAR).
406                                  */
407                                 dprintf("matched vendor/model\n");
408                                 break;
409                 } else {
410                         dprintf("no match\n");
411                 }
412         }
413
414         if (retval == 0) {
415                 if (vendor_in != NULL || model_in != NULL ||
416                     options_in != NULL) {
417                         /*
418                          * Something matched. Allocate newargv, and store
419                          * values found in options_in.
420                          */
421                         strcpy(buffer, options_in);
422                         c = argc_count(buffer) + 2;
423                         *newargv = calloc(c, sizeof(**newargv));
424                         if (!*newargv) {
425                                 log_message(LOG_WARNING,
426                                             "Can't allocate memory.\n");
427                                 retval = -1;
428                         } else {
429                                 *argc = c;
430                                 c = 0;
431                                 /*
432                                  * argv[0] at 0 is skipped by getopt, but
433                                  * store the buffer address there for
434                                  * alter freeing.
435                                  */
436                                 (*newargv)[c] = buffer;
437                                 for (c = 1; c < *argc; c++)
438                                         (*newargv)[c] = strsep(&buffer, " ");
439                         }
440                 } else {
441                         /*
442                          * No matches.
443                          */
444                         retval = 1;
445                 }
446         }
447         if (retval != 0)
448                 free(buffer);
449         fclose(fd);
450         return retval;
451 }
452
453 static int set_options(int argc, char **argv, const char *short_opts,
454                        char *target, char *maj_min_dev)
455 {
456         int option;
457
458         /*
459          * optind is a global extern used by getopt. Since we can call
460          * set_options twice (once for command line, and once for config
461          * file) we have to reset this back to 1. [Note glibc handles
462          * setting this to 0, but klibc does not.]
463          */
464         optind = 1;
465         while (1) {
466                 option = getopt(argc, argv, short_options);
467                 if (option == -1)
468                         break;
469
470                 if (optarg)
471                         dprintf("option '%c' arg '%s'\n", option, optarg);
472                 else
473                         dprintf("option '%c'\n", option);
474
475                 switch (option) {
476                 case 'b':
477                         all_good = 0;
478                         break;
479
480                 case 'c':
481                         default_callout = optarg;
482                         break;
483
484                 case 'd':
485                         dev_specified = 1;
486                         strncpy(maj_min_dev, optarg, MAX_NAME_LEN);
487                         break;
488
489                 case 'e':
490                         use_stderr = 1;
491                         break;
492
493                 case 'f':
494                         strncpy(config_file, optarg, MAX_NAME_LEN);
495                         break;
496
497                 case 'g':
498                         all_good = 1;
499                         break;
500
501                 case 'i':
502                         display_bus_id = 1;
503                         break;
504
505                 case 'p':
506                         if (strcmp(optarg, "0x80") == 0) {
507                                 default_page_code = 0x80;
508                         } else if (strcmp(optarg, "0x83") == 0) {
509                                 default_page_code = 0x83;
510                         } else {
511                                 log_message(LOG_WARNING,
512                                             "Unknown page code '%s'\n", optarg);
513                                 return -1;
514                         }
515                         break;
516
517                 case 's':
518                         sys_specified = 1;
519                         strncpy(target, sysfs_mnt_path, MAX_NAME_LEN);
520                         strncat(target, optarg, MAX_NAME_LEN);
521                         break;
522
523                 case 'v':
524                         debug++;
525                         break;
526
527                 case 'V':
528                         log_message(LOG_WARNING, "scsi_id version: %s\n",
529                                     SCSI_ID_VERSION);
530                         exit(0);
531                         break;
532
533                 default:
534                         log_message(LOG_WARNING,
535                                     "Unknown or bad option '%c' (0x%x)\n",
536                                     option, option);
537                         return -1;
538                 }
539         }
540         return 0;
541 }
542
543 static int per_dev_options(struct sysfs_class_device *scsi_dev, int *good_bad,
544                            int *page_code, char *callout)
545 {
546         int retval;
547         int newargc;
548         char **newargv = NULL;
549         char vendor[MAX_ATTR_LEN];
550         char model[MAX_ATTR_LEN];
551         int option;
552
553         *good_bad = all_good;
554         *page_code = default_page_code;
555         if (default_callout && (callout != default_callout))
556                 strncpy(callout, default_callout, MAX_NAME_LEN);
557         else
558                 callout[0] = '\0';
559
560         if (sysfs_get_attr(scsi_dev->path, "vendor", vendor, MAX_ATTR_LEN)) {
561                 log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
562                             scsi_dev->name);
563                 return -1;
564         }
565
566         if (sysfs_get_attr(scsi_dev->path, "model", model, MAX_ATTR_LEN)) {
567                 log_message(LOG_WARNING, "%s: cannot get model attribute\n",
568                             scsi_dev->name);
569                 return -1;
570         }
571
572         retval = get_file_options(vendor, model, &newargc, &newargv);
573
574         optind = 1; /* reset this global extern */
575         while (retval == 0) {
576                 option = getopt(newargc, newargv, dev_short_options);
577                 if (option == -1)
578                         break;
579
580                 if (optarg)
581                         dprintf("option '%c' arg '%s'\n", option, optarg);
582                 else
583                         dprintf("option '%c'\n", option);
584
585                 switch (option) {
586                 case 'b':
587                         *good_bad = 0;
588                         break;
589
590                 case 'c':
591                         strncpy(callout, default_callout, MAX_NAME_LEN);
592                         break;
593
594                 case 'g':
595                         *good_bad = 1;
596                         break;
597
598                 case 'p':
599                         if (strcmp(optarg, "0x80") == 0) {
600                                 *page_code = 0x80;
601                         } else if (strcmp(optarg, "0x83") == 0) {
602                                 *page_code = 0x83;
603                         } else {
604                                 log_message(LOG_WARNING,
605                                             "Unknown page code '%s'\n", optarg);
606                                 retval = -1;
607                         }
608                         break;
609
610                 default:
611                         log_message(LOG_WARNING,
612                                     "Unknown or bad option '%c' (0x%x)\n",
613                                     option, option);
614                         retval = -1;
615                         break;
616                 }
617         }
618
619         if (newargv) {
620                 free(newargv[0]);
621                 free(newargv);
622         }
623         return retval;
624 }
625
626 /*
627  * scsi_id: try to get an id, if one is found, printf it to stdout.
628  * returns a value passed to exit() - 0 if printed an id, else 1. This
629  * could be expanded, for example, if we want to report a failure like no
630  * memory etc. return 2, and return 1 for expected cases (like broken
631  * device found) that do not print an id.
632  */
633 static int scsi_id(const char *target_path, char *maj_min_dev)
634 {
635         int retval;
636         int dev_type = 0;
637         char full_dev_path[MAX_NAME_LEN];
638         char serial[MAX_SERIAL_LEN];
639         struct sysfs_class_device *scsi_dev; /* of scsi_device full_dev_path */
640         int good_dev;
641         int page_code;
642         char callout[MAX_NAME_LEN];
643
644         dprintf("target_path %s\n", target_path);
645
646         /*
647          * Ugly: depend on the sysfs path to tell us whether this is a
648          * block or char device. This should probably be encoded in the
649          * "dev" along with the major/minor.
650          */
651         if (has_sysfs_prefix(target_path, "/block")) {
652                 dev_type = S_IFBLK;
653         } else if (has_sysfs_prefix(target_path, "/class")) {
654                 dev_type = S_IFCHR;
655         } else {
656                 if (!hotplug_mode) {
657                         log_message(LOG_WARNING,
658                                     "Non block or class device '%s'\n",
659                                     target_path);
660                         return 1;
661                 } else {
662                         /*
663                          * Expected in some cases.
664                          */
665                         dprintf("Non block or class device\n");
666                         return 0;
667                 }
668         }
669
670         if (sysfs_get_actual_dev(target_path, full_dev_path, MAX_NAME_LEN))
671                 return 1;
672
673         dprintf("full_dev_path %s\n", full_dev_path);
674
675         /*
676          * Allow only scsi devices (those that have a matching device
677          * under /bus/scsi/devices).
678          *
679          * Other block devices can support SG IO, but only ide-cd does, so
680          * for now, don't bother with anything else.
681          */
682         retval = sysfs_is_bus(full_dev_path, "scsi");
683         if (retval == 0) {
684                 if (hotplug_mode)
685                         /*
686                          * Expected in some cases.
687                          */
688                         dprintf("%s is not a scsi device\n", target_path);
689                 else
690                         log_message(LOG_WARNING, "%s is not a scsi device\n",
691                                     target_path);
692                 return 1;
693         } else if (retval < 0) {
694                 log_message(LOG_WARNING, "sysfs_is_bus failed: %s\n",
695                         strerror(errno));
696                 return 1;
697         }
698
699         /*
700          * mknod a temp dev to communicate with the device.
701          */
702         if (!dev_specified && create_tmp_dev(target_path, maj_min_dev,
703                                              dev_type)) {
704                 dprintf("create_tmp_dev failed\n");
705                 return 1;
706         }
707
708         scsi_dev = sysfs_open_class_device_path(full_dev_path);
709         if (!scsi_dev) {
710                 log_message(LOG_WARNING, "open class %s failed: %s\n",
711                             full_dev_path, strerror(errno));
712                 return 1;
713         }
714
715         /*
716          * Get any per device (vendor + model) options from the config
717          * file.
718          */
719         retval = per_dev_options(scsi_dev, &good_dev, &page_code, callout);
720         dprintf("per dev options: good %d; page code 0x%x; callout '%s'\n",
721                 good_dev, page_code, callout);
722
723         if (!good_dev) {
724                 retval = 1;
725         } else if (callout[0] != '\0') {
726                 /*
727                  * exec vendor callout, pass it only the "name" to be used
728                  * for error messages, and the dev to open.
729                  *
730                  * This won't work if we need to pass on the original
731                  * command line (when not hotplug mode) since the option
732                  * parsing and per dev parsing modify the argv's.
733                  *
734                  * XXX Not implemented yet. And not fully tested ;-)
735                  */
736                 retval = 1;
737         } else if (scsi_get_serial(scsi_dev, maj_min_dev, page_code,
738                                    serial, MAX_SERIAL_LEN)) {
739                 retval = 1;
740         } else {
741                 retval = 0;
742         }
743         if (!retval) {
744                 if (display_bus_id)
745                         printf("%s ", scsi_dev->name);
746                 printf("%s", serial);
747                 if (!hotplug_mode)
748                         printf("\n");
749                 dprintf("%s\n", serial);
750                 retval = 0;
751         }
752         sysfs_close_class_device(scsi_dev);
753
754         if (!dev_specified)
755                 unlink(maj_min_dev);
756
757         return retval;
758 }
759
760 int main(int argc, char **argv)
761 {
762         int retval;
763         char *devpath;
764         char target_path[MAX_NAME_LEN];
765         char maj_min_dev[MAX_NAME_LEN];
766         int newargc;
767         char **newargv;
768
769         if (getenv("DEBUG"))
770                 debug++;
771
772         if ((argc == 2) && (argv[1][0] != '-')) {
773                 hotplug_mode = 1;
774                 dprintf("hotplug assumed\n");
775         }
776
777         dprintf("argc is %d\n", argc);
778         if (sysfs_get_mnt_path(sysfs_mnt_path, MAX_NAME_LEN)) {
779                 log_message(LOG_WARNING, "sysfs_get_mnt_path failed: %s\n",
780                         strerror(errno));
781                 exit(1);
782         }
783
784         if (hotplug_mode) {
785                 /*
786                  * There is a kernel race creating attributes, if called
787                  * directly, uncomment the sleep.
788                  */
789                 /* sleep(1); */
790
791                 devpath = getenv("DEVPATH");
792                 if (!devpath) {
793                         log_message(LOG_WARNING, "DEVPATH is not set\n");
794                         exit(1);
795                 }
796                 sys_specified = 1;
797
798                 strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN);
799                 strncat(target_path, devpath, MAX_NAME_LEN);
800         } else {
801                 if (set_options(argc, argv, short_options, target_path,
802                                 maj_min_dev) < 0)
803                         exit(1);
804         }
805
806         /*
807          * Override any command line options set via the config file. This
808          * is the only way to set options when in hotplug mode.
809          */
810         newargv = NULL;
811         retval = get_file_options(NULL, NULL, &newargc, &newargv);
812         if (retval < 0) {
813                 exit(1);
814         } else if (newargv && (retval == 0)) {
815                 if (set_options(newargc, newargv, short_options, target_path,
816                                 maj_min_dev) < 0)
817                         exit(1);
818                 free(newargv);
819         }
820
821         if (!sys_specified) {
822                 log_message(LOG_WARNING, "-s must be specified\n");
823                 exit(1);
824         }
825
826         retval = scsi_id(target_path, maj_min_dev);
827         exit(retval);
828 }