valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone
923a60
From e819659256d139cd5faebb5c0ca3ad4ad95ccb27 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 21 Mar 2015 11:31:16 -0400
923a60
Subject: [PATCH] fstab-generator: ignore invalid swap priority
923a60
923a60
A failed priority is not something worth stopping boot over. Most people
923a60
have only one swap device, in which case priority is irrelevant, and even
923a60
if there is more than one swap device, they are all usable, and ignoring the
923a60
priority field should only result in some loss of performance.
923a60
923a60
The kernel will report the priority as -1 if not set, so it's easy for
923a60
people to make this mistake.
923a60
923a60
https://bugzilla.redhat.com/show_bug.cgi?id=1204336
923a60
(cherry picked from commit e0952d9d021234e79f3a70f33a9e5d201872a417)
923a60
---
923a60
 src/fstab-generator/fstab-generator.c | 23 ++++++++++++++++-------
923a60
 1 file changed, 16 insertions(+), 7 deletions(-)
923a60
923a60
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
923a60
index 5662b5fde1..8e2f522bd0 100644
923a60
--- a/src/fstab-generator/fstab-generator.c
923a60
+++ b/src/fstab-generator/fstab-generator.c
923a60
@@ -54,9 +54,10 @@ static int add_swap(
923a60
                 bool noauto,
923a60
                 bool nofail) {
923a60
 
923a60
-        _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
923a60
+        _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *filtered = NULL;
923a60
         _cleanup_fclose_ FILE *f = NULL;
923a60
         int r, pri = -1;
923a60
+        const char *opts;
923a60
 
923a60
         assert(what);
923a60
         assert(me);
923a60
@@ -71,9 +72,17 @@ static int add_swap(
923a60
                 return 0;
923a60
         }
923a60
 
923a60
-        r = fstab_find_pri(me->mnt_opts, &pri);
923a60
-        if (r < 0)
923a60
-                return log_error_errno(r, "Failed to parse priority: %m");
923a60
+        opts = me->mnt_opts;
923a60
+        r = fstab_find_pri(opts, &pri);
923a60
+        if (r < 0) {
923a60
+                log_error_errno(r, "Failed to parse priority, ignoring: %m");
923a60
+
923a60
+                /* Remove invalid pri field */
923a60
+                r = fstab_filter_options(opts, "pri\0", NULL, NULL, &filtered);
923a60
+                if (r < 0)
923a60
+                        return log_error_errno(r, "Failed to parse options: %m");
923a60
+                opts = filtered;
923a60
+        }
923a60
 
923a60
         name = unit_name_from_path(what, ".swap");
923a60
         if (!name)
923a60
@@ -106,15 +115,15 @@ static int add_swap(
923a60
         if (pri >= 0)
923a60
                 fprintf(f, "Priority=%i\n", pri);
923a60
 
923a60
-        if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults"))
923a60
-                fprintf(f, "Options=%s\n", me->mnt_opts);
923a60
+        if (!isempty(opts) && !streq(opts, "defaults"))
923a60
+                fprintf(f, "Options=%s\n", opts);
923a60
 
923a60
         r = fflush_and_check(f);
923a60
         if (r < 0)
923a60
                 return log_error_errno(r, "Failed to write unit file %s: %m", unit);
923a60
 
923a60
         /* use what as where, to have a nicer error message */
923a60
-        r = generator_write_timeouts(arg_dest, what, what, me->mnt_opts, NULL);
923a60
+        r = generator_write_timeouts(arg_dest, what, what, opts, NULL);
923a60
         if (r < 0)
923a60
                 return r;
923a60