summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/systemd.mount.xml6
-rw-r--r--man/systemd.swap.xml9
-rw-r--r--src/fstab-generator/fstab-generator.c27
3 files changed, 30 insertions, 12 deletions
diff --git a/man/systemd.mount.xml b/man/systemd.mount.xml
index 2117433bf0..8d9517a913 100644
--- a/man/systemd.mount.xml
+++ b/man/systemd.mount.xml
@@ -366,9 +366,9 @@
<varlistentry>
<term><varname>Options=</varname></term>
- <listitem><para>Mount options to use when mounting. This takes
- a comma-separated list of options. This setting is
- optional.</para></listitem>
+ <listitem><para>Mount options to use when mounting. This takes a comma-separated list of options. This setting
+ is optional. 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>
diff --git a/man/systemd.swap.xml b/man/systemd.swap.xml
index cf4e1ba839..7f82d69725 100644
--- a/man/systemd.swap.xml
+++ b/man/systemd.swap.xml
@@ -195,12 +195,11 @@
<varlistentry>
<term><varname>Options=</varname></term>
- <listitem><para>May contain an option string for the swap
- device. This may be used for controlling discard options among
- other functionality, if the swap backing device supports the
- discard or trim operation. (See
+ <listitem><para>May contain an option string for the swap device. This may be used for controlling discard
+ options among 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>
- 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>
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 3c601a63e2..00c6b2d37b 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -57,6 +57,23 @@ static char *arg_usr_fstype = NULL;
static char *arg_usr_options = NULL;
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(
const char *what,
struct mntent *me,
@@ -105,8 +122,9 @@ static int add_swap(
"What=%s\n",
what);
- if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults"))
- fprintf(f, "Options=%s\n", me->mnt_opts);
+ r = write_options(f, me->mnt_opts);
+ if (r < 0)
+ return r;
r = fflush_and_check(f);
if (r < 0)
@@ -347,8 +365,9 @@ static int add_mount(
if (r < 0)
return r;
- if (!isempty(filtered) && !streq(filtered, "defaults"))
- fprintf(f, "Options=%s\n", filtered);
+ r = write_options(f, filtered);
+ if (r < 0)
+ return r;
r = fflush_and_check(f);
if (r < 0)