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
+63
-51
@@ -1073,6 +1073,62 @@ static void process_file(const char *fn)
|
||||
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)
|
||||
{
|
||||
fprintf(stderr,
|
||||
@@ -1155,58 +1211,14 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* If config files specified on command line, process only those */
|
||||
if (optind < argc) {
|
||||
for (int i = optind; i < argc; i++)
|
||||
process_file(argv[i]);
|
||||
return 0;
|
||||
/* Remove and clean first, or an r entry takes what an f entry above it made */
|
||||
if (create_flag && (clean_flag || remove_flag)) {
|
||||
create_flag = 0;
|
||||
process(argc - optind, &argv[optind]);
|
||||
create_flag = 1;
|
||||
clean_flag = remove_flag = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
process(argc - optind, &argv[optind]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user