Blob Blame History Raw
From eada3a23db3aed6f679c8d5476618f33d4249cb7 Mon Sep 17 00:00:00 2001
From: Dave Reisner <dreisner@archlinux.org>
Date: Wed, 24 Jul 2013 11:10:05 -0400
Subject: [PATCH] tmpfiles: support passing --prefix multiple times

---
 man/systemd-tmpfiles.xml |  3 ++-
 src/tmpfiles/tmpfiles.c  | 24 +++++++++++++++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml
index 405a9f1..b0f2d9c 100644
--- a/man/systemd-tmpfiles.xml
+++ b/man/systemd-tmpfiles.xml
@@ -121,7 +121,8 @@
                                 <term><option>--prefix=PATH</option></term>
                                 <listitem><para>Only apply rules that
                                 apply to paths with the specified
-                                prefix.</para></listitem>
+                                prefix. This option can be specified
+                                multiple times.</para></listitem>
                         </varlistentry>
 
 
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index eae993e..cb15133 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -105,7 +105,7 @@ static bool arg_create = false;
 static bool arg_clean = false;
 static bool arg_remove = false;
 
-static const char *arg_prefix = NULL;
+static char **include_prefixes = NULL;
 
 static const char conf_file_dirs[] =
         "/etc/tmpfiles.d\0"
@@ -1018,6 +1018,21 @@ static bool item_equal(Item *a, Item *b) {
         return true;
 }
 
+static bool should_include_path(const char *path) {
+        char **prefix;
+
+        /* no explicit paths specified for inclusion, so everything is valid */
+        if (strv_length(include_prefixes) == 0)
+                return true;
+
+        STRV_FOREACH(prefix, include_prefixes) {
+                if (path_startswith(path, *prefix))
+                        return true;
+        }
+
+        return false;
+}
+
 static int parse_line(const char *fname, unsigned line, const char *buffer) {
         _cleanup_item_free_ Item *i = NULL;
         Item *existing;
@@ -1119,7 +1134,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
 
         path_kill_slashes(i->path);
 
-        if (arg_prefix && !path_startswith(i->path, arg_prefix))
+        if (!should_include_path(i->path))
                 return 0;
 
         if (user && !streq(user, "-")) {
@@ -1258,7 +1273,8 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_PREFIX:
-                        arg_prefix = optarg;
+                        if (strv_extend(&include_prefixes, optarg) < 0)
+                                return log_oom();
                         break;
 
                 case '?':
@@ -1423,6 +1439,8 @@ finish:
         hashmap_free(items);
         hashmap_free(globs);
 
+        strv_free(include_prefixes);
+
         set_free_free(unix_sockets);
 
         label_finish();