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

Lennart Poettering lennart at poettering.net
Fri Mar 1 08:37:43 PST 2013


On Fri, 01.03.13 15:13, harald at redhat.com (harald at redhat.com) wrote:

> 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

This sounds good, in order to stay in sync with the initrd-less kernel
logic. Please commit!

> ---
>  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);


Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list