summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-09 09:18:41 -0500
committerGitHub <noreply@github.com>2017-02-09 09:18:41 -0500
commitbc7e815445d84f26e81d3883c1b707fc0bf825ba (patch)
treeee5dd98503dd5410f47d9467c0b3c57ab816a43a /src
parent6f844e3a3f97d2b3fce9d37714575177b9ff3f4c (diff)
parent19d0833bead317dc099c10b472c23e665ff76cfd (diff)
Merge pull request #5255 from poettering/percent-escape
fstab-generator: Options= applies specifier expansion
Diffstat (limited to 'src')
-rw-r--r--src/fstab-generator/fstab-generator.c61
1 files changed, 47 insertions, 14 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 3c601a63e2..d97bafd1fb 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -57,6 +57,34 @@ 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 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,
@@ -96,17 +124,19 @@ 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;
- 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)
@@ -331,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);
@@ -347,8 +379,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)