mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: let %T and %V follow $TMPDIR
The %T and %V specifiers are always /tmp and /var/tmp. In systemd both are the first of $TMPDIR, $TEMP, and $TMP that is set to an absolute path of a directory, and only otherwise /tmp and /var/tmp. Do the same. At boot none of them are set, so nothing changes there. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+29
-4
No files matched your search
@@ -38,6 +38,8 @@ All relevant changes are documented in this file.
|
||||
each below a line with its name
|
||||
- tmpfiles: add `--graceful`, for scripts that give it. It changes
|
||||
nothing, an unknown user or group is never an error in Finit
|
||||
- tmpfiles: the `%T` and `%V` specifiers now follow `$TMPDIR`, `$TEMP`,
|
||||
or `$TMP`, when set to a directory
|
||||
- tmpfiles: add `--prefix=PATH`, to only run the entries for paths below
|
||||
it. `--prefix` and `--exclude-prefix` match whole path components,
|
||||
`--exclude-prefix=/dev` no longer skips `/devices`
|
||||
|
||||
@@ -35,6 +35,4 @@ Missing options: `--root`, `--replace`, and `--purge`.
|
||||
left as it is, with a warning
|
||||
* An `x` or `X` entry with an age should have what it names cleaned
|
||||
by that age, the age is not read
|
||||
* The `%T` and `%V` specifiers are always `/tmp` and `/var/tmp`, they
|
||||
do not look at `$TMPDIR`
|
||||
* `mksubsys()` in `src/util.c` is unused
|
||||
+17
-2
@@ -1297,6 +1297,21 @@ static const char *specifier_arch(const char *machine)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* As in systemd, the first of these that names a directory */
|
||||
static const char *specifier_tmp(const char *fallback)
|
||||
{
|
||||
static const char *env[] = { "TMPDIR", "TEMP", "TMP" };
|
||||
|
||||
for (size_t i = 0; i < NELEMS(env); i++) {
|
||||
const char *dir = getenv(env[i]);
|
||||
|
||||
if (dir && dir[0] == '/' && fisdir(dir))
|
||||
return dir;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/*
|
||||
* The % specifiers of tmpfiles.d(5). tmpfiles runs as root, so the
|
||||
* user ones are fixed. Returns NULL for one that is unknown or has
|
||||
@@ -1315,10 +1330,10 @@ static const char *specifier(char c, char *buf, size_t len)
|
||||
case 'L': return "/var/log";
|
||||
case 'S': return "/var/lib";
|
||||
case 't': return "/run";
|
||||
case 'T': return "/tmp";
|
||||
case 'T': return specifier_tmp("/tmp");
|
||||
case 'u': return "root";
|
||||
case 'U': return "0";
|
||||
case 'V': return "/var/tmp";
|
||||
case 'V': return specifier_tmp("/var/tmp");
|
||||
case 'b':
|
||||
specifier_file("/proc/sys/kernel/random/boot_id", "-", buf, len);
|
||||
break;
|
||||
|
||||
@@ -50,3 +50,13 @@ assert "Skipped: a lone % and an unknown specifier" "$(texec sh -c "ls $DIR | gr
|
||||
assert "OS ID and version" "$(texec ls $DIR/os-finit-test-1.2)" = "$DIR/os-finit-test-1.2"
|
||||
assert "Architecture" "$(texec sh -c "ls $DIR | grep -c '^arch-.'")" = "1"
|
||||
assert "Empty when not in os-release" "$(texec ls $DIR/variant-)" = "$DIR/variant-"
|
||||
|
||||
sep
|
||||
say "%T and %V follow \$TMPDIR when it is a directory"
|
||||
run "cat > $CONF" <<CONF
|
||||
f $DIR/tmpdir - - - - %T %V
|
||||
CONF
|
||||
run "TMPDIR=$DIR /libexec/finit/tmpfiles --create $CONF"
|
||||
assert "From the environment" "$(texec cat $DIR/tmpdir)" = "$DIR $DIR"
|
||||
run "rm $DIR/tmpdir; TMPDIR=/no/such/dir /libexec/finit/tmpfiles --create $CONF"
|
||||
assert "Not a directory" "$(texec cat $DIR/tmpdir)" = "/tmp /var/tmp"
|
||||
Reference in new issue
Block a user