core: introduce specifiers for /tmp and /var/tmp

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).
This commit is contained in:
Lennart Poettering
2018-05-29 11:39:15 +02:00
parent 709f4c472c
commit b294e5943f
8 changed files with 73 additions and 3 deletions
+35
View 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;