fstab-generator: also convert % → %% for What=

Same reasons as the previous patch.
This commit is contained in:
Lennart Poettering
2017-02-08 17:20:35 +01:00
parent d5cc4be28f
commit 19d0833bea
3 changed files with 39 additions and 29 deletions
+24 -10
View 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);