chiark / gitweb /
man: fix name of systemd.journal-fields(7)
[elogind.git] / src / udev / scsi_id / scsi_id.c
index 03bd3a9182f3efc6aeb4d95222cf3cd72df0e9d8..a1b8e75facab719c6a9f13d599a05e078fed47eb 100644 (file)
@@ -25,7 +25,6 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
-#include <syslog.h>
 #include <ctype.h>
 #include <getopt.h>
 #include <sys/stat.h>
@@ -55,7 +54,6 @@ static bool dev_specified = false;
 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];
@@ -65,14 +63,6 @@ static char model_enc_str[256];
 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;
@@ -184,7 +174,7 @@ static int get_file_options(struct udev *udev,
                 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;
                 }
         }
@@ -314,18 +304,20 @@ static int get_file_options(struct udev *udev,
 }
 
 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);
 
 }
 
@@ -390,13 +382,14 @@ static int set_options(struct udev *udev,
                         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;
@@ -584,13 +577,13 @@ int main(int argc, char **argv)
         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.
          */
@@ -615,7 +608,7 @@ int main(int argc, char **argv)
                 exit(1);
 
         if (!dev_specified) {
-                log_error("no device specified");
+                log_error("No device specified.");
                 retval = 1;
                 goto exit;
         }