]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/unit-files: only put valid unit paths and dropin dirs in the cache 13436/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 30 Aug 2019 12:10:42 +0000 (14:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 30 Aug 2019 12:10:42 +0000 (14:10 +0200)
src/basic/strv.h
src/shared/unit-file.c

index e80964acd17bcee0f70fc226c2408b9be88aa514..fbfa96a566589d7da35db2eb8ccc4bc05aeff8b2 100644 (file)
@@ -157,6 +157,18 @@ void strv_print(char **l);
                 _found;                                         \
         })
 
+#define ENDSWITH_SET(p, ...)                                    \
+        ({                                                      \
+                const char *_p = (p);                           \
+                char  *_found = NULL, **_i;                     \
+                STRV_FOREACH(_i, STRV_MAKE(__VA_ARGS__)) {      \
+                        _found = endswith(_p, *_i);             \
+                        if (_found)                             \
+                                break;                          \
+                }                                               \
+                _found;                                         \
+        })
+
 #define FOREACH_STRING(x, y, ...)                                       \
         for (char **_l = STRV_MAKE(({ x = y; }), ##__VA_ARGS__);        \
              x;                                                         \
index b9b5268d0a60f30b0c4bbb31cd337c1632f07b5a..4a5f23e6c1bcbb0e76ffe9a508d661022fc98189 100644 (file)
@@ -246,6 +246,15 @@ int unit_file_build_name_map(
                         char *filename;
                         _cleanup_free_ char *_filename_free = NULL, *simplified = NULL;
                         const char *suffix, *dst = NULL;
+                        bool valid_unit_name;
+
+                        valid_unit_name = unit_name_is_valid(de->d_name, UNIT_NAME_ANY);
+
+                        /* We only care about valid units and dirs with certain suffixes, let's ignore the
+                         * rest. */
+                        if (!valid_unit_name &&
+                            !ENDSWITH_SET(de->d_name, ".wants", ".requires", ".d"))
+                                continue;
 
                         filename = path_join(*dir, de->d_name);
                         if (!filename)
@@ -260,7 +269,7 @@ int unit_file_build_name_map(
                         } else
                                 _filename_free = filename; /* Make sure we free the filename. */
 
-                        if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
+                        if (!valid_unit_name)
                                 continue;
                         assert_se(suffix = strrchr(de->d_name, '.'));