chiark / gitweb /
unit: introduce %f specifier to decode file names
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Oct 2010 14:16:45 +0000 (16:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Oct 2010 14:16:45 +0000 (16:16 +0200)
man/systemd.unit.xml
src/unit-name.c
src/unit-name.h
src/unit.c
units/fsck@.service.in

index e54cafaabcd2f0b854b7d9e1aa7126c83170d5a5..f72b947dca052ffefc7fe99d0eb344638a9b829d 100644 (file)
                 <literal>%i</literal> specifier in many of the
                 configuration options. Other specifiers that may be
                 used are <literal>%n</literal>, <literal>%N</literal>,
-                <literal>%p</literal>, <literal>%P</literal> and
-                <literal>%I</literal>, 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.</para>
+                <literal>%p</literal>, <literal>%P</literal>,
+                <literal>%I</literal> and <literal>%f</literal>, 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.</para>
 
                 <para>If a unit file is empty (i.e. has the file size
                 0) or is symlinked to <filename>/dev/null</filename>
index dbaa4a7b12c3acdf5b02b323e236477e0336d8cb..d0cfca62549cb9af5329d7a84e491de355679903 100644 (file)
@@ -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;
+}
index 9842db35524f2d4b6f436c3c7d40567847c73b05..e369910aea1b23ae1802aae8143ebfcc66109931 100644 (file)
@@ -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);
index 07978134de959889f213740bd55aaeffd80bb939..ab6eb20227c1c9c1b2177228646ad422826d30a8 100644 (file)
@@ -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 }
         };
 
index f0ccc8f075ccdb0a3324c9ec0f8997c3f55a2ed9..860c3a646a52bbacced848520722f427f5f8cf61 100644 (file)
@@ -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