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