chiark / gitweb /
gpt-auto-generator: prefix messages with device name
[elogind.git] / src / gpt-auto-generator / gpt-auto-generator.c
index 9f2da79e2c354dc9780fcadebd658dee639a5f45..99dc50fe3c3aa3cfe6159a9f25d8755cd594f0b2 100644 (file)
@@ -346,7 +346,7 @@ static int enumerate_partitions(dev_t devnum) {
         _cleanup_free_ char *home = NULL, *srv = NULL;
         struct udev_list_entry *first, *item;
         struct udev_device *parent = NULL;
-        const char *node, *pttype, *devtype;
+        const char *name, *node, *pttype, *devtype;
         int home_nr = -1, srv_nr = -1;
         bool home_rw = true, srv_rw = true;
         blkid_partlist pl;
@@ -361,33 +361,42 @@ static int enumerate_partitions(dev_t devnum) {
         if (!d)
                 return log_oom();
 
+        name = udev_device_get_devnode(d);
+        if (!name)
+                name = udev_device_get_syspath(d);
+        if (!name) {
+                log_debug("Device %u:%u does not have a name, ignoring.",
+                          major(devnum), minor(devnum));
+                return 0;
+        }
+
         parent = udev_device_get_parent(d);
         if (!parent) {
-                log_debug("Not a partitioned device, ignoring.");
+                log_debug("%s: not a partitioned device, ignoring.", name);
                 return 0;
         }
 
         /* Does it have a devtype? */
         devtype = udev_device_get_devtype(parent);
         if (!devtype) {
-                log_debug("Parent doesn't have a device type, ignoring.");
+                log_debug("%s: parent doesn't have a device type, ignoring.", name);
                 return 0;
         }
 
         /* Is this a disk or a partition? We only care for disks... */
         if (!streq(devtype, "disk")) {
-                log_debug("Parent isn't a raw disk, ignoring.");
+                log_debug("%s: parent isn't a raw disk, ignoring.", name);
                 return 0;
         }
 
         /* Does it have a device node? */
         node = udev_device_get_devnode(parent);
         if (!node) {
-                log_debug("Parent device does not have device node, ignoring.");
+                log_debug("%s: parent device does not have device node, ignoring.", name);
                 return 0;
         }
 
-        log_debug("Root device %s.", node);
+        log_debug("%s: root device %s.", name, node);
 
         pn = udev_device_get_devnum(parent);
         if (major(pn) == 0)
@@ -399,8 +408,7 @@ static int enumerate_partitions(dev_t devnum) {
                 if (errno == 0)
                         return log_oom();
 
-                log_error_errno(errno, "Failed allocate prober: %m");
-                return -errno;
+                return log_error_errno(errno, "%s: failed to allocate prober: %m", node);
         }
 
         blkid_probe_enable_partitions(b, 1);
@@ -410,25 +418,18 @@ static int enumerate_partitions(dev_t devnum) {
         r = blkid_do_safeprobe(b);
         if (r == -2 || r == 1) /* no result or uncertain */
                 return 0;
-        else if (r != 0) {
-                if (errno == 0)
-                        errno = EIO;
-                log_error_errno(errno, "Failed to probe %s: %m", node);
-                return -errno;
-        }
+        else if (r != 0)
+                return log_error_errno(errno ?: EIO, "%s: failed to probe: %m", node);
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PTTYPE", &pttype, NULL);
-        if (r != 0) {
-                if (errno == 0)
-                        errno = EIO;
-                log_error_errno(errno, "Failed to determine partition table type of %s: %m", node);
-                return -errno;
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO,
+                                       "%s: failed to determine partition table type: %m", node);
 
         /* We only do this all for GPT... */
         if (!streq_ptr(pttype, "gpt")) {
-                log_debug("Not a GPT partition table, ignoring.");
+                log_debug("%s: not a GPT partition table, ignoring.", node);
                 return 0;
         }
 
@@ -438,8 +439,7 @@ static int enumerate_partitions(dev_t devnum) {
                 if (errno == 0)
                         return log_oom();
 
-                log_error_errno(errno, "Failed to list partitions of %s: %m", node);
-                return -errno;
+                return log_error_errno(errno, "%s: failed to list partitions: %m", node);
         }
 
         e = udev_enumerate_new(udev);
@@ -456,7 +456,7 @@ static int enumerate_partitions(dev_t devnum) {
 
         r = udev_enumerate_scan_devices(e);
         if (r < 0)
-                return log_error_errno(r, "Failed to enumerate partitions on %s: %m", node);
+                return log_error_errno(r, "%s: failed to enumerate partitions: %m", node);
 
         first = udev_enumerate_get_list_entry(e);
         udev_list_entry_foreach(item, first) {
@@ -511,7 +511,7 @@ static int enumerate_partitions(dev_t devnum) {
                 if (sd_id128_equal(type_id, GPT_SWAP)) {
 
                         if (flags & GPT_FLAG_READ_ONLY) {
-                                log_debug("%s marked as read-only swap partition, which is bogus, ignoring.", subnode);
+                                log_debug("%s marked as read-only swap partition, which is bogus. Ignoring.", subnode);
                                 continue;
                         }
 
@@ -597,7 +597,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
 
                 r = parse_boolean(value);
                 if (r < 0)
-                        log_warning("Failed to parse gpt-auto switch %s. Ignoring.", value);
+                        log_warning("Failed to parse gpt-auto switch \"%s\". Ignoring.", value);
                 else
                         arg_enabled = r;