X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ffstab-generator%2Ffstab-generator.c;h=7f065eb353f18fbdbbca41b4d07c4e1a7f722eb2;hb=80c39ad27f5e99b1f18bdacd2b27a05ddee6cca1;hp=b4fb1344e6b200e5e6cd5dbd956ac00b72583944;hpb=700e07ffd53083114e91bb4ba646ed26d0463f67;p=elogind.git diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b4fb1344e..7f065eb35 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -199,6 +199,12 @@ static bool mount_in_initrd(struct mntent *me) { streq(me->mnt_dir, "/usr"); } +static bool mount_is_rootfs(struct mntent *me) { + assert(me); + + return hasmntopt(me, "x-initrd.rootfs"); +} + static int add_mount(const char *what, const char *where, const char *type, const char *opts, int passno, bool noauto, bool nofail, bool automount, bool isbind, const char *pre, const char *post, const char *source) { @@ -383,13 +389,15 @@ static int add_mount(const char *what, const char *where, const char *type, cons } static int parse_fstab(const char *prefix, bool initrd) { - FILE *f; _cleanup_free_ char *fstab_path = NULL; + FILE *f; int r = 0; struct mntent *me; - errno = 0; - fstab_path = strjoin(prefix, "/etc/fstab", NULL); + fstab_path = strjoin(strempty(prefix), "/etc/fstab", NULL); + if (!fstab_path) + return log_oom(); + f = setmntent(fstab_path, "r"); if (!f) { if (errno == ENOENT) @@ -434,6 +442,9 @@ static int parse_fstab(const char *prefix, bool initrd) { if (initrd) { post = SPECIAL_INITRD_FS_TARGET; pre = NULL; + } else if (mount_is_rootfs(me)) { + post = SPECIAL_INITRD_ROOT_FS_TARGET; + pre = NULL; } else if (mount_is_network(me)) { post = SPECIAL_REMOTE_FS_TARGET; pre = SPECIAL_REMOTE_FS_PRE_TARGET; @@ -457,8 +468,8 @@ finish: } static int parse_new_root_from_proc_cmdline(void) { - char *w, *state; _cleanup_free_ char *what = NULL, *type = NULL, *opts = NULL, *line = NULL; + char *w, *state; int r; size_t l; @@ -476,7 +487,7 @@ static int parse_new_root_from_proc_cmdline(void) { /* root= and roofstype= may occur more than once, the last instance should take precedence. * In the case of multiple rootflags= the arguments should be concatenated */ FOREACH_WORD_QUOTED(w, l, line, state) { - char *word, *tmp_word; + _cleanup_free_ char *word; word = strndup(w, l); if (!word) @@ -495,22 +506,25 @@ static int parse_new_root_from_proc_cmdline(void) { return log_oom(); } else if (startswith(word, "rootflags=")) { - tmp_word = opts; - opts = strjoin(opts, ",", word + 10, NULL); - free(tmp_word); - if (!opts) + char *o; + + o = strjoin(opts, ",", word + 10, NULL); + if (!o) return log_oom(); + free(opts); + opts = o; + } else if (streq(word, "ro") || streq(word, "rw")) { - tmp_word = opts; - opts = strjoin(opts, ",", word, NULL); - free(tmp_word); - if (!opts) + char *o; + + o = strjoin(opts, ",", word, NULL); + if (!o) return log_oom(); + free(opts); + opts = o; } - - free(word); } if (!what) { @@ -525,7 +539,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, false, false, false, - false, NULL, SPECIAL_ROOT_FS_TARGET, "/proc/cmdline"); + false, NULL, SPECIAL_INITRD_ROOT_FS_TARGET, "/proc/cmdline"); return (r < 0) ? r : 0; } @@ -605,7 +619,7 @@ int main(int argc, char *argv[]) { if (!arg_enabled) return (r < 0) ? EXIT_FAILURE : EXIT_SUCCESS; - k = parse_fstab("", false); + k = parse_fstab(NULL, false); if (in_initrd()) l = parse_fstab("/sysroot", true);