fstab-generator: Options= applies specifier expansion

Let's document that this is the case, and properly escape % when we
generate Options= in the generator.

Fixes: #5086
This commit is contained in:
Lennart Poettering 2017-02-07 13:08:56 +01:00
parent b53ede699c
commit d5cc4be28f
3 changed files with 30 additions and 12 deletions

View file

@ -366,9 +366,9 @@
<varlistentry> <varlistentry>
<term><varname>Options=</varname></term> <term><varname>Options=</varname></term>
<listitem><para>Mount options to use when mounting. This takes <listitem><para>Mount options to use when mounting. This takes a comma-separated list of options. This setting
a comma-separated list of options. This setting is is optional. Note that the usual specifier expansion is applied to this setting, literal percent characters
optional.</para></listitem> should hence be written as <literal>%%</literal>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View file

@ -195,12 +195,11 @@
<varlistentry> <varlistentry>
<term><varname>Options=</varname></term> <term><varname>Options=</varname></term>
<listitem><para>May contain an option string for the swap <listitem><para>May contain an option string for the swap device. This may be used for controlling discard
device. This may be used for controlling discard options among options among other functionality, if the swap backing device supports the discard or trim operation. (See
other functionality, if the swap backing device supports the
discard or trim operation. (See
<citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> <citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry>
for more information.) </para></listitem> for more information.) Note that the usual specifier expansion is applied to this setting, literal percent
characters should hence be written as <literal>%%</literal>.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View file

@ -57,6 +57,23 @@ static char *arg_usr_fstype = NULL;
static char *arg_usr_options = NULL; static char *arg_usr_options = NULL;
static VolatileMode arg_volatile_mode = _VOLATILE_MODE_INVALID; static VolatileMode arg_volatile_mode = _VOLATILE_MODE_INVALID;
static int write_options(FILE *f, const char *options) {
_cleanup_free_ char *o = NULL;
if (isempty(options))
return 0;
if (streq(options, "defaults"))
return 0;
o = strreplace(options, "%", "%%");
if (!o)
return log_oom();
fprintf(f, "Options=%s\n", o);
return 1;
}
static int add_swap( static int add_swap(
const char *what, const char *what,
struct mntent *me, struct mntent *me,
@ -105,8 +122,9 @@ static int add_swap(
"What=%s\n", "What=%s\n",
what); what);
if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults")) r = write_options(f, me->mnt_opts);
fprintf(f, "Options=%s\n", me->mnt_opts); if (r < 0)
return r;
r = fflush_and_check(f); r = fflush_and_check(f);
if (r < 0) if (r < 0)
@ -347,8 +365,9 @@ static int add_mount(
if (r < 0) if (r < 0)
return r; return r;
if (!isempty(filtered) && !streq(filtered, "defaults")) r = write_options(f, filtered);
fprintf(f, "Options=%s\n", filtered); if (r < 0)
return r;
r = fflush_and_check(f); r = fflush_and_check(f);
if (r < 0) if (r < 0)