]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #5449 from keszybz/blkd-error-handling
authorMartin Pitt <martinpitt@users.noreply.github.com>
Sat, 25 Feb 2017 11:25:27 +0000 (12:25 +0100)
committerGitHub <noreply@github.com>
Sat, 25 Feb 2017 11:25:27 +0000 (12:25 +0100)
blkid error handling

src/boot/bootctl.c
src/shared/dissect-image.c
src/udev/udev-builtin-blkid.c

index 116608bbd3d17837fadcbaf4b9854b9334376c4d..155bf278b2e444072e05d60916070f9d3036e3fd 100644 (file)
@@ -125,12 +125,8 @@ static int verify_esp(
 
         errno = 0;
         b = blkid_new_probe_from_filename(t);
-        if (!b) {
-                if (errno == 0)
-                        return log_oom();
-
-                return log_error_errno(errno, "Failed to open file system \"%s\": %m", p);
-        }
+        if (!b)
+                return log_error_errno(errno ?: ENOMEM, "Failed to open file system \"%s\": %m", p);
 
         blkid_probe_enable_superblocks(b, 1);
         blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
@@ -145,17 +141,13 @@ static int verify_esp(
         } else if (r == 1) {
                 log_error("File system \"%s\" does not contain a label.", p);
                 return -ENODEV;
-        } else if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe file system \"%s\": %m", p);
-        }
+        } else if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe file system \"%s\": %m", p);
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "TYPE", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe file system type \"%s\": %m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe file system type \"%s\": %m", p);
         if (!streq(v, "vfat")) {
                 log_error("File system \"%s\" is not FAT.", p);
                 return -ENODEV;
@@ -163,10 +155,8 @@ static int verify_esp(
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PART_ENTRY_SCHEME", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe partition scheme \"%s\": %m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe partition scheme \"%s\": %m", p);
         if (!streq(v, "gpt")) {
                 log_error("File system \"%s\" is not on a GPT partition table.", p);
                 return -ENODEV;
@@ -174,10 +164,8 @@ static int verify_esp(
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PART_ENTRY_TYPE", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe partition type UUID \"%s\": %m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe partition type UUID \"%s\": %m", p);
         if (!streq(v, "c12a7328-f81f-11d2-ba4b-00a0c93ec93b")) {
                 log_error("File system \"%s\" has wrong type for an EFI System Partition (ESP).", p);
                 return -ENODEV;
@@ -185,10 +173,8 @@ static int verify_esp(
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PART_ENTRY_UUID", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe partition entry UUID \"%s\": %m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe partition entry UUID \"%s\": %m", p);
         r = sd_id128_from_string(v, &uuid);
         if (r < 0) {
                 log_error("Partition \"%s\" has invalid UUID \"%s\".", p, v);
@@ -197,30 +183,24 @@ static int verify_esp(
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PART_ENTRY_NUMBER", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe partition number \"%s\": m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe partition number \"%s\": m", p);
         r = safe_atou32(v, &part);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse PART_ENTRY_NUMBER field.");
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PART_ENTRY_OFFSET", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe partition offset \"%s\": %m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe partition offset \"%s\": %m", p);
         r = safe_atou64(v, &pstart);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse PART_ENTRY_OFFSET field.");
 
         errno = 0;
         r = blkid_probe_lookup_value(b, "PART_ENTRY_SIZE", &v, NULL);
-        if (r != 0) {
-                r = errno ? -errno : -EIO;
-                return log_error_errno(r, "Failed to probe partition size \"%s\": %m", p);
-        }
+        if (r != 0)
+                return log_error_errno(errno ?: EIO, "Failed to probe partition size \"%s\": %m", p);
         r = safe_atou64(v, &psize);
         if (r < 0)
                 return log_error_errno(r, "Failed to parse PART_ENTRY_SIZE field.");
index 410a7764ed7c638732074bdba084e1982ada11e5..39e724c51a7b9ea563b37cef44b28188e3ab03d7 100644 (file)
@@ -61,12 +61,8 @@ static int probe_filesystem(const char *node, char **ret_fstype) {
                 log_debug("Failed to identify any partition type on partition %s", node);
                 goto not_found;
         }
-        if (r != 0) {
-                if (errno == 0)
-                        return -EIO;
-
-                return -errno;
-        }
+        if (r != 0)
+                return -errno ?: -EIO;
 
         (void) blkid_probe_lookup_value(b, "TYPE", &fstype, NULL);
 
@@ -146,12 +142,8 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
 
         errno = 0;
         r = blkid_probe_set_device(b, fd, 0, 0);
-        if (r != 0) {
-                if (errno == 0)
-                        return -ENOMEM;
-
-                return -errno;
-        }
+        if (r != 0)
+                return -errno ?: -ENOMEM;
 
         if ((flags & DISSECT_IMAGE_GPT_ONLY) == 0) {
                 /* Look for file system superblocks, unless we only shall look for GPT partition tables */
@@ -168,12 +160,8 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
                 log_debug("Failed to identify any partition table.");
                 return -ENOPKG;
         }
-        if (r != 0) {
-                if (errno == 0)
-                        return -EIO;
-
-                return -errno;
-        }
+        if (r != 0)
+                return -errno ?: -EIO;
 
         m = new0(DissectedImage, 1);
         if (!m)
@@ -232,12 +220,8 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI
 
         errno = 0;
         pl = blkid_probe_get_partitions(b);
-        if (!pl) {
-                if (errno == 0)
-                        return -ENOMEM;
-
-                return -errno;
-        }
+        if (!pl)
+                return -errno ?: -ENOMEM;
 
         udev = udev_new();
         if (!udev)
index 3c58445836d08dab618d40904e0586858c1330fd..9037aa1304d68a3b31c626babf73b961715ee59d 100644 (file)
@@ -122,7 +122,7 @@ static int find_gpt_root(struct udev_device *dev, blkid_probe pr, bool test) {
         errno = 0;
         pl = blkid_probe_get_partitions(pr);
         if (!pl)
-                return errno > 0 ? -errno : -ENOMEM;
+                return -errno ?: -ENOMEM;
 
         nvals = blkid_partlist_numof_partitions(pl);
         for (i = 0; i < nvals; i++) {
@@ -193,7 +193,7 @@ static int probe_superblocks(blkid_probe pr) {
         int rc;
 
         if (fstat(blkid_probe_get_fd(pr), &st))
-                return -1;
+                return -errno;
 
         blkid_probe_enable_partitions(pr, 1);