chiark / gitweb /
udev: switch to systemd logging functions
[elogind.git] / src / udev / cdrom_id / cdrom_id.c
index 93467c2d35b0b95734570536dd8cb996f9ed8e85..48ceb657e071a025386970f1e2e637ade11e36f6 100644 (file)
 #include "libudev.h"
 #include "libudev-private.h"
 
-static bool debug;
-
-_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)
-{
-        if (debug) {
-                fprintf(stderr, "%s: ", fn);
-                vfprintf(stderr, format, args);
-        } else {
-                vsyslog(priority, format, args);
-        }
-}
-
 /* device info */
 static unsigned int cd_cd_rom;
 static unsigned int cd_cd_r;
@@ -556,7 +541,7 @@ static int cd_profiles(struct udev *udev, int fd)
         if ((err != 0)) {
                 info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
                 /* handle pre-MMC2 drives which do not support GET CONFIGURATION */
-                if (SK(err) == 0x5 && ASC(err) == 0x20) {
+                if (SK(err) == 0x5 && (ASC(err) == 0x20 || ASC(err) == 0x24)) {
                         log_debug("drive is pre-MMC2 and does not support 46h get configuration command");
                         log_debug("trying to work around the problem");
                         ret = cd_profiles_old_mmc(udev, fd);
@@ -613,7 +598,7 @@ static int cd_profiles(struct udev *udev, int fd)
                 switch (feature) {
                 case 0x00:
                         log_debug("GET CONFIGURATION: feature 'profiles', with %i entries", features[i+3] / 4);
-                        feature_profiles(udev, &features[i]+4, features[i+3]);
+                        feature_profiles(udev, &features[i]+4, MIN(features[i+3], len - i - 4));
                         break;
                 default:
                         log_debug("GET CONFIGURATION: feature 0x%04x <ignored>, with 0x%02x bytes", feature, features[i+3]);
@@ -875,13 +860,13 @@ int main(int argc, char *argv[])
         int cnt;
         int rc = 0;
 
+        log_parse_environment();
+        log_open();
+
         udev = udev_new();
         if (udev == NULL)
                 goto exit;
 
-        log_open();
-        udev_set_log_fn(udev, log_fn);
-
         while (1) {
                 int option;
 
@@ -900,9 +885,9 @@ int main(int argc, char *argv[])
                         eject = true;
                         break;
                 case 'd':
-                        debug = true;
+                        log_set_target(LOG_TARGET_CONSOLE);
                         log_set_max_level(LOG_DEBUG);
-                        udev_set_log_priority(udev, LOG_DEBUG);
+                        log_open();
                         break;
                 case 'h':
                         printf("Usage: cdrom_id [options] <device>\n"
@@ -926,7 +911,7 @@ int main(int argc, char *argv[])
                 goto exit;
         }
 
-        srand((unsigned int)getpid());
+        initialize_srand();
         for (cnt = 20; cnt > 0; cnt--) {
                 struct timespec duration;