chiark / gitweb /
treewide: more log_*_errno + return simplifications
[elogind.git] / src / gpt-auto-generator / gpt-auto-generator.c
index 4927919b81d5d3c446ba535998dc66d352a4a91e..0e935b30b9707f4fae1cd439a88d0118ac064dc7 100644 (file)
@@ -124,7 +124,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
                 return log_oom();
 
         p = strjoin(arg_dest, "/", n, NULL);
-        if (!n)
+        if (!p)
                 return log_oom();
 
         f = fopen(p, "wxe");
@@ -144,7 +144,6 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
                 "Before=umount.target cryptsetup.target\n"
                 "After=%s\n"
                 "IgnoreOnIsolate=true\n"
-                "After=systemd-readahead-collect.service systemd-readahead-replay.service\n\n"
                 "[Service]\n"
                 "Type=oneshot\n"
                 "RemainAfterExit=yes\n"
@@ -205,10 +204,8 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
                         "# Automatically generated by systemd-gpt-auto-generator\n\n"
                         "[Unit]\n"
                         "JobTimeoutSec=0\n"); /* the binary handles timeouts anyway */
-        if (r < 0) {
-                log_error("Failed to write device drop-in: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to write device drop-in: %m");
 
         ret = strappend("/dev/mapper/", id);
         if (!ret)
@@ -436,8 +433,6 @@ static int enumerate_partitions(dev_t devnum) {
                 return -errno;
         }
 
-        blkid_probe_enable_superblocks(b, 1);
-        blkid_probe_set_superblocks_flags(b, BLKID_SUBLKS_TYPE);
         blkid_probe_enable_partitions(b, 1);
         blkid_probe_set_partitions_flags(b, BLKID_PARTS_ENTRY_DETAILS);
 
@@ -490,10 +485,8 @@ static int enumerate_partitions(dev_t devnum) {
                 return log_oom();
 
         r = udev_enumerate_scan_devices(e);
-        if (r < 0) {
-                log_error("Failed to enumerate partitions on %s: %s", node, strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to enumerate partitions on %s: %m", node);
 
         first = udev_enumerate_get_list_entry(e);
         udev_list_entry_foreach(item, first) {
@@ -683,8 +676,8 @@ 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);
-
-                arg_enabled = r;
+                else
+                        arg_enabled = r;
 
         } else if (streq(key, "root") && value) {
 
@@ -697,8 +690,6 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
                 arg_root_rw = true;
         else if (streq(key, "ro") && !value)
                 arg_root_rw = false;
-        else if (startswith(key, "systemd.gpt-auto.") || startswith(key, "rd.systemd.gpt-auto."))
-                log_warning("Unknown kernel switch %s. Ignoring.", key);
 
         return 0;
 }
@@ -717,10 +708,8 @@ static int add_root_mount(void) {
         if (r == -ENOENT) {
                 log_debug("EFI loader partition unknown, exiting.");
                 return 0;
-        } else if (r < 0) {
-                log_error("Failed to read ESP partition UUID: %s", strerror(-r));
-                return r;
-        }
+        } else if (r < 0)
+                return log_error_errno(r, "Failed to read ESP partition UUID: %m");
 
         /* OK, we have an ESP partition, this is fantastic, so let's
          * wait for a root device to show up. A udev rule will create
@@ -744,10 +733,9 @@ static int add_mounts(void) {
         int r;
 
         r = get_block_device("/", &devno);
-        if (r < 0) {
-                log_error("Failed to determine block device of root file system: %s", strerror(-r));
-                return r;
-        } else if (r == 0) {
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine block device of root file system: %m");
+        else if (r == 0) {
                 log_debug("Root file system not on a (single) block device.");
                 return 0;
         }
@@ -777,8 +765,9 @@ int main(int argc, char *argv[]) {
                 return EXIT_SUCCESS;
         }
 
-        if (parse_proc_cmdline(parse_proc_cmdline_item) < 0)
-                return EXIT_FAILURE;
+        r = parse_proc_cmdline(parse_proc_cmdline_item);
+        if (r < 0)
+                log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
 
         if (!arg_enabled) {
                 log_debug("Disabled, exiting.");