mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
tmpfiles: remove before creating when asked to do both
With both --create and --remove each entry was removed and then
created before the next one was read. An r entry took what an entry
above it had just created:
f /tmp/file - - - - new
r /tmp/file
tmpfiles --create --remove t.conf
This left no /tmp/file. The same goes for --clean.
Run all the files twice in that case, first to remove and clean, then
to create.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+95
-51
No files matched your search
@@ -249,6 +249,9 @@ All relevant changes are documented in this file.
|
|||||||
- Fix the argument of a tmpfiles entry written in aligned columns, the space
|
- Fix the argument of a tmpfiles entry written in aligned columns, the space
|
||||||
after the age field ended up in the argument, e.g. in the target of an `L`
|
after the age field ended up in the argument, e.g. in the target of an `L`
|
||||||
link. A lone `-` is now read as no argument
|
link. A lone `-` is now read as no argument
|
||||||
|
- Fix `tmpfiles --create --remove`, each entry was removed and created in
|
||||||
|
turn, so an `r` entry removed what an entry above it had just created.
|
||||||
|
All of the removing is now done first
|
||||||
- Fix a lost reload for a service paused mid-reload by a condition in
|
- Fix a lost reload for a service paused mid-reload by a condition in
|
||||||
flux. A second reload arriving meanwhile re-parsed the unchanged .conf
|
flux. A second reload arriving meanwhile re-parsed the unchanged .conf
|
||||||
and cleared the pending mark, so the service resumed without ever being
|
and cleared the pending mark, so the service resumed without ever being
|
||||||
|
|||||||
+63
-51
@@ -1073,6 +1073,62 @@ static void process_file(const char *fn)
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void process(int num, char *file[])
|
||||||
|
{
|
||||||
|
/* If config files specified on command line, process only those */
|
||||||
|
if (num) {
|
||||||
|
for (int i = 0; i < num; i++)
|
||||||
|
process_file(file[i]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No config files specified, process standard tmpfiles.d directories.
|
||||||
|
*
|
||||||
|
* Only the three last tmpfiles.d/ directories are defined in
|
||||||
|
* tmpfiles.d(5) as system search paths. Finit adds two more
|
||||||
|
* before that to have Finit specific ones sorted first, and
|
||||||
|
* a configure prefix specific one after that for user needs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* in priority order */
|
||||||
|
char *dir[] = {
|
||||||
|
FINIT_TMPFILES "/*.conf",
|
||||||
|
TMPFILES_PATH_ "/*.conf",
|
||||||
|
"/usr/lib/tmpfiles.d/*.conf",
|
||||||
|
"/run/tmpfiles.d/*.conf",
|
||||||
|
"/etc/tmpfiles.d/*.conf", /* local admin overrides */
|
||||||
|
};
|
||||||
|
int flags = GLOB_NOESCAPE;
|
||||||
|
glob_t gl;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < NELEMS(dir); i++) {
|
||||||
|
glob(dir[i], flags, NULL, &gl);
|
||||||
|
flags |= GLOB_APPEND;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < gl.gl_pathc; i++) {
|
||||||
|
char *fn = gl.gl_pathv[i];
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
/* check for overrides */
|
||||||
|
for (j = i + 1; j < gl.gl_pathc; j++) {
|
||||||
|
if (strcmp(basenm(fn), basenm(gl.gl_pathv[j])))
|
||||||
|
continue;
|
||||||
|
fn = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fn)
|
||||||
|
continue; /* skip, override exists */
|
||||||
|
|
||||||
|
process_file(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
globfree(&gl);
|
||||||
|
}
|
||||||
|
|
||||||
static int usage(int rc)
|
static int usage(int rc)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -1155,58 +1211,14 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If config files specified on command line, process only those */
|
/* Remove and clean first, or an r entry takes what an f entry above it made */
|
||||||
if (optind < argc) {
|
if (create_flag && (clean_flag || remove_flag)) {
|
||||||
for (int i = optind; i < argc; i++)
|
create_flag = 0;
|
||||||
process_file(argv[i]);
|
process(argc - optind, &argv[optind]);
|
||||||
return 0;
|
create_flag = 1;
|
||||||
|
clean_flag = remove_flag = 0;
|
||||||
}
|
}
|
||||||
|
process(argc - optind, &argv[optind]);
|
||||||
/*
|
|
||||||
* No config files specified, process standard tmpfiles.d directories.
|
|
||||||
*
|
|
||||||
* Only the three last tmpfiles.d/ directories are defined in
|
|
||||||
* tmpfiles.d(5) as system search paths. Finit adds two more
|
|
||||||
* before that to have Finit specific ones sorted first, and
|
|
||||||
* a configure prefix specific one after that for user needs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* in priority order */
|
|
||||||
char *dir[] = {
|
|
||||||
FINIT_TMPFILES "/*.conf",
|
|
||||||
TMPFILES_PATH_ "/*.conf",
|
|
||||||
"/usr/lib/tmpfiles.d/*.conf",
|
|
||||||
"/run/tmpfiles.d/*.conf",
|
|
||||||
"/etc/tmpfiles.d/*.conf", /* local admin overrides */
|
|
||||||
};
|
|
||||||
int flags = GLOB_NOESCAPE;
|
|
||||||
glob_t gl;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < NELEMS(dir); i++) {
|
|
||||||
glob(dir[i], flags, NULL, &gl);
|
|
||||||
flags |= GLOB_APPEND;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < gl.gl_pathc; i++) {
|
|
||||||
char *fn = gl.gl_pathv[i];
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
/* check for overrides */
|
|
||||||
for (j = i + 1; j < gl.gl_pathc; j++) {
|
|
||||||
if (strcmp(basenm(fn), basenm(gl.gl_pathv[j])))
|
|
||||||
continue;
|
|
||||||
fn = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fn)
|
|
||||||
continue; /* skip, override exists */
|
|
||||||
|
|
||||||
process_file(fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
globfree(&gl);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ EXTRA_DIST += testserv.sh
|
|||||||
EXTRA_DIST += tmpfiles-acl.sh
|
EXTRA_DIST += tmpfiles-acl.sh
|
||||||
EXTRA_DIST += tmpfiles-arg.sh
|
EXTRA_DIST += tmpfiles-arg.sh
|
||||||
EXTRA_DIST += tmpfiles-perm.sh
|
EXTRA_DIST += tmpfiles-perm.sh
|
||||||
|
EXTRA_DIST += tmpfiles-order.sh
|
||||||
EXTRA_DIST += unexpected-restart.sh
|
EXTRA_DIST += unexpected-restart.sh
|
||||||
EXTRA_DIST += dbus-auth.sh
|
EXTRA_DIST += dbus-auth.sh
|
||||||
EXTRA_DIST += dbus-authz.sh
|
EXTRA_DIST += dbus-authz.sh
|
||||||
@@ -164,6 +165,7 @@ TESTS += testserv.sh
|
|||||||
TESTS += tmpfiles-acl.sh
|
TESTS += tmpfiles-acl.sh
|
||||||
TESTS += tmpfiles-arg.sh
|
TESTS += tmpfiles-arg.sh
|
||||||
TESTS += tmpfiles-perm.sh
|
TESTS += tmpfiles-perm.sh
|
||||||
|
TESTS += tmpfiles-order.sh
|
||||||
endif
|
endif
|
||||||
TESTS += unexpected-restart.sh
|
TESTS += unexpected-restart.sh
|
||||||
if DBUS
|
if DBUS
|
||||||
|
|||||||
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Verify that tmpfiles removes before it creates when asked to do both
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
TEST_DIR=$(dirname "$0")
|
||||||
|
|
||||||
|
DIR=/tmp/order
|
||||||
|
CONF=/tmp/order.conf
|
||||||
|
|
||||||
|
test_teardown()
|
||||||
|
{
|
||||||
|
say "Running test teardown."
|
||||||
|
run "rm -rf $DIR $CONF"
|
||||||
|
}
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$TEST_DIR/lib/setup.sh"
|
||||||
|
|
||||||
|
run "cat > $CONF" <<CONF
|
||||||
|
d $DIR
|
||||||
|
f $DIR/file - - - - new
|
||||||
|
r $DIR/file
|
||||||
|
CONF
|
||||||
|
run "mkdir $DIR; echo old > $DIR/file"
|
||||||
|
run "/libexec/finit/tmpfiles --create --remove $CONF"
|
||||||
|
|
||||||
|
assert "The old file is removed, a new one created" "$(texec cat $DIR/file)" = "new"
|
||||||
Reference in new issue
Block a user