diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-12-01 12:32:45 +0100 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-12-11 17:34:32 +0100 |
commit | 39a4c452d2ab1de2779061f2a81c7b5ff59addd0 (patch) | |
tree | 1a22da15a7f450c79f6e1f10baad9a3712386b6c /src/fstab-generator | |
parent | man/systemd.mount: update implicit deps on device unit (diff) | |
download | systemd-39a4c452d2ab1de2779061f2a81c7b5ff59addd0.tar.xz systemd-39a4c452d2ab1de2779061f2a81c7b5ff59addd0.zip |
fstab-generator: disable default deps if x-systemd.{wanted,required}-by= is used
Fixes #30273
Diffstat (limited to 'src/fstab-generator')
-rw-r--r-- | src/fstab-generator/fstab-generator.c | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index fd1a78aed2..3c0b597470 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -599,13 +599,25 @@ static int add_mount( SET_FLAG(flags, MOUNT_NOFAIL, true); } + if (!strv_isempty(wanted_by) || !strv_isempty(required_by)) { + /* If x-systemd.{wanted,required}-by= is specified, target_unit is not used */ + target_unit = NULL; + + /* Don't set default ordering dependencies on local-fs.target or remote-fs.target, but we + * still need to conflict with umount.target. */ + fputs("DefaultDependencies=no\n" + "Conflicts=umount.target\n" + "Before=umount.target\n", + f); + } + r = write_extra_dependencies(f, opts); if (r < 0) return r; /* Order the mount unit we generate relative to target_unit, so that DefaultDependencies= on the * target unit won't affect us. */ - if (!FLAGS_SET(flags, MOUNT_NOFAIL)) + if (target_unit && !FLAGS_SET(flags, MOUNT_NOFAIL)) fprintf(f, "Before=%s\n", target_unit); if (passno != 0) { @@ -696,26 +708,7 @@ static int add_mount( } } - if (!FLAGS_SET(flags, MOUNT_AUTOMOUNT)) { - if (!FLAGS_SET(flags, MOUNT_NOAUTO) && strv_isempty(wanted_by) && strv_isempty(required_by)) { - r = generator_add_symlink(dest, target_unit, - (flags & MOUNT_NOFAIL) ? "wants" : "requires", name); - if (r < 0) - return r; - } else { - STRV_FOREACH(s, wanted_by) { - r = generator_add_symlink(dest, *s, "wants", name); - if (r < 0) - return r; - } - - STRV_FOREACH(s, required_by) { - r = generator_add_symlink(dest, *s, "requires", name); - if (r < 0) - return r; - } - } - } else { + if (FLAGS_SET(flags, MOUNT_AUTOMOUNT)) { r = unit_name_from_path(where, ".automount", &automount_name); if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); @@ -745,11 +738,37 @@ static int add_mount( r = fflush_and_check(f); if (r < 0) return log_error_errno(r, "Failed to write unit file %s: %m", automount_name); + } - r = generator_add_symlink(dest, target_unit, - (flags & MOUNT_NOFAIL) ? "wants" : "requires", automount_name); - if (r < 0) - return r; + if (target_unit) { + assert(strv_isempty(wanted_by)); + assert(strv_isempty(required_by)); + + /* noauto has no effect if x-systemd.automount is used */ + if (!FLAGS_SET(flags, MOUNT_NOAUTO) || automount_name) { + r = generator_add_symlink(dest, target_unit, + FLAGS_SET(flags, MOUNT_NOFAIL) ? "wants" : "requires", + automount_name ?: name); + if (r < 0) + return r; + } + } else { + const char *unit_name = automount_name ?: name; + + STRV_FOREACH(s, wanted_by) { + r = generator_add_symlink(dest, *s, "wants", unit_name); + if (r < 0) + return r; + } + + STRV_FOREACH(s, required_by) { + r = generator_add_symlink(dest, *s, "requires", unit_name); + if (r < 0) + return r; + } + + if ((flags & (MOUNT_NOAUTO|MOUNT_NOFAIL)) != 0) + log_warning("x-systemd.wanted-by= and/or x-systemd.required-by= specified, 'noauto' and 'nofail' have no effect."); } return true; |