From a9dd208208e672a4fe5a3c2405946c1506e034db Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 28 Apr 2011 04:55:05 +0200 Subject: [PATCH] lookup: drop empty directories from search paths --- TODO | 2 -- src/path-lookup.c | 4 ++++ src/util.c | 20 ++++++++++++++++++++ src/util.h | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 106ee974d..d5479b501 100644 --- a/TODO +++ b/TODO @@ -34,8 +34,6 @@ Features: * Maybe merge nss-myhostname into systemd? -* ensure we strip empty directories from search path - * GC unreferenced jobs (such as .device jobs) * support wildcard expansion in ListenStream= and friends diff --git a/src/path-lookup.c b/src/path-lookup.c index b39ce8b69..b1c69814c 100644 --- a/src/path-lookup.c +++ b/src/path-lookup.c @@ -205,6 +205,7 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { return -ENOMEM; strv_uniq(p->unit_path); + strv_path_remove_empty(p->unit_path); if (!strv_isempty(p->unit_path)) { @@ -259,6 +260,9 @@ int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as) { strv_uniq(p->sysvinit_path); strv_uniq(p->sysvrcnd_path); + strv_path_remove_empty(p->sysvinit_path); + strv_path_remove_empty(p->sysvrcnd_path); + if (!strv_isempty(p->sysvinit_path)) { if (!(t = strv_join(p->sysvinit_path, "\n\t"))) diff --git a/src/util.c b/src/util.c index 5029896ef..6037455f7 100644 --- a/src/util.c +++ b/src/util.c @@ -1209,6 +1209,26 @@ char **strv_path_canonicalize(char **l) { return l; } +char **strv_path_remove_empty(char **l) { + char **f, **t; + + if (!l) + return NULL; + + for (f = t = l; *f; f++) { + + if (dir_is_empty(*f) > 0) { + free(*f); + continue; + } + + *(t++) = *f; + } + + *t = NULL; + return l; +} + int reset_all_signal_handlers(void) { int sig; diff --git a/src/util.h b/src/util.h index 7fa488b0f..ff2947450 100644 --- a/src/util.h +++ b/src/util.h @@ -224,6 +224,7 @@ char *path_make_absolute_cwd(const char *p); char **strv_path_make_absolute_cwd(char **l); char **strv_path_canonicalize(char **l); +char **strv_path_remove_empty(char **l); int reset_all_signal_handlers(void); -- 2.30.2