File: core-resolve-more-specifiers-in-unit_name_printf.patch

package info (click to toggle)
systemd 232-25%2Bdeb9u12
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,192 kB
  • sloc: ansic: 290,590; xml: 49,217; makefile: 5,503; sh: 4,031; python: 2,596; perl: 1,838
file content (97 lines) | stat: -rw-r--r-- 4,553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 5 Dec 2016 19:12:54 +0100
Subject: core: resolve more specifiers in unit_name_printf()

unit_name_printf() is usually what we use when the resulting string shall
qualify as unit name, and it hence avoids resolving specifiers that almost
certainly won't result in valid unit names.

Add a couple of more specifiers that unit_full_printf() resolves also to the
list unit_name_printf() resolves, as they are likely to be useful in valid unit
names too. (Note that there might be cases where this doesn't hold, but we
should still permit this, as more often than not they are safe, and if people
want to use them that way, they should be able to.)

(cherry picked from commit b1801e6433c30cb0ab7d7c823c98c637edfe0720)
---
 src/core/unit-printf.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index f11df42..677eed2 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -194,13 +194,20 @@ static int specifier_user_shell(char specifier, void *data, void *userdata, char
 int unit_name_printf(Unit *u, const char* format, char **ret) {
 
         /*
-         * This will use the passed string as format string and
-         * replace the following specifiers:
+         * This will use the passed string as format string and replace the following specifiers (which should all be
+         * safe for inclusion in unit names):
          *
          * %n: the full id of the unit                 (foo@bar.waldo)
          * %N: the id of the unit without the suffix   (foo@bar)
          * %p: the prefix                              (foo)
          * %i: the instance                            (bar)
+         *
+         * %U: the UID of the running user
+         * %u: the username of the running user
+         *
+         * %m: the machine ID of the running system
+         * %H: the host name of the running system
+         * %b: the boot ID of the running system
          */
 
         const Specifier table[] = {
@@ -208,7 +215,14 @@ int unit_name_printf(Unit *u, const char* format, char **ret) {
                 { 'N', specifier_prefix_and_instance, NULL },
                 { 'p', specifier_prefix,              NULL },
                 { 'i', specifier_string,              u->instance },
-                { 0, NULL, NULL }
+
+                { 'U', specifier_user_id,             NULL },
+                { 'u', specifier_user_name,           NULL },
+
+                { 'm', specifier_machine_id,          NULL },
+                { 'H', specifier_host_name,           NULL },
+                { 'b', specifier_boot_id,             NULL },
+                {}
         };
 
         assert(u);
@@ -220,22 +234,19 @@ int unit_name_printf(Unit *u, const char* format, char **ret) {
 
 int unit_full_printf(Unit *u, const char *format, char **ret) {
 
-        /* This is similar to unit_name_printf() but also supports
-         * unescaping. Also, adds a couple of additional codes:
+        /* This is similar to unit_name_printf() but also supports unescaping. Also, adds a couple of additional codes
+         * (which are likely not suitable for unescaped inclusion in unit names):
+         *
+         * %f: the unescaped instance if set, otherwise the id unescaped as path
+         * %c: cgroup path of unit
+         * %r: where units in this slice are placed in the cgroup tree
+         * %R: the root of this systemd's instance tree
+         * %t: the runtime directory to place sockets in (e.g. "/run" or $XDG_RUNTIME_DIR)
+         *
+         * %h: the homedir of the running user
+         * %s: the shell of the running user
          *
-         * %f the instance if set, otherwise the id
-         * %c cgroup path of unit
-         * %r where units in this slice are placed in the cgroup tree
-         * %R the root of this systemd's instance tree
-         * %t the runtime directory to place sockets in (e.g. "/run" or $XDG_RUNTIME_DIR)
-         * %U the UID of the running user
-         * %u the username of the running user
-         * %h the homedir of the running user
-         * %s the shell of the running user
-         * %m the machine ID of the running system
-         * %H the host name of the running system
-         * %b the boot ID of the running system
-         * %v `uname -r` of the running system
+         * %v: `uname -r` of the running system
          */
 
         const Specifier table[] = {