X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ffstab-generator%2Ffstab-generator.c;h=78d7609c6c14b83842f9eabe118cb0bda4b17454;hb=5ecb28f69ef670c7e194b656b57fda6f8850f0ba;hp=6ebe8aa67300016a901171f3c52cd89f18df232c;hpb=64347fc2b983f33e7efb0fd2bb44e133fb9f30f4;p=elogind.git diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 6ebe8aa67..78d7609c6 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -64,8 +64,9 @@ static int mount_find_pri(struct mntent *me, int *ret) { } static int add_swap(const char *what, struct mntent *me) { - _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL; + _cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL; _cleanup_fclose_ FILE *f = NULL; + bool noauto; int r, pri = -1; assert(what); @@ -77,6 +78,8 @@ static int add_swap(const char *what, struct mntent *me) { return pri; } + noauto = !!hasmntopt(me, "noauto"); + name = unit_name_from_path(what, ".swap"); if (!name) return log_oom(); @@ -97,8 +100,7 @@ static int add_swap(const char *what, struct mntent *me) { fprintf(f, "# Automatically generated by systemd-fstab-generator\n\n" "[Unit]\n" - "SourcePath=/etc/fstab\n" - "\n" + "SourcePath=/etc/fstab\n\n" "[Swap]\n" "What=%s\n", what); @@ -114,6 +116,18 @@ static int add_swap(const char *what, struct mntent *me) { return -errno; } + if (!noauto) { + lnk = strjoin(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL); + if (!lnk) + return log_oom(); + + mkdir_parents_label(lnk, 0755); + if (symlink(unit, lnk) < 0) { + log_error("Failed to create symlink %s: %m", lnk); + return -errno; + } + } + return 0; } @@ -145,7 +159,7 @@ static int add_mount( const char *post, const char *source) { _cleanup_free_ char - *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL, + *name = NULL, *unit = NULL, *lnk = NULL, *automount_name = NULL, *automount_unit = NULL; _cleanup_fclose_ FILE *f = NULL; @@ -195,17 +209,42 @@ static int add_mount( "Before=%s\n", post); + if (passno > 0) { + if (streq(where, "/")) { + lnk = strjoin(arg_dest, "/", SPECIAL_LOCAL_FS_TARGET, ".wants/", "systemd-fsck-root.service", NULL); + if (!lnk) + return log_oom(); + + mkdir_parents_label(lnk, 0755); + if (symlink("systemd-fsck-root.service", lnk) < 0) { + log_error("Failed to create symlink %s: %m", lnk); + return -errno; + } + } else { + _cleanup_free_ char *fsck = NULL; + + fsck = unit_name_from_path_instance("systemd-fsck", what, ".service"); + if (!fsck) + return log_oom(); + + fprintf(f, + "Requires=%s\n" + "After=%s\n", + fsck, + fsck); + } + } + + fprintf(f, "\n" "[Mount]\n" "What=%s\n" "Where=%s\n" - "Type=%s\n" - "FsckPassNo=%i\n", + "Type=%s\n", what, where, - type, - passno); + type); if (!isempty(opts) && !streq(opts, "defaults")) @@ -221,6 +260,7 @@ static int add_mount( if (!noauto) { if (post) { + free(lnk); lnk = strjoin(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL); if (!lnk) return log_oom(); @@ -287,15 +327,12 @@ static int add_mount( } static int parse_fstab(const char *prefix, bool initrd) { - _cleanup_free_ char *fstab_path = NULL; - FILE *f; + char *fstab_path; + _cleanup_endmntent_ FILE *f; int r = 0; struct mntent *me; - fstab_path = strjoin(strempty(prefix), "/etc/fstab", NULL); - if (!fstab_path) - return log_oom(); - + fstab_path = strappenda(strempty(prefix), "/etc/fstab"); f = setmntent(fstab_path, "r"); if (!f) { if (errno == ENOENT) @@ -314,10 +351,8 @@ static int parse_fstab(const char *prefix, bool initrd) { what = fstab_node_to_udev_node(me->mnt_fsname); where = strjoin(strempty(prefix), me->mnt_dir, NULL); - if (!what || !where) { - r = log_oom(); - goto finish; - } + if (!what || !where) + return log_oom(); if (is_path(where)) path_kill_slashes(where); @@ -355,8 +390,6 @@ static int parse_fstab(const char *prefix, bool initrd) { r = k; } -finish: - endmntent(f); return r; } @@ -435,7 +468,7 @@ static int parse_new_root_from_proc_cmdline(void) { } log_debug("Found entry what=%s where=/sysroot type=%s", what, type); - r = add_mount(what, "/sysroot", type, opts, 0, noauto, nofail, false, + r = add_mount(what, "/sysroot", type, opts, 1, noauto, nofail, false, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline"); return (r < 0) ? r : 0;