daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From e819659256d139cd5faebb5c0ca3ad4ad95ccb27 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Sat, 21 Mar 2015 11:31:16 -0400
Subject: [PATCH] fstab-generator: ignore invalid swap priority

A failed priority is not something worth stopping boot over. Most people
have only one swap device, in which case priority is irrelevant, and even
if there is more than one swap device, they are all usable, and ignoring the
priority field should only result in some loss of performance.

The kernel will report the priority as -1 if not set, so it's easy for
people to make this mistake.

https://bugzilla.redhat.com/show_bug.cgi?id=1204336
(cherry picked from commit e0952d9d021234e79f3a70f33a9e5d201872a417)
---
 src/fstab-generator/fstab-generator.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 5662b5fde1..8e2f522bd0 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -54,9 +54,10 @@ static int add_swap(
                 bool noauto,
                 bool nofail) {
 
-        _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
+        _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *filtered = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         int r, pri = -1;
+        const char *opts;
 
         assert(what);
         assert(me);
@@ -71,9 +72,17 @@ static int add_swap(
                 return 0;
         }
 
-        r = fstab_find_pri(me->mnt_opts, &pri);
-        if (r < 0)
-                return log_error_errno(r, "Failed to parse priority: %m");
+        opts = me->mnt_opts;
+        r = fstab_find_pri(opts, &pri);
+        if (r < 0) {
+                log_error_errno(r, "Failed to parse priority, ignoring: %m");
+
+                /* Remove invalid pri field */
+                r = fstab_filter_options(opts, "pri\0", NULL, NULL, &filtered);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse options: %m");
+                opts = filtered;
+        }
 
         name = unit_name_from_path(what, ".swap");
         if (!name)
@@ -106,15 +115,15 @@ static int add_swap(
         if (pri >= 0)
                 fprintf(f, "Priority=%i\n", pri);
 
-        if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults"))
-                fprintf(f, "Options=%s\n", me->mnt_opts);
+        if (!isempty(opts) && !streq(opts, "defaults"))
+                fprintf(f, "Options=%s\n", opts);
 
         r = fflush_and_check(f);
         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);
+        r = generator_write_timeouts(arg_dest, what, what, opts, NULL);
         if (r < 0)
                 return r;