]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: introduce specifiers for /tmp and /var/tmp
authorLennart Poettering <lennart@poettering.net>
Tue, 29 May 2018 09:25:26 +0000 (11:25 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 29 May 2018 09:39:15 +0000 (11:39 +0200)
This corresponds nicely with the specifiers we already pass for
/var/lib, /var/cache, /run and so on.

This is particular useful to update the test-path service files to
operate without guessable files, thus allowing multiple parallel
test-path invocations to pass without issues (the idea is to set $TMPDIR
early on in the test to some private directory, and then only use the
new %T or %V specifier to refer to it).

man/systemd.unit.xml
man/tmpfiles.d.xml
src/core/unit-printf.c
src/shared/specifier.c
src/shared/specifier.h
src/sysusers/sysusers.c
src/tmpfiles/tmpfiles.c
test/test-execute/exec-specifier.service

index 3d0f0ff87c52326a19cf1cf37fefcede934c8594..b6f4728b0098df3d87adedb91ce0c116be32bf77 100644 (file)
             <entry>Runtime directory root</entry>
             <entry>This is either <filename>/run</filename> (for the system manager) or the path <literal>$XDG_RUNTIME_DIR</literal> resolves to (for user managers).</entry>
           </row>
+          <row>
+            <entry><literal>%T</literal></entry>
+            <entry>Directory for temporary files</entry>
+            <entry>This is either <filename>/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
+          </row>
           <row>
             <entry><literal>%u</literal></entry>
             <entry>User name</entry>
             <entry>Kernel release</entry>
             <entry>Identical to <command>uname -r</command> output</entry>
           </row>
+          <row>
+            <entry><literal>%V</literal></entry>
+            <entry>Directory for larger and persistent temporary files</entry>
+            <entry>This is either <filename>/var/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
+          </row>
           <row>
             <entry><literal>%%</literal></entry>
             <entry>Single percent sign</entry>
index 30809f25f009320090e308d7e5b457f920ba4839..46bec912c529461ffd5337e27b3347359b787f8e 100644 (file)
@@ -651,6 +651,11 @@ r! /tmp/.X[0-9]*-lock</programlisting>
               <entry>System or user runtime directory</entry>
               <entry>In --user mode, this is the same <varname>$XDG_RUNTIME_DIR</varname>, and <filename>/run</filename> otherwise.</entry>
             </row>
+            <row>
+              <entry><literal>%T</literal></entry>
+              <entry>Directory for temporary files</entry>
+              <entry>This is either <filename>/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
+            </row>
             <row>
               <entry><literal>%u</literal></entry>
               <entry>User name</entry>
@@ -666,6 +671,11 @@ r! /tmp/.X[0-9]*-lock</programlisting>
               <entry>Kernel release</entry>
               <entry>Identical to <command>uname -r</command> output.</entry>
             </row>
+            <row>
+              <entry><literal>%V</literal></entry>
+              <entry>Directory for larger and persistent temporary files</entry>
+              <entry>This is either <filename>/var/tmp</filename> or the path <literal>$TMPDIR</literal>, <literal>$TEMP</literal> or <literal>$TMP</literal> are set to.</entry>
+            </row>
             <row>
               <entry><literal>%%</literal></entry>
               <entry>Escaped <literal>%</literal></entry>
index d2948ab6aad29902c724375b5473b4354e6da5e8..20891200bad9dd7eb5904b22b5d12bfa22a7f9f6 100644 (file)
@@ -232,6 +232,8 @@ int unit_full_printf(Unit *u, const char *format, char **ret) {
          * %S: the state directory root (e.g. /var/lib or $XDG_CONFIG_HOME)
          * %C: the cache directory root (e.g. /var/cache or $XDG_CACHE_HOME)
          * %L: the log directory root (e.g. /var/log or $XDG_CONFIG_HOME/log)
+         * %T: the temporary directory (e.g. /tmp, or $TMPDIR, $TEMP, $TMP)
+         * %V: the temporary directory for large, persistent stuff (e.g. /var/tmp, or $TMPDIR, $TEMP, $TMP)
          *
          * %h: the homedir of the running user
          * %s: the shell of the running user
@@ -257,10 +259,13 @@ int unit_full_printf(Unit *u, const char *format, char **ret) {
                 { 'c', specifier_cgroup,                   NULL },
                 { 'r', specifier_cgroup_slice,             NULL },
                 { 'R', specifier_cgroup_root,              NULL },
+
                 { 't', specifier_special_directory,        UINT_TO_PTR(EXEC_DIRECTORY_RUNTIME) },
                 { 'S', specifier_special_directory,        UINT_TO_PTR(EXEC_DIRECTORY_STATE) },
                 { 'C', specifier_special_directory,        UINT_TO_PTR(EXEC_DIRECTORY_CACHE) },
                 { 'L', specifier_special_directory,        UINT_TO_PTR(EXEC_DIRECTORY_LOGS) },
+                { 'T', specifier_tmp_dir,                  NULL },
+                { 'V', specifier_var_tmp_dir,              NULL },
 
                 { 'U', specifier_user_id,                  NULL },
                 { 'u', specifier_user_name,                NULL },
index 27782b8d5b2acdbc5ffadd18cee7018648838c1d..c4b2bdc12d7c63563a71eca91d21e16a01b54570 100644 (file)
@@ -15,6 +15,7 @@
 #include "sd-id128.h"
 
 #include "alloc-util.h"
+#include "fs-util.h"
 #include "hostname-util.h"
 #include "macro.h"
 #include "specifier.h"
@@ -222,6 +223,40 @@ int specifier_user_shell(char specifier, void *data, void *userdata, char **ret)
         return get_shell(ret);
 }
 
+int specifier_tmp_dir(char specifier, void *data, void *userdata, char **ret) {
+        const char *p;
+        char *copy;
+        int r;
+
+        r = tmp_dir(&p);
+        if (r < 0)
+                return r;
+
+        copy = strdup(p);
+        if (!copy)
+                return -ENOMEM;
+
+        *ret = copy;
+        return 0;
+}
+
+int specifier_var_tmp_dir(char specifier, void *data, void *userdata, char **ret) {
+        const char *p;
+        char *copy;
+        int r;
+
+        r = var_tmp_dir(&p);
+        if (r < 0)
+                return r;
+
+        copy = strdup(p);
+        if (!copy)
+                return -ENOMEM;
+
+        *ret = copy;
+        return 0;
+}
+
 int specifier_escape_strv(char **l, char ***ret) {
         char **z, **p, **q;
 
index b998c2a7592c72ba7c578e4c27172674d8500d85..33c0e2727e754882c97ffc5867e0388c895f66a4 100644 (file)
@@ -31,6 +31,9 @@ int specifier_user_id(char specifier, void *data, void *userdata, char **ret);
 int specifier_user_home(char specifier, void *data, void *userdata, char **ret);
 int specifier_user_shell(char specifier, void *data, void *userdata, char **ret);
 
+int specifier_tmp_dir(char specifier, void *data, void *userdata, char **ret);
+int specifier_var_tmp_dir(char specifier, void *data, void *userdata, char **ret);
+
 static inline char* specifier_escape(const char *string) {
         return strreplace(string, "%", "%%");
 }
index af041d2f74bb3f5ba6771d0ff5219a16415652fb..b521200346d7037b08f3e9d4b170cebd84c8c0fe 100644 (file)
@@ -1359,10 +1359,12 @@ static bool item_equal(Item *a, Item *b) {
 static int parse_line(const char *fname, unsigned line, const char *buffer) {
 
         static const Specifier specifier_table[] = {
-                { 'm', specifier_machine_id, NULL },
-                { 'b', specifier_boot_id, NULL },
-                { 'H', specifier_host_name, NULL },
+                { 'm', specifier_machine_id,     NULL },
+                { 'b', specifier_boot_id,        NULL },
+                { 'H', specifier_host_name,      NULL },
                 { 'v', specifier_kernel_release, NULL },
+                { 'T', specifier_tmp_dir,        NULL },
+                { 'V', specifier_var_tmp_dir,    NULL },
                 {}
         };
 
index 9a9cfdd8a28f9cc5011a4d655a8409369db8063e..049e24b8bd0b0fc33657cb9245729cb7fa1581e4 100644 (file)
@@ -179,10 +179,13 @@ static const Specifier specifier_table[] = {
         { 'U', specifier_user_id,         NULL },
         { 'u', specifier_user_name,       NULL },
         { 'h', specifier_user_home,       NULL },
+
         { 't', specifier_directory,       UINT_TO_PTR(DIRECTORY_RUNTIME) },
         { 'S', specifier_directory,       UINT_TO_PTR(DIRECTORY_STATE) },
         { 'C', specifier_directory,       UINT_TO_PTR(DIRECTORY_CACHE) },
         { 'L', specifier_directory,       UINT_TO_PTR(DIRECTORY_LOGS) },
+        { 'T', specifier_tmp_dir,         NULL },
+        { 'V', specifier_var_tmp_dir,     NULL },
         {}
 };
 
index 926d45182b17ede494e9eb296065012234614652..e46373ddfe7ce2678227066fb8a2abfaa1902f21 100644 (file)
@@ -16,6 +16,8 @@ ExecStart=test %t = /run
 ExecStart=test %S = /var/lib
 ExecStart=test %C = /var/cache
 ExecStart=test %L = /var/log
+ExecStart=test %T = /tmp
+ExecStart=test %V = /var/tmp
 ExecStart=sh -c 'test %u = $$(id -un 0)'
 ExecStart=test %U = 0
 ExecStart=sh -c 'test %h = $$(getent passwd 0 | cut -d: -f 6)'