ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Harald Hoyer fe20ad
From eada3a23db3aed6f679c8d5476618f33d4249cb7 Mon Sep 17 00:00:00 2001
Harald Hoyer fe20ad
From: Dave Reisner <dreisner@archlinux.org>
Harald Hoyer fe20ad
Date: Wed, 24 Jul 2013 11:10:05 -0400
Harald Hoyer fe20ad
Subject: [PATCH] tmpfiles: support passing --prefix multiple times
Harald Hoyer fe20ad
Harald Hoyer fe20ad
---
Harald Hoyer fe20ad
 man/systemd-tmpfiles.xml |  3 ++-
Harald Hoyer fe20ad
 src/tmpfiles/tmpfiles.c  | 24 +++++++++++++++++++++---
Harald Hoyer fe20ad
 2 files changed, 23 insertions(+), 4 deletions(-)
Harald Hoyer fe20ad
Harald Hoyer fe20ad
diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml
Harald Hoyer fe20ad
index 405a9f1..b0f2d9c 100644
Harald Hoyer fe20ad
--- a/man/systemd-tmpfiles.xml
Harald Hoyer fe20ad
+++ b/man/systemd-tmpfiles.xml
Harald Hoyer fe20ad
@@ -121,7 +121,8 @@
Harald Hoyer fe20ad
                                 <term><option>--prefix=PATH</option></term>
Harald Hoyer fe20ad
                                 <listitem><para>Only apply rules that
Harald Hoyer fe20ad
                                 apply to paths with the specified
Harald Hoyer fe20ad
-                                prefix.</para></listitem>
Harald Hoyer fe20ad
+                                prefix. This option can be specified
Harald Hoyer fe20ad
+                                multiple times.</para></listitem>
Harald Hoyer fe20ad
                         </varlistentry>
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
Harald Hoyer fe20ad
index eae993e..cb15133 100644
Harald Hoyer fe20ad
--- a/src/tmpfiles/tmpfiles.c
Harald Hoyer fe20ad
+++ b/src/tmpfiles/tmpfiles.c
Harald Hoyer fe20ad
@@ -105,7 +105,7 @@ static bool arg_create = false;
Harald Hoyer fe20ad
 static bool arg_clean = false;
Harald Hoyer fe20ad
 static bool arg_remove = false;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-static const char *arg_prefix = NULL;
Harald Hoyer fe20ad
+static char **include_prefixes = NULL;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
 static const char conf_file_dirs[] =
Harald Hoyer fe20ad
         "/etc/tmpfiles.d\0"
Harald Hoyer fe20ad
@@ -1018,6 +1018,21 @@ static bool item_equal(Item *a, Item *b) {
Harald Hoyer fe20ad
         return true;
Harald Hoyer fe20ad
 }
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
+static bool should_include_path(const char *path) {
Harald Hoyer fe20ad
+        char **prefix;
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
+        /* no explicit paths specified for inclusion, so everything is valid */
Harald Hoyer fe20ad
+        if (strv_length(include_prefixes) == 0)
Harald Hoyer fe20ad
+                return true;
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
+        STRV_FOREACH(prefix, include_prefixes) {
Harald Hoyer fe20ad
+                if (path_startswith(path, *prefix))
Harald Hoyer fe20ad
+                        return true;
Harald Hoyer fe20ad
+        }
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
+        return false;
Harald Hoyer fe20ad
+}
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
 static int parse_line(const char *fname, unsigned line, const char *buffer) {
Harald Hoyer fe20ad
         _cleanup_item_free_ Item *i = NULL;
Harald Hoyer fe20ad
         Item *existing;
Harald Hoyer fe20ad
@@ -1119,7 +1134,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         path_kill_slashes(i->path);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
-        if (arg_prefix && !path_startswith(i->path, arg_prefix))
Harald Hoyer fe20ad
+        if (!should_include_path(i->path))
Harald Hoyer fe20ad
                 return 0;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         if (user && !streq(user, "-")) {
Harald Hoyer fe20ad
@@ -1258,7 +1273,8 @@ static int parse_argv(int argc, char *argv[]) {
Harald Hoyer fe20ad
                         break;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
                 case ARG_PREFIX:
Harald Hoyer fe20ad
-                        arg_prefix = optarg;
Harald Hoyer fe20ad
+                        if (strv_extend(&include_prefixes, optarg) < 0)
Harald Hoyer fe20ad
+                                return log_oom();
Harald Hoyer fe20ad
                         break;
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
                 case '?':
Harald Hoyer fe20ad
@@ -1423,6 +1439,8 @@ finish:
Harald Hoyer fe20ad
         hashmap_free(items);
Harald Hoyer fe20ad
         hashmap_free(globs);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
+        strv_free(include_prefixes);
Harald Hoyer fe20ad
+
Harald Hoyer fe20ad
         set_free_free(unix_sockets);
Harald Hoyer fe20ad
 
Harald Hoyer fe20ad
         label_finish();