Skip to content

Commit

Permalink
fstab-generator: call add_swap() earlier
Browse files Browse the repository at this point in the history
As 'where' field will be ignored for swap entry.

(cherry picked from commit 256604ccddd41a16de329ff792c5f49d6750e510)

Related: #2190228
  • Loading branch information
yuwata authored and dtardon committed Jul 18, 2023
1 parent 0bbebc5 commit a0d1a65
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/fstab-generator/fstab-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ static int add_swap(
return 0;
}


log_debug("Found swap entry what=%s makefs=%s growfs=%s noauto=%s nofail=%s",
what,
yes_no(flags & MAKEFS), yes_no(flags & GROWFS),
yes_no(flags & NOAUTO), yes_no(flags & NOFAIL));

r = unit_name_from_path(what, ".swap", &name);
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
Expand Down Expand Up @@ -530,16 +536,18 @@ static int parse_fstab_one(
_cleanup_free_ char *where = NULL, *what = NULL, *canonical_where = NULL;
const char *post;
MountpointFlags flags;
bool is_swap;
int r;

assert(what_original);
assert(where_original);
assert(fstype);
assert(options);

if (initrd && !mount_in_initrd(where_original, options))
return 0;

is_swap = streq_ptr(fstype, "swap");

what = fstab_node_to_udev_node(what_original);
if (!what)
return log_oom();
Expand All @@ -549,6 +557,13 @@ static int parse_fstab_one(
return 0;
}

flags = fstab_options_to_flags(options, is_swap);

if (is_swap)
return add_swap(what, options, flags);

assert(where_original); /* 'where' is not necessary for swap entry. */

where = strdup(where_original);
if (!where)
return log_oom();
Expand All @@ -572,16 +587,11 @@ static int parse_fstab_one(
log_debug("Canonicalized what=%s where=%s to %s", what, where, canonical_where);
}

flags = fstab_options_to_flags(options, streq_ptr(fstype, "swap"));

log_debug("Found entry what=%s where=%s type=%s makefs=%s noauto=%s nofail=%s",
what, where, strna(fstype),
yes_no(flags & MAKEFS),
yes_no(flags & NOAUTO), yes_no(flags & NOFAIL));

if (streq(fstype, "swap"))
return add_swap(what, options, flags);

if (initrd)
post = SPECIAL_INITRD_FS_TARGET;
else if (mount_is_network(fstype, options))
Expand Down

0 comments on commit a0d1a65

Please sign in to comment.