1
0
mirror of https://github.com/systemd/systemd.git synced 2025-08-31 09:49:54 +03:00

Merge pull request #5255 from poettering/percent-escape

fstab-generator: Options= applies specifier expansion
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2017-02-09 09:18:41 -05:00
committed by GitHub
3 changed files with 69 additions and 41 deletions

View File

@ -337,14 +337,12 @@
<varlistentry> <varlistentry>
<term><varname>What=</varname></term> <term><varname>What=</varname></term>
<listitem><para>Takes an absolute path of a device node, file <listitem><para>Takes an absolute path of a device node, file or other resource to mount. See <citerefentry
or other resource to mount. See project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details. If
<citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> this refers to a device node, a dependency on the respective device unit is automatically created. (See
for details. If this refers to a device node, a dependency on <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
the respective device unit is automatically created. (See information.) This option is mandatory. Note that the usual specifier expansion is applied to this setting,
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> literal percent characters should hence be written as <literal>%%</literal>.</para></listitem>
for more information.) This option is
mandatory.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -366,9 +364,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

@ -170,17 +170,15 @@
<varlistentry> <varlistentry>
<term><varname>What=</varname></term> <term><varname>What=</varname></term>
<listitem><para>Takes an absolute path of a device node or <listitem><para>Takes an absolute path of a device node or file to use for paging. See <citerefentry
file to use for paging. See project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
<citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> details. If this refers to a device node, a dependency on the respective device unit is automatically
for details. If this refers to a device node, a dependency on created. (See
the respective device unit is automatically created. (See <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> information.) If this refers to a file, a dependency on the respective mount unit is automatically
for more information.) If this refers to a file, a dependency created. (See <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
on the respective mount unit is automatically created. (See for more information.) This option is mandatory. Note that the usual specifier expansion is applied to this
<citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry> setting, literal percent characters should hence be written as <literal>%%</literal>.</para></listitem>
for more information.) This option is
mandatory.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
@ -195,12 +193,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,34 @@ 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 write_what(FILE *f, const char *what) {
_cleanup_free_ char *w = NULL;
w = strreplace(what, "%", "%%");
if (!w)
return log_oom();
fprintf(f, "What=%s\n", w);
return 1;
}
static int add_swap( static int add_swap(
const char *what, const char *what,
struct mntent *me, struct mntent *me,
@ -96,17 +124,19 @@ static int add_swap(
"Failed to create unit file %s: %m", "Failed to create unit file %s: %m",
unit); unit);
fprintf(f, fputs("# Automatically generated by systemd-fstab-generator\n\n"
"# Automatically generated by systemd-fstab-generator\n\n"
"[Unit]\n" "[Unit]\n"
"SourcePath=/etc/fstab\n" "SourcePath=/etc/fstab\n"
"Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n" "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n"
"[Swap]\n" "[Swap]\n", f);
"What=%s\n",
what);
if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults")) r = write_what(f, what);
fprintf(f, "Options=%s\n", me->mnt_opts); if (r < 0)
return r;
r = write_options(f, me->mnt_opts);
if (r < 0)
return r;
r = fflush_and_check(f); r = fflush_and_check(f);
if (r < 0) if (r < 0)
@ -331,11 +361,13 @@ static int add_mount(
fprintf(f, fprintf(f,
"\n" "\n"
"[Mount]\n" "[Mount]\n"
"What=%s\n"
"Where=%s\n", "Where=%s\n",
what,
where); where);
r = write_what(f, what);
if (r < 0)
return r;
if (!isempty(fstype) && !streq(fstype, "auto")) if (!isempty(fstype) && !streq(fstype, "auto"))
fprintf(f, "Type=%s\n", fstype); fprintf(f, "Type=%s\n", fstype);
@ -347,8 +379,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)