chiark / gitweb /
treewide: use log_*_errno whenever %m is in the format string
[elogind.git] / src / fstab-generator / fstab-generator.c
index 94cbc3a5fe8f64d7c9e4d7fd63420e0782ccc8d6..1c85a729b82093392dbf85608b704de24a558488 100644 (file)
@@ -74,11 +74,14 @@ static int mount_find_pri(struct mntent *me, int *ret) {
         return 1;
 }
 
-static int add_swap(const char *what, struct mntent *me) {
+static int add_swap(
+                const char *what,
+                struct mntent *me,
+                bool noauto,
+                bool nofail) {
+
         _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-
-        bool noauto;
         int r, pri = -1;
 
         assert(what);
@@ -95,8 +98,6 @@ static int add_swap(const char *what, struct mntent *me) {
                 return r;
         }
 
-        noauto = !!hasmntopt(me, "noauto");
-
         name = unit_name_from_path(what, ".swap");
         if (!name)
                 return log_oom();
@@ -110,7 +111,7 @@ static int add_swap(const char *what, struct mntent *me) {
                 if (errno == EEXIST)
                         log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
                 else
-                        log_error("Failed to create unit file %s: %m", unit);
+                        log_error_errno(errno, "Failed to create unit file %s: %m", unit);
                 return -errno;
         }
 
@@ -132,10 +133,8 @@ static int add_swap(const char *what, struct mntent *me) {
                 fprintf(f, "Options=%s\n", me->mnt_opts);
 
         r = fflush_and_check(f);
-        if (r < 0) {
-                log_error("Failed to write unit file %s: %s", unit, strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to write unit file %s: %m", unit);
 
         /* use what as where, to have a nicer error message */
         r = generator_write_timeouts(arg_dest, what, what, me->mnt_opts, NULL);
@@ -143,13 +142,14 @@ static int add_swap(const char *what, struct mntent *me) {
                 return r;
 
         if (!noauto) {
-                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
+                lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET,
+                              nofail ? ".wants/" : ".requires/", name, NULL);
                 if (!lnk)
                         return log_oom();
 
                 mkdir_parents_label(lnk, 0755);
                 if (symlink(unit, lnk) < 0) {
-                        log_error("Failed to create symlink %s: %m", lnk);
+                        log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
                         return -errno;
                 }
         }
@@ -229,7 +229,7 @@ static int add_mount(
                 if (errno == EEXIST)
                         log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
                 else
-                        log_error("Failed to create unit file %s: %m", unit);
+                        log_error_errno(errno, "Failed to create unit file %s: %m", unit);
                 return -errno;
         }
 
@@ -269,7 +269,7 @@ static int add_mount(
 
         fflush(f);
         if (ferror(f)) {
-                log_error("Failed to write unit file %s: %m", unit);
+                log_error_errno(errno, "Failed to write unit file %s: %m", unit);
                 return -errno;
         }
 
@@ -280,7 +280,7 @@ static int add_mount(
 
                 mkdir_parents_label(lnk, 0755);
                 if (symlink(unit, lnk) < 0) {
-                        log_error("Failed to create symlink %s: %m", lnk);
+                        log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
                         return -errno;
                 }
         }
@@ -297,7 +297,7 @@ static int add_mount(
                 fclose(f);
                 f = fopen(automount_unit, "wxe");
                 if (!f) {
-                        log_error("Failed to create unit file %s: %m", automount_unit);
+                        log_error_errno(errno, "Failed to create unit file %s: %m", automount_unit);
                         return -errno;
                 }
 
@@ -320,7 +320,7 @@ static int add_mount(
 
                 fflush(f);
                 if (ferror(f)) {
-                        log_error("Failed to write unit file %s: %m", automount_unit);
+                        log_error_errno(errno, "Failed to write unit file %s: %m", automount_unit);
                         return -errno;
                 }
 
@@ -331,7 +331,7 @@ static int add_mount(
 
                 mkdir_parents_label(lnk, 0755);
                 if (symlink(automount_unit, lnk) < 0) {
-                        log_error("Failed to create symlink %s: %m", lnk);
+                        log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
                         return -errno;
                 }
         }
@@ -351,12 +351,13 @@ static int parse_fstab(bool initrd) {
                 if (errno == ENOENT)
                         return 0;
 
-                log_error("Failed to open %s: %m", fstab_path);
+                log_error_errno(errno, "Failed to open %s: %m", fstab_path);
                 return -errno;
         }
 
         while ((me = getmntent(f))) {
                 _cleanup_free_ char *where = NULL, *what = NULL;
+                bool noauto, nofail;
                 int k;
 
                 if (initrd && !mount_in_initrd(me))
@@ -378,16 +379,18 @@ static int parse_fstab(bool initrd) {
                 if (is_path(where))
                         path_kill_slashes(where);
 
-                log_debug("Found entry what=%s where=%s type=%s", what, where, me->mnt_type);
+                noauto = !!hasmntopt(me, "noauto");
+                nofail = !!hasmntopt(me, "nofail");
+                log_debug("Found entry what=%s where=%s type=%s nofail=%s noauto=%s",
+                          what, where, me->mnt_type,
+                          yes_no(noauto), yes_no(nofail));
 
                 if (streq(me->mnt_type, "swap"))
-                        k = add_swap(what, me);
+                        k = add_swap(what, me, noauto, nofail);
                 else {
-                        bool noauto, nofail, automount;
+                        bool automount;
                         const char *post;
 
-                        noauto = !!hasmntopt(me, "noauto");
-                        nofail = !!hasmntopt(me, "nofail");
                         automount =
                                   hasmntopt(me, "comment=systemd.automount") ||
                                   hasmntopt(me, "x-systemd.automount");
@@ -593,8 +596,9 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        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");
 
         /* Always honour root= and usr= in the kernel command line if we are in an initrd */
         if (in_initrd()) {