[systemd-devel] [PATCH] fstab-generator: default to "ro"

harald at redhat.com harald at redhat.com
Fri Mar 1 06:13:45 PST 2013


From: Harald Hoyer <harald at redhat.com>

If no "ro" or "rw" is specified on the kernel command line, mount root
read-only on /sysroot by default
---
 src/fstab-generator/fstab-generator.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 026d070..d83e73f 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -465,9 +465,11 @@ 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 *tmp_word;
         int r;
         size_t l;
         bool wait = false;
+        bool ro_rw = false;
 
         r = read_one_line_file("/proc/cmdline", &line);
         if (r < 0) {
@@ -482,7 +484,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;
+                char *word;
 
                 word = strndup(w, l);
                 if (!word)
@@ -514,12 +516,22 @@ static int parse_new_root_from_proc_cmdline(void) {
                         if (!opts)
                                 return log_oom();
 
+                        ro_rw = true;
+
                 } else if (streq(word, "rootwait"))
                         wait = true;
 
                 free(word);
         }
 
+        if (!ro_rw) {
+                tmp_word = opts;
+                opts = strjoin(opts, ",", "ro", NULL);
+                free(tmp_word);
+                if (!opts)
+                        return log_oom();
+        }
+
         if (what) {
 
                 log_debug("Found entry what=%s where=/sysroot type=%s", what, type);
-- 
1.8.1



More information about the systemd-devel mailing list