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