]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: also convert % → %% for What= 5255/head
authorLennart Poettering <lennart@poettering.net>
Wed, 8 Feb 2017 16:14:58 +0000 (17:14 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 8 Feb 2017 16:20:35 +0000 (17:20 +0100)
Same reasons as the previous patch.

man/systemd.mount.xml
man/systemd.swap.xml
src/fstab-generator/fstab-generator.c

index 8d9517a9139ca902c742ea0d6e1a073bc605e4b9..bb372d788a39f4deefda025bcbad482cda937529 100644 (file)
 
       <varlistentry>
         <term><varname>What=</varname></term>
-        <listitem><para>Takes an absolute path of a device node, file
-        or other resource to mount. See
-        <citerefentry project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry>
-        for details. If this refers to a device node, a dependency on
-        the respective device unit is automatically created. (See
-        <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>
-        for more information.) This option is
-        mandatory.</para></listitem>
+        <listitem><para>Takes an absolute path of a device node, file or other resource to mount. See <citerefentry
+        project='man-pages'><refentrytitle>mount</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details. If
+        this refers to a device node, a dependency on the respective device unit is automatically created. (See
+        <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
+        information.) This option is mandatory. 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>
index 7f82d69725ceeaf63e7222b2e6b73e16be5bc26c..d2c202722867de1d8aaabafba17c8b36b3d51717 100644 (file)
 
       <varlistentry>
         <term><varname>What=</varname></term>
-        <listitem><para>Takes an absolute path of a device node or
-        file to use for paging. See
-        <citerefentry project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry>
-        for details. If this refers to a device node, a dependency on
-        the respective device unit is automatically created. (See
-        <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry>
-        for more information.) If this refers to a file, a dependency
-        on the respective mount unit is automatically created. (See
-        <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
-        for more information.) This option is
-        mandatory.</para></listitem>
+        <listitem><para>Takes an absolute path of a device node or file to use for paging. See <citerefentry
+        project='man-pages'><refentrytitle>swapon</refentrytitle><manvolnum>8</manvolnum></citerefentry> for
+        details. If this refers to a device node, a dependency on the respective device unit is automatically
+        created. (See
+        <citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
+        information.) If this refers to a file, a dependency on the respective mount unit is automatically
+        created. (See <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+        for more information.) This option is mandatory. 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>
index 00c6b2d37b407549a76381b9de30118b07dd7b69..d97bafd1fb2a58a4f1506ad78a0195456d9d88b0 100644 (file)
@@ -74,6 +74,17 @@ static int write_options(FILE *f, const char *options) {
         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(
                 const char *what,
                 struct mntent *me,
@@ -113,14 +124,15 @@ static int add_swap(
                                        "Failed to create unit file %s: %m",
                                        unit);
 
-        fprintf(f,
-                "# Automatically generated by systemd-fstab-generator\n\n"
-                "[Unit]\n"
-                "SourcePath=/etc/fstab\n"
-                "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n"
-                "[Swap]\n"
-                "What=%s\n",
-                what);
+        fputs("# Automatically generated by systemd-fstab-generator\n\n"
+              "[Unit]\n"
+              "SourcePath=/etc/fstab\n"
+              "Documentation=man:fstab(5) man:systemd-fstab-generator(8)\n\n"
+              "[Swap]\n", f);
+
+        r = write_what(f, what);
+        if (r < 0)
+                return r;
 
         r = write_options(f, me->mnt_opts);
         if (r < 0)
@@ -349,11 +361,13 @@ static int add_mount(
         fprintf(f,
                 "\n"
                 "[Mount]\n"
-                "What=%s\n"
                 "Where=%s\n",
-                what,
                 where);
 
+        r = write_what(f, what);
+        if (r < 0)
+                return r;
+
         if (!isempty(fstype) && !streq(fstype, "auto"))
                 fprintf(f, "Type=%s\n", fstype);