1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-21 02:50:18 +03:00

shared/unit-files: only put valid unit paths and dropin dirs in the cache

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-08-30 14:10:42 +02:00
parent 29a45fe5aa
commit 890befcf47
2 changed files with 22 additions and 1 deletions

View 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; \

View 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, '.'));