+ size_t l;
+
+ /* Skip generation, if sysroot.mount already exists */
+ mu = strjoin(arg_dest, "/", "sysroot.mount", NULL);
+ if (!mu)
+ return log_oom();
+
+ r = access(mu, R_OK);
+ if (r == 0)
+ return 0;
+
+ r = read_one_line_file("/proc/cmdline", &line);
+ if (r < 0) {
+ log_error("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
+ return 0;
+ }
+
+ opts = strdup("ro");
+ type = strdup("auto");
+ if (!opts || !type)
+ return log_oom();
+
+ /* 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;
+
+ word = strndup(w, l);
+ if (!word)
+ return log_oom();
+
+ else if (startswith(word, "root=")) {
+ free(what);
+ what = fstab_node_to_udev_node(word+5);
+ if (!what)
+ return log_oom();
+
+ } else if (startswith(word, "rootfstype=")) {
+ free(type);
+ type = strdup(word + 11);
+ if (!type)
+ return log_oom();
+
+ } else if (startswith(word, "rootflags=")) {
+ tmp_word = opts;
+ opts = strjoin(opts, ",", word + 10, NULL);
+ free(tmp_word);
+ if (!opts)
+ return log_oom();
+
+ } else if (streq(word, "ro") || streq(word, "rw")) {
+ tmp_word = opts;
+ opts = strjoin(opts, ",", word, NULL);
+ free(tmp_word);
+ if (!opts)
+ return log_oom();
+
+ }
+
+ free(word);
+ }
+
+ if (what) {
+
+ log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
+ r = add_mount(what, "/sysroot", type, opts, 0, false, false, false,
+ false, false, true, "/proc/cmdline");
+
+ if (r < 0)
+ return r;
+ } else
+ log_error("Could not find a root= entry on the kernel commandline.");
+
+ return 0;
+}
+
+static int parse_proc_cmdline(void) {
+ char _cleanup_free_ *line = NULL;
+ char *w, *state;
+ int r;
+ size_t l;
+
+ if (detect_container(NULL) > 0)
+ return 0;
+
+ r = read_one_line_file("/proc/cmdline", &line);
+ if (r < 0) {
+ log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
+ return 0;
+ }
+
+ FOREACH_WORD_QUOTED(w, l, line, state) {
+ char _cleanup_free_ *word = NULL;
+
+ word = strndup(w, l);
+ if (!word)
+ return log_oom();
+
+ if (startswith(word, "fstab=")) {
+ r = parse_boolean(word + 6);
+ if (r < 0)
+ log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
+ else
+ arg_enabled = r;
+
+ } else if (startswith(word, "rd.fstab=")) {
+
+ if (in_initrd()) {
+ r = parse_boolean(word + 6);
+ if (r < 0)
+ log_warning("Failed to parse fstab switch %s. Ignoring.", word + 6);
+ else
+ arg_enabled = r;
+ }
+
+ } else if (startswith(word, "fstab.") ||
+ (in_initrd() && startswith(word, "rd.fstab."))) {
+
+ log_warning("Unknown kernel switch %s. Ignoring.", word);
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ int r = 0, k = 0, l = 0;