#include <fcntl.h>
#include <errno.h>
#include <string.h>
-#include <syslog.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/stat.h>
static char config_file[MAX_PATH_LEN] = "/etc/scsi_id.config";
static enum page_code default_page_code = PAGE_UNSPECIFIED;
static int sg_version = 4;
-static int debug = 0;
static bool reformat_serial = false;
static bool export = false;
static char vendor_str[64];
static char revision_str[16];
static char type_str[16];
-_printf_(6,0)
-static void log_fn(struct udev *udev, int priority,
- const char *file, int line, const char *fn,
- const char *format, va_list args)
-{
- vsyslog(priority, format, args);
-}
-
static void set_type(const char *from, char *to, size_t len)
{
int type_num;
if (errno == ENOENT)
return 1;
else {
- log_error("can't open %s: %m", config_file);
+ log_error_errno(errno, "can't open %s: %m", config_file);
return -1;
}
}
}
static void help(void) {
- printf("Usage: scsi_id [OPTION...] DEVICE\n"
- " -d,--device= device node for SG_IO commands\n"
- " -f,--config= location of config file\n"
- " -p,--page=0x80|0x83|pre-spc3-83 SCSI page (0x80, 0x83, pre-spc3-83)\n"
- " -s,--sg-version=3|4 use SGv3 or SGv4\n"
- " -b,--blacklisted threat device as blacklisted\n"
- " -g,--whitelisted threat device as whitelisted\n"
- " -u,--replace-whitespace replace all whitespace by underscores\n"
- " -v,--verbose verbose logging\n"
- " --version print version\n"
- " -x,--export print values as environment keys\n"
- " -h,--help print this help text\n\n");
+ printf("Usage: %s [OPTION...] DEVICE\n\n"
+ "SCSI device identification.\n\n"
+ " -h --help Print this message\n"
+ " --version Print version of the program\n\n"
+ " -d --device= Device node for SG_IO commands\n"
+ " -f --config= Location of config file\n"
+ " -p --page=0x80|0x83|pre-spc3-83 SCSI page (0x80, 0x83, pre-spc3-83)\n"
+ " -s --sg-version=3|4 Use SGv3 or SGv4\n"
+ " -b --blacklisted Treat device as blacklisted\n"
+ " -g --whitelisted Treat device as whitelisted\n"
+ " -u --replace-whitespace Replace all whitespace by underscores\n"
+ " -v --verbose Verbose logging\n"
+ " -x --export Print values as environment keys\n"
+ , program_invocation_short_name);
}
break;
case 'v':
- debug++;
+ log_set_target(LOG_TARGET_CONSOLE);
+ log_set_max_level(LOG_DEBUG);
+ log_open();
break;
case 'V':
printf("%s\n", VERSION);
exit(0);
- break;
case 'x':
export = true;
int newargc;
char **newargv = NULL;
+ log_parse_environment();
+ log_open();
+
udev = udev_new();
if (udev == NULL)
goto exit;
- log_open();
- udev_set_log_fn(udev, log_fn);
-
/*
* Get config file options.
*/
exit(1);
if (!dev_specified) {
- log_error("no device specified");
+ log_error("No device specified.");
retval = 1;
goto exit;
}