]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/cryptsetup/cryptsetup-generator.c
tree-wide: use mfree more
[thirdparty/systemd.git] / src / cryptsetup / cryptsetup-generator.c
index 27b2360d240fffddd5c604a44b2f66c71657ff2e..de0a3b6f9c19f1ca1cf372ef0b1e2af8af0fccf8 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
 ***/
 
 #include <errno.h>
-#include <string.h>
-#include <unistd.h>
 
+#include "alloc-util.h"
 #include "dropin.h"
+#include "fd-util.h"
 #include "fileio.h"
+#include "fstab-util.h"
 #include "generator.h"
 #include "hashmap.h"
 #include "log.h"
 #include "mkdir.h"
+#include "parse-util.h"
 #include "path-util.h"
-#include "fstab-util.h"
+#include "proc-cmdline.h"
+#include "string-util.h"
 #include "strv.h"
 #include "unit-name.h"
 #include "util.h"
@@ -81,9 +82,9 @@ static int create_disk(
         if (!e)
                 return log_oom();
 
-        n = unit_name_build("systemd-cryptsetup", e, ".service");
-        if (!n)
-                return log_oom();
+        r = unit_name_build("systemd-cryptsetup", e, ".service", &n);
+        if (r < 0)
+                return log_error_errno(r, "Failed to generate unit name: %m");
 
         p = strjoin(arg_dest, "/", n, NULL);
         if (!p)
@@ -93,9 +94,9 @@ static int create_disk(
         if (!u)
                 return log_oom();
 
-        d = unit_name_from_path(u, ".device");
-        if (!d)
-                return log_oom();
+        r = unit_name_from_path(u, ".device", &d);
+        if (r < 0)
+                return log_error_errno(r, "Failed to generate unit name: %m");
 
         f = fopen(p, "wxe");
         if (!f)
@@ -131,11 +132,11 @@ static int create_disk(
                         if (!path_equal(uu, "/dev/null")) {
 
                                 if (is_device_path(uu)) {
-                                        _cleanup_free_ char *dd;
+                                        _cleanup_free_ char *dd = NULL;
 
-                                        dd = unit_name_from_path(uu, ".device");
-                                        if (!dd)
-                                                return log_oom();
+                                        r = unit_name_from_path(uu, ".device", &dd);
+                                        if (r < 0)
+                                                return log_error_errno(r, "Failed to generate unit name: %m");
 
                                         fprintf(f, "After=%1$s\nRequires=%1$s\n", dd);
                                 } else
@@ -179,11 +180,11 @@ static int create_disk(
                         "ExecStartPost=/sbin/mkswap '/dev/mapper/%s'\n",
                         name);
 
-        fflush(f);
-        if (ferror(f))
-                return log_error_errno(errno, "Failed to write file %s: %m", p);
+        r = fflush_and_check(f);
+        if (r < 0)
+                return log_error_errno(r, "Failed to write file %s: %m", p);
 
-        from = strappenda("../", n);
+        from = strjoina("../", n);
 
         if (!noauto) {
 
@@ -263,16 +264,13 @@ static crypto_device *get_crypto_device(const char *uuid) {
                 d->keyfile = d->options = d->name = NULL;
 
                 d->uuid = strdup(uuid);
-                if (!d->uuid) {
-                        free(d);
-                        return NULL;
-                }
+                if (!d->uuid)
+                        return mfree(d);
 
                 r = hashmap_put(arg_disks, d->uuid, d);
                 if (r < 0) {
                         free(d->uuid);
-                        free(d);
-                        return NULL;
+                        return mfree(d);
                 }
         }
 
@@ -333,7 +331,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
                         free(d->keyfile);
                         d->keyfile = uuid_value;
                         uuid_value = NULL;
-                } else if (free_and_strdup(&arg_default_keyfile, value))
+                } else if (free_and_strdup(&arg_default_keyfile, value) < 0)
                         return log_oom();
 
         } else if (STR_IN_SET(key, "luks.name", "rd.luks.name") && value) {
@@ -377,13 +375,6 @@ static int add_crypttab_devices(void) {
                 return 0;
         }
 
-        /* If we readd support for specifying passphrases
-         * directly in crypttab we should upgrade the warning
-         * below, though possibly only if a passphrase is
-         * specified directly. */
-        if (st.st_mode & 0005)
-                log_debug("/etc/crypttab is world-readable. This is usually not a good idea.");
-
         for (;;) {
                 int r, k;
                 char line[LINE_MAX], *l, *uuid;