From 9fc507041eb524799a0410839e961ec188a78491 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 20 Oct 2010 16:16:45 +0200 Subject: [PATCH] unit: introduce %f specifier to decode file names --- man/systemd.unit.xml | 18 +++++++++++------- src/unit-name.c | 23 +++++++++++++++++++++++ src/unit-name.h | 2 ++ src/unit.c | 11 +++++++++++ units/fsck@.service.in | 4 ++-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index e54cafaa..f72b947d 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -182,13 +182,17 @@ %i specifier in many of the configuration options. Other specifiers that may be used are %n, %N, - %p, %P and - %I, for the full unit name, the - unescaped unit name, the prefix name, the unescaped - prefix name and the unescaped instance name, - respectively. The prefix name here refers to the - string before the @, i.e. "getty" in the example - above, where "tty3" is the instance name. + %p, %P, + %I and %f, for + the full unit name, the unescaped unit name, the + prefix name, the unescaped prefix name, the unescaped + instance name and the unescaped filename, + respectively. The unescaped filename is either the + unescaped instance name (if set) with / prepended (if + necessary), or the prefix name similarly prepended + with /. The prefix name here refers to the string + before the @, i.e. "getty" in the example above, where + "tty3" is the instance name. If a unit file is empty (i.e. has the file size 0) or is symlinked to /dev/null diff --git a/src/unit-name.c b/src/unit-name.c index dbaa4a7b..d0cfca62 100644 --- a/src/unit-name.c +++ b/src/unit-name.c @@ -427,3 +427,26 @@ char *unit_name_to_path(const char *name) { return e; } + +char *unit_name_path_unescape(const char *f) { + char *e; + + assert(f); + + if (!(e = unit_name_unescape(f))) + return NULL; + + if (e[0] != '/') { + char *w; + + w = strappend("/", e); + free(e); + + if (!w) + return NULL; + + e = w; + } + + return e; +} diff --git a/src/unit-name.h b/src/unit-name.h index 9842db35..e369910a 100644 --- a/src/unit-name.h +++ b/src/unit-name.h @@ -42,6 +42,8 @@ char *unit_name_build_escape(const char *prefix, const char *instance, const cha char *unit_name_escape(const char *f); char *unit_name_unescape(const char *f); +char *unit_name_path_unescape(const char *f); + bool unit_name_is_template(const char *n); char *unit_name_replace_instance(const char *f, const char *i); diff --git a/src/unit.c b/src/unit.c index 07978134..ab6eb202 100644 --- a/src/unit.c +++ b/src/unit.c @@ -1880,6 +1880,16 @@ static char *specifier_instance_unescaped(char specifier, void *data, void *user return strdup(""); } +static char *specifier_filename(char specifier, void *data, void *userdata) { + Unit *u = userdata; + assert(u); + + if (u->meta.instance) + return unit_name_path_unescape(u->meta.instance); + + return unit_name_to_path(u->meta.instance); +} + char *unit_name_printf(Unit *u, const char* format) { /* @@ -1918,6 +1928,7 @@ char *unit_full_printf(Unit *u, const char *format) { { 'P', specifier_prefix_unescaped, NULL }, { 'i', specifier_string, u->meta.instance }, { 'I', specifier_instance_unescaped, NULL }, + { 'f', specifier_filename, NULL }, { 0, NULL, NULL } }; diff --git a/units/fsck@.service.in b/units/fsck@.service.in index f0ccc8f0..860c3a64 100644 --- a/units/fsck@.service.in +++ b/units/fsck@.service.in @@ -6,7 +6,7 @@ # (at your option) any later version. [Unit] -Description=File System Check on %I +Description=File System Check on %f DefaultDependencies=no Requires=%i.device After=systemd-readahead-collect.service systemd-readahead-replay.service %i.device @@ -15,4 +15,4 @@ Before=local-fs.target shutdown.target [Service] Type=oneshot RemainAfterExit=no -ExecStart=@rootlibexecdir@/systemd-fsck %I +ExecStart=@rootlibexecdir@/systemd-fsck %f -- 2.39.5