X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ffstab-generator%2Ffstab-generator.c;h=9754f3a69a76c9ebd7b511775635189e50ae7d83;hb=1b036593b76614dd05942a78120c151161cccc0f;hp=d5f9db49ca8b6016afd34bb5548070bad0ee5067;hpb=790838e4f16831f2bb06aeb845b9e2fb0f1d28dd;p=elogind.git diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index d5f9db49c..9754f3a69 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -389,19 +389,21 @@ 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) return 0; - log_error("Failed to open %s/etc/fstab: %m", prefix); + log_error("Failed to open %s/etc/fstab: %m", strempty(prefix)); return -errno; } @@ -413,7 +415,7 @@ static int parse_fstab(const char *prefix, bool initrd) { continue; what = fstab_node_to_udev_node(me->mnt_fsname); - where = strjoin(prefix, me->mnt_dir, NULL); + where = strjoin(strempty(prefix), me->mnt_dir, NULL); if (!what || !where) { r = log_oom(); goto finish; @@ -466,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; @@ -485,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) @@ -504,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) { @@ -614,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);