1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-23 02:04:32 +03:00

fstab-generator: write main unit file first, drop-ins afterwards

We would start writing the main file, then write some drop-ins, then the rest
of the first file, and then some more stuff. This is a bit silly, let's write
out the main file in one go. This is easier to follow, and if something goes
wrong half-way, we don't end up with a half-written file.

Inspired by https://bugzilla.redhat.com/show_bug.cgi?id=2292626, where some
SELinux snafu prevents the generator from writing the drop-in. The correct fix
is to make SELinux not fail, but we can make our code more resilient too.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2024-06-19 18:20:43 +02:00
parent ae2bf016bc
commit 526298a8dd

View File

@ -589,6 +589,14 @@ static int add_mount(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
/* Write timeout dropin and get filtered options */
r = generator_write_timeouts(dest, what, where, opts, &filtered);
if (r < 0)
return r;
/* Write main fragment */
r = generator_open_unit_file(dest, source, name, &f);
if (r < 0)
return r;
@ -670,20 +678,6 @@ static int add_mount(
fprintf(f, "Type=%s\n", t);
}
r = generator_write_timeouts(dest, what, where, opts, &filtered);
if (r < 0)
return r;
r = generator_write_device_deps(dest, what, where, opts);
if (r < 0)
return r;
if (in_initrd() && path_equal(where, "/sysroot") && is_device_path(what)) {
r = generator_write_initrd_root_device_deps(dest, what);
if (r < 0)
return r;
}
r = write_mount_timeout(f, where, opts);
if (r < 0)
return r;
@ -699,6 +693,18 @@ static int add_mount(
if (r < 0)
return log_error_errno(r, "Failed to write unit file %s: %m", name);
/* Write other drop-ins */
r = generator_write_device_deps(dest, what, where, opts);
if (r < 0)
return r;
if (in_initrd() && path_equal(where, "/sysroot") && is_device_path(what)) {
r = generator_write_initrd_root_device_deps(dest, what);
if (r < 0)
return r;
}
if (flags & MOUNT_MAKEFS) {
r = generator_hook_up_mkfs(dest, what, where, fstype);
if (r < 0)