[systemd-devel] [PATCH 2/2] tmpfiles: introduce --exclude-prefix

Dave Reisner dreisner at archlinux.org
Wed Jul 24 08:25:51 PDT 2013


The opposite of --prefix, allows specifying path prefixes which should
be skipped when processing rules.
---
 man/systemd-tmpfiles.xml                    |  7 ++++
 shell-completion/systemd-zsh-completion.zsh |  1 +
 src/tmpfiles/tmpfiles.c                     | 50 +++++++++++++++++++++--------
 3 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml
index b0f2d9c..403592d 100644
--- a/man/systemd-tmpfiles.xml
+++ b/man/systemd-tmpfiles.xml
@@ -124,6 +124,13 @@
                                 prefix. This option can be specified
                                 multiple times.</para></listitem>
                         </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>
diff --git a/shell-completion/systemd-zsh-completion.zsh b/shell-completion/systemd-zsh-completion.zsh
index b62b6df..1ab1311 100644
--- a/shell-completion/systemd-zsh-completion.zsh
+++ b/shell-completion/systemd-zsh-completion.zsh
@@ -249,6 +249,7 @@ _ctls()
                 '--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.]' \
                 '--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.]' \
                 '*::files:_files'
         ;;
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index cb15133..bc001ac 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -106,6 +106,7 @@ static bool arg_clean = false;
 static bool arg_remove = false;
 
 static char **include_prefixes = NULL;
+static char **exclude_prefixes = NULL;
 
 static const char conf_file_dirs[] =
         "/etc/tmpfiles.d\0"
@@ -1018,6 +1019,21 @@ static bool item_equal(Item *a, Item *b) {
         return true;
 }
 
+static bool should_exclude_path(const char *path) {
+        char **prefix;
+
+        /* no explicit paths specified for exclusion, so everything is valid */
+        if (strv_length(exclude_prefixes) == 0)
+                return false;
+
+        STRV_FOREACH(prefix, exclude_prefixes) {
+                if (path_startswith(path, *prefix))
+                        return true;
+        }
+
+        return false;
+}
+
 static bool should_include_path(const char *path) {
         char **prefix;
 
@@ -1134,7 +1150,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
 
         path_kill_slashes(i->path);
 
-        if (!should_include_path(i->path))
+        if (should_exclude_path(i->path) || !should_include_path(i->path))
                 return 0;
 
         if (user && !streq(user, "-")) {
@@ -1219,11 +1235,12 @@ static int help(void) {
 
         printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
                "Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
-               "  -h --help             Show this help\n"
-               "     --create           Create marked files/directories\n"
-               "     --clean            Clean up marked directories\n"
-               "     --remove           Remove marked files/directories\n"
-               "     --prefix=PATH      Only apply rules that apply to paths with the specified prefix\n",
+               "  -h --help                 Show this help\n"
+               "     --create               Create marked files/directories\n"
+               "     --clean                Clean up marked directories\n"
+               "     --remove               Remove marked files/directories\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);
 
         return 0;
@@ -1235,16 +1252,18 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_CREATE,
                 ARG_CLEAN,
                 ARG_REMOVE,
-                ARG_PREFIX
+                ARG_PREFIX,
+                ARG_SKIP_PREFIX,
         };
 
         static const struct option options[] = {
-                { "help",      no_argument,       NULL, 'h'           },
-                { "create",    no_argument,       NULL, ARG_CREATE    },
-                { "clean",     no_argument,       NULL, ARG_CLEAN     },
-                { "remove",    no_argument,       NULL, ARG_REMOVE    },
-                { "prefix",    required_argument, NULL, ARG_PREFIX    },
-                { NULL,        0,                 NULL, 0             }
+                { "help",           no_argument,         NULL, 'h'             },
+                { "create",         no_argument,         NULL, ARG_CREATE      },
+                { "clean",          no_argument,         NULL, ARG_CLEAN       },
+                { "remove",         no_argument,         NULL, ARG_REMOVE      },
+                { "prefix",         required_argument,   NULL, ARG_PREFIX      },
+                { "exclude-prefix", required_argument,   NULL, ARG_SKIP_PREFIX },
+                { NULL,             0,                   NULL, 0               }
         };
 
         int c;
@@ -1277,6 +1296,11 @@ static int parse_argv(int argc, char *argv[]) {
                                 return log_oom();
                         break;
 
+                case ARG_SKIP_PREFIX:
+                        if (strv_extend(&exclude_prefixes, optarg) < 0)
+                                return log_oom();
+                        break;
+
                 case '?':
                         return -EINVAL;
 
-- 
1.8.3.3



More information about the systemd-devel mailing list