scsi_id.c revision b43d1d01eabe2cbbf393e8f56b76e182c6069c4c
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) IBM Corp. 2003
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * Copyright (C) SUSE Linux Products GmbH, 2006
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering *
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is free software: you can redistribute it and/or modify
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * it under the terms of the GNU General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering *
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * This program is distributed in the hope that it will be useful,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * GNU General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering *
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * You should have received a copy of the GNU General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdio.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdlib.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <unistd.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <signal.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <fcntl.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <errno.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <string.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <syslog.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <stdarg.h>
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering#include <ctype.h>
24710c48ed16be5fa461fbb303a744a907541dafLennart Poettering#include <getopt.h>
71d35b6b5563817dfbe757ab9e3b9f018b2db491Thomas Hindoe Paaboel Andersen#include <sys/stat.h>
71d35b6b5563817dfbe757ab9e3b9f018b2db491Thomas Hindoe Paaboel Andersen
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering#include "libudev.h"
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering#include "libudev-private.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "scsi_id.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic const struct option options[] = {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "device", required_argument, NULL, 'd' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "config", required_argument, NULL, 'f' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "page", required_argument, NULL, 'p' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "blacklisted", no_argument, NULL, 'b' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "whitelisted", no_argument, NULL, 'g' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "replace-whitespace", no_argument, NULL, 'u' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "sg-version", required_argument, NULL, 's' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "verbose", no_argument, NULL, 'v' },
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering { "version", no_argument, NULL, 'V' },
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering { "export", no_argument, NULL, 'x' },
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering { "help", no_argument, NULL, 'h' },
24710c48ed16be5fa461fbb303a744a907541dafLennart Poettering {}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering};
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic const char short_options[] = "d:f:ghip:uvVx";
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringstatic const char dev_short_options[] = "bgp:";
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poetteringstatic int all_good;
1e43061b67336052b5b231840a38508a5397a363Michal Schmidtstatic int dev_specified;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poetteringstatic char config_file[MAX_PATH_LEN] = "/etc/scsi_id.config";
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poetteringstatic enum page_code default_page_code;
aea2429d6ec32261dbf6b9caa125fcc6ea9ea76aLennart Poetteringstatic int sg_version = 4;
aea2429d6ec32261dbf6b9caa125fcc6ea9ea76aLennart Poetteringstatic int use_stderr;
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersenstatic int debug;
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersenstatic int reformat_serial;
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersenstatic int export;
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poetteringstatic char vendor_str[64];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic char model_str[64];
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poetteringstatic char vendor_enc_str[256];
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poetteringstatic char model_enc_str[256];
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poetteringstatic char revision_str[16];
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poetteringstatic char type_str[16];
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poettering
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poetteringstatic void log_fn(struct udev *udev, int priority,
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poettering const char *file, int line, const char *fn,
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poettering const char *format, va_list args)
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poettering{
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poettering vsyslog(priority, format, args);
f9ebb22ab4758bc5bbaaf8eeead74b5b4f81d5c3Lennart Poettering}
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void set_type(const char *from, char *to, size_t len)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering{
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering int type_num;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char *eptr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering const char *type = "generic";
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen type_num = strtoul(from, &eptr, 0);
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen if (eptr != from) {
519ef04651b07a547f010d6462603669d7fde4e5Lennart Poettering switch (type_num) {
519ef04651b07a547f010d6462603669d7fde4e5Lennart Poettering case 0:
519ef04651b07a547f010d6462603669d7fde4e5Lennart Poettering type = "disk";
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering break;
51323288fc628a5cac50914df915545d685b793eLennart Poettering case 1:
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering type = "tape";
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering break;
2c27fbca2d88214bd305272308a370a962818f1eLennart Poettering case 4:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering type = "optical";
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering break;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering case 5:
0db4c90afd7d9c7c8884bf8b3ec459edc74a03daDaniel Mack type = "cd";
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering break;
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering case 7:
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering type = "optical";
f52e61da047d7fc74e83f12dbbf87e0cbcc51c73Lennart Poettering break;
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering case 0xe:
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering type = "disk";
a407657425a3e47fd2b559cd3bc800f791303f63Lennart Poettering break;
4d506d6bb757af3b99e0876234c465e6898c5ea4Lennart Poettering case 0xf:
4d506d6bb757af3b99e0876234c465e6898c5ea4Lennart Poettering type = "optical";
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering break;
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering default:
801ad6a6a9cd8fbd58b9f9c27f20dbb3c87d47ddLennart Poettering break;
dc477e7385e8ab29efb8fadb72ec994077a105c6Lennart Poettering }
}
strscpy(to, len, type);
}
/*
* get_value:
*
* buf points to an '=' followed by a quoted string ("foo") or a string ending
* with a space or ','.
*
* Return a pointer to the NUL terminated string, returns NULL if no
* matches.
*/
static char *get_value(char **buffer)
{
static const char *quote_string = "\"\n";
static const char *comma_string = ",\n";
char *val;
const char *end;
if (**buffer == '"') {
/*
* skip leading quote, terminate when quote seen
*/
(*buffer)++;
end = quote_string;
} else {
end = comma_string;
}
val = strsep(buffer, end);
if (val && end == quote_string)
/*
* skip trailing quote
*/
(*buffer)++;
while (isspace(**buffer))
(*buffer)++;
return val;
}
static int argc_count(char *opts)
{
int i = 0;
while (*opts != '\0')
if (*opts++ == ' ')
i++;
return i;
}
/*
* get_file_options:
*
* If vendor == NULL, find a line in the config file with only "OPTIONS=";
* if vendor and model are set find the first OPTIONS line in the config
* file that matches. Set argc and argv to match the OPTIONS string.
*
* vendor and model can end in '\n'.
*/
static int get_file_options(struct udev *udev,
const char *vendor, const char *model,
int *argc, char ***newargv)
{
char *buffer;
FILE *fd;
char *buf;
char *str1;
char *vendor_in, *model_in, *options_in; /* read in from file */
int lineno;
int c;
int retval = 0;
fd = fopen(config_file, "re");
if (fd == NULL) {
if (errno == ENOENT) {
return 1;
} else {
log_error("can't open %s: %s\n", config_file, strerror(errno));
return -1;
}
}
/*
* Allocate a buffer rather than put it on the stack so we can
* keep it around to parse any options (any allocated newargv
* points into this buffer for its strings).
*/
buffer = malloc(MAX_BUFFER_LEN);
if (!buffer) {
fclose(fd);
return log_oom();
}
*newargv = NULL;
lineno = 0;
while (1) {
vendor_in = model_in = options_in = NULL;
buf = fgets(buffer, MAX_BUFFER_LEN, fd);
if (buf == NULL)
break;
lineno++;
if (buf[strlen(buffer) - 1] != '\n') {
log_error("Config file line %d too long\n", lineno);
break;
}
while (isspace(*buf))
buf++;
/* blank or all whitespace line */
if (*buf == '\0')
continue;
/* comment line */
if (*buf == '#')
continue;
str1 = strsep(&buf, "=");
if (str1 && strcaseeq(str1, "VENDOR")) {
str1 = get_value(&buf);
if (!str1) {
retval = log_oom();
break;
}
vendor_in = str1;
str1 = strsep(&buf, "=");
if (str1 && strcaseeq(str1, "MODEL")) {
str1 = get_value(&buf);
if (!str1) {
retval = log_oom();
break;
}
model_in = str1;
str1 = strsep(&buf, "=");
}
}
if (str1 && strcaseeq(str1, "OPTIONS")) {
str1 = get_value(&buf);
if (!str1) {
retval = log_oom();
break;
}
options_in = str1;
}
/*
* Only allow: [vendor=foo[,model=bar]]options=stuff
*/
if (!options_in || (!vendor_in && model_in)) {
log_error("Error parsing config file line %d '%s'\n", lineno, buffer);
retval = -1;
break;
}
if (vendor == NULL) {
if (vendor_in == NULL)
break;
} else if ((vendor_in && strneq(vendor, vendor_in,
strlen(vendor_in))) &&
(!model_in || (strneq(model, model_in,
strlen(model_in))))) {
/*
* Matched vendor and optionally model.
*
* Note: a short vendor_in or model_in can
* give a partial match (that is FOO
* matches FOOBAR).
*/
break;
}
}
if (retval == 0) {
if (vendor_in != NULL || model_in != NULL ||
options_in != NULL) {
/*
* Something matched. Allocate newargv, and store
* values found in options_in.
*/
strcpy(buffer, options_in);
c = argc_count(buffer) + 2;
*newargv = calloc(c, sizeof(**newargv));
if (!*newargv) {
retval = log_oom();
} else {
*argc = c;
c = 0;
/*
* argv[0] at 0 is skipped by getopt, but
* store the buffer address there for
* later freeing
*/
(*newargv)[c] = buffer;
for (c = 1; c < *argc; c++)
(*newargv)[c] = strsep(&buffer, " \t");
}
} else {
/* No matches */
retval = 1;
}
}
if (retval != 0)
free(buffer);
fclose(fd);
return retval;
}
static int set_options(struct udev *udev,
int argc, char **argv, const char *short_opts,
char *maj_min_dev)
{
int option;
/*
* optind is a global extern used by getopt. Since we can call
* set_options twice (once for command line, and once for config
* file) we have to reset this back to 1.
*/
optind = 1;
while (1) {
option = getopt_long(argc, argv, short_opts, options, NULL);
if (option == -1)
break;
switch (option) {
case 'b':
all_good = 0;
break;
case 'd':
dev_specified = 1;
strscpy(maj_min_dev, MAX_PATH_LEN, optarg);
break;
case 'e':
use_stderr = 1;
break;
case 'f':
strscpy(config_file, MAX_PATH_LEN, optarg);
break;
case 'g':
all_good = 1;
break;
case 'h':
printf("Usage: scsi_id OPTIONS <device>\n"
" --device= device node for SG_IO commands\n"
" --config= location of config file\n"
" --page=0x80|0x83|pre-spc3-83 SCSI page (0x80, 0x83, pre-spc3-83)\n"
" --sg-version=3|4 use SGv3 or SGv4\n"
" --blacklisted threat device as blacklisted\n"
" --whitelisted threat device as whitelisted\n"
" --replace-whitespace replace all whitespaces by underscores\n"
" --verbose verbose logging\n"
" --version print version\n"
" --export print values as environment keys\n"
" --help print this help text\n\n");
exit(0);
case 'p':
if (strcmp(optarg, "0x80") == 0) {
default_page_code = PAGE_80;
} else if (strcmp(optarg, "0x83") == 0) {
default_page_code = PAGE_83;
} else if (strcmp(optarg, "pre-spc3-83") == 0) {
default_page_code = PAGE_83_PRE_SPC3;
} else {
log_error("Unknown page code '%s'\n", optarg);
return -1;
}
break;
case 's':
sg_version = atoi(optarg);
if (sg_version < 3 || sg_version > 4) {
log_error("Unknown SG version '%s'\n", optarg);
return -1;
}
break;
case 'u':
reformat_serial = 1;
break;
case 'x':
export = 1;
break;
case 'v':
debug++;
break;
case 'V':
printf("%s\n", VERSION);
exit(0);
break;
default:
exit(1);
}
}
if (optind < argc && !dev_specified) {
dev_specified = 1;
strscpy(maj_min_dev, MAX_PATH_LEN, argv[optind]);
}
return 0;
}
static int per_dev_options(struct udev *udev,
struct scsi_id_device *dev_scsi, int *good_bad, int *page_code)
{
int retval;
int newargc;
char **newargv = NULL;
int option;
*good_bad = all_good;
*page_code = default_page_code;
retval = get_file_options(udev, vendor_str, model_str, &newargc, &newargv);
optind = 1; /* reset this global extern */
while (retval == 0) {
option = getopt_long(newargc, newargv, dev_short_options, options, NULL);
if (option == -1)
break;
switch (option) {
case 'b':
*good_bad = 0;
break;
case 'g':
*good_bad = 1;
break;
case 'p':
if (strcmp(optarg, "0x80") == 0) {
*page_code = PAGE_80;
} else if (strcmp(optarg, "0x83") == 0) {
*page_code = PAGE_83;
} else if (strcmp(optarg, "pre-spc3-83") == 0) {
*page_code = PAGE_83_PRE_SPC3;
} else {
log_error("Unknown page code '%s'\n", optarg);
retval = -1;
}
break;
default:
log_error("Unknown or bad option '%c' (0x%x)\n", option, option);
retval = -1;
break;
}
}
if (newargv) {
free(newargv[0]);
free(newargv);
}
return retval;
}
static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, const char *path)
{
int retval;
dev_scsi->use_sg = sg_version;
retval = scsi_std_inquiry(udev, dev_scsi, path);
if (retval)
return retval;
udev_util_encode_string(dev_scsi->vendor, vendor_enc_str, sizeof(vendor_enc_str));
udev_util_encode_string(dev_scsi->model, model_enc_str, sizeof(model_enc_str));
util_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str));
util_replace_chars(vendor_str, NULL);
util_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str));
util_replace_chars(model_str, NULL);
set_type(dev_scsi->type, type_str, sizeof(type_str));
util_replace_whitespace(dev_scsi->revision, revision_str, sizeof(revision_str));
util_replace_chars(revision_str, NULL);
return 0;
}
/*
* scsi_id: try to get an id, if one is found, printf it to stdout.
* returns a value passed to exit() - 0 if printed an id, else 1.
*/
static int scsi_id(struct udev *udev, char *maj_min_dev)
{
struct scsi_id_device dev_scsi;
int good_dev;
int page_code;
int retval = 0;
memset(&dev_scsi, 0x00, sizeof(struct scsi_id_device));
if (set_inq_values(udev, &dev_scsi, maj_min_dev) < 0) {
retval = 1;
goto out;
}
/* get per device (vendor + model) options from the config file */
per_dev_options(udev, &dev_scsi, &good_dev, &page_code);
if (!good_dev) {
retval = 1;
goto out;
}
/* read serial number from mode pages (no values for optical drives) */
scsi_get_serial(udev, &dev_scsi, maj_min_dev, page_code, MAX_SERIAL_LEN);
if (export) {
char serial_str[MAX_SERIAL_LEN];
printf("ID_SCSI=1\n");
printf("ID_VENDOR=%s\n", vendor_str);
printf("ID_VENDOR_ENC=%s\n", vendor_enc_str);
printf("ID_MODEL=%s\n", model_str);
printf("ID_MODEL_ENC=%s\n", model_enc_str);
printf("ID_REVISION=%s\n", revision_str);
printf("ID_TYPE=%s\n", type_str);
if (dev_scsi.serial[0] != '\0') {
util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
util_replace_chars(serial_str, NULL);
printf("ID_SERIAL=%s\n", serial_str);
util_replace_whitespace(dev_scsi.serial_short, serial_str, sizeof(serial_str));
util_replace_chars(serial_str, NULL);
printf("ID_SERIAL_SHORT=%s\n", serial_str);
}
if (dev_scsi.wwn[0] != '\0') {
printf("ID_WWN=0x%s\n", dev_scsi.wwn);
if (dev_scsi.wwn_vendor_extension[0] != '\0') {
printf("ID_WWN_VENDOR_EXTENSION=0x%s\n", dev_scsi.wwn_vendor_extension);
printf("ID_WWN_WITH_EXTENSION=0x%s%s\n", dev_scsi.wwn, dev_scsi.wwn_vendor_extension);
} else {
printf("ID_WWN_WITH_EXTENSION=0x%s\n", dev_scsi.wwn);
}
}
if (dev_scsi.tgpt_group[0] != '\0') {
printf("ID_TARGET_PORT=%s\n", dev_scsi.tgpt_group);
}
if (dev_scsi.unit_serial_number[0] != '\0') {
printf("ID_SCSI_SERIAL=%s\n", dev_scsi.unit_serial_number);
}
goto out;
}
if (dev_scsi.serial[0] == '\0') {
retval = 1;
goto out;
}
if (reformat_serial) {
char serial_str[MAX_SERIAL_LEN];
util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str));
util_replace_chars(serial_str, NULL);
printf("%s\n", serial_str);
goto out;
}
printf("%s\n", dev_scsi.serial);
out:
return retval;
}
int main(int argc, char **argv)
{
struct udev *udev;
int retval = 0;
char maj_min_dev[MAX_PATH_LEN];
int newargc;
char **newargv;
udev = udev_new();
if (udev == NULL)
goto exit;
log_open();
udev_set_log_fn(udev, log_fn);
/*
* Get config file options.
*/
newargv = NULL;
retval = get_file_options(udev, NULL, NULL, &newargc, &newargv);
if (retval < 0) {
retval = 1;
goto exit;
}
if (newargv && (retval == 0)) {
if (set_options(udev, newargc, newargv, short_options, maj_min_dev) < 0) {
retval = 2;
goto exit;
}
free(newargv);
}
/*
* Get command line options (overriding any config file settings).
*/
if (set_options(udev, argc, argv, short_options, maj_min_dev) < 0)
exit(1);
if (!dev_specified) {
log_error("no device specified\n");
retval = 1;
goto exit;
}
retval = scsi_id(udev, maj_min_dev);
exit:
udev_unref(udev);
log_close();
return retval;
}