mirror of
https://github.com/clearlinux/systemd-stable.git
synced 2026-09-06 13:41:31 +00:00
tmpfiles: introduce --exclude-prefix
The opposite of --prefix, allows specifying path prefixes which should be skipped when processing rules.
This commit is contained in:
@@ -124,6 +124,13 @@
|
|||||||
prefix. This option can be specified
|
prefix. This option can be specified
|
||||||
multiple times.</para></listitem>
|
multiple times.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--exclude-prefix=PATH</option></term>
|
||||||
|
<listitem><para>Ignore rules that
|
||||||
|
apply to paths with the specified
|
||||||
|
prefix. This option can be specified
|
||||||
|
multiple times.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ _ctls()
|
|||||||
'--clean[Clean up all files and directories with an age parameter configured.]' \
|
'--clean[Clean up all files and directories with an age parameter configured.]' \
|
||||||
'--remove[All files and directories marked with r, R in the configuration files are removed.]' \
|
'--remove[All files and directories marked with r, R in the configuration files are removed.]' \
|
||||||
'--prefix=[Only apply rules that apply to paths with the specified prefix.]' \
|
'--prefix=[Only apply rules that apply to paths with the specified prefix.]' \
|
||||||
|
'--exclude-prefix=[Ignore rules that apply to paths with the specified prefix.]' \
|
||||||
'--help[Prints a short help text and exits.]' \
|
'--help[Prints a short help text and exits.]' \
|
||||||
'*::files:_files'
|
'*::files:_files'
|
||||||
;;
|
;;
|
||||||
|
|||||||
+28
-16
@@ -106,6 +106,7 @@ static bool arg_clean = false;
|
|||||||
static bool arg_remove = false;
|
static bool arg_remove = false;
|
||||||
|
|
||||||
static char **include_prefixes = NULL;
|
static char **include_prefixes = NULL;
|
||||||
|
static char **exclude_prefixes = NULL;
|
||||||
|
|
||||||
static const char conf_file_dirs[] =
|
static const char conf_file_dirs[] =
|
||||||
"/etc/tmpfiles.d\0"
|
"/etc/tmpfiles.d\0"
|
||||||
@@ -1021,16 +1022,19 @@ static bool item_equal(Item *a, Item *b) {
|
|||||||
static bool should_include_path(const char *path) {
|
static bool should_include_path(const char *path) {
|
||||||
char **prefix;
|
char **prefix;
|
||||||
|
|
||||||
/* no explicit paths specified for inclusion, so everything is valid */
|
STRV_FOREACH(prefix, exclude_prefixes) {
|
||||||
if (strv_length(include_prefixes) == 0)
|
if (path_startswith(path, *prefix))
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
STRV_FOREACH(prefix, include_prefixes) {
|
STRV_FOREACH(prefix, include_prefixes) {
|
||||||
if (path_startswith(path, *prefix))
|
if (path_startswith(path, *prefix))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
/* no matches, so we should include this path only if we
|
||||||
|
* have no whitelist at all */
|
||||||
|
return strv_length(include_prefixes) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
||||||
@@ -1219,11 +1223,12 @@ static int help(void) {
|
|||||||
|
|
||||||
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
|
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
|
||||||
"Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
|
"Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
|
||||||
" -h --help Show this help\n"
|
" -h --help Show this help\n"
|
||||||
" --create Create marked files/directories\n"
|
" --create Create marked files/directories\n"
|
||||||
" --clean Clean up marked directories\n"
|
" --clean Clean up marked directories\n"
|
||||||
" --remove Remove marked files/directories\n"
|
" --remove Remove marked files/directories\n"
|
||||||
" --prefix=PATH Only apply rules that apply to paths with the specified prefix\n",
|
" --prefix=PATH Only apply rules that apply to paths with the specified prefix\n"
|
||||||
|
" --exclude-prefix=PATH Ignore rules that apply to paths with the specified prefix\n",
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1235,16 +1240,18 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
ARG_CREATE,
|
ARG_CREATE,
|
||||||
ARG_CLEAN,
|
ARG_CLEAN,
|
||||||
ARG_REMOVE,
|
ARG_REMOVE,
|
||||||
ARG_PREFIX
|
ARG_PREFIX,
|
||||||
|
ARG_EXCLUDE_PREFIX,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "create", no_argument, NULL, ARG_CREATE },
|
{ "create", no_argument, NULL, ARG_CREATE },
|
||||||
{ "clean", no_argument, NULL, ARG_CLEAN },
|
{ "clean", no_argument, NULL, ARG_CLEAN },
|
||||||
{ "remove", no_argument, NULL, ARG_REMOVE },
|
{ "remove", no_argument, NULL, ARG_REMOVE },
|
||||||
{ "prefix", required_argument, NULL, ARG_PREFIX },
|
{ "prefix", required_argument, NULL, ARG_PREFIX },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ "exclude-prefix", required_argument, NULL, ARG_EXCLUDE_PREFIX },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
@@ -1277,6 +1284,11 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return log_oom();
|
return log_oom();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ARG_EXCLUDE_PREFIX:
|
||||||
|
if (strv_extend(&exclude_prefixes, optarg) < 0)
|
||||||
|
return log_oom();
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user