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