summaryrefslogtreecommitdiff
path: root/src/shared/dropin.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-02 12:17:20 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-02 12:17:20 -0500
commit17e78d1825bcc6cb9af25c9b1598ef32c82da6af (patch)
treec9afdf3f2dd2e2899975afed2a9684ad440ecfa9 /src/shared/dropin.c
parent3ef21542b20bc62760a423aebeebb4c9e014131c (diff)
systemctl: also use chase_symlinks for dropins
The general rule is: - code in shared/ should take an "original_root" argument (possibly NULL) and pass it along down to chase_symlinks - code in core/ should always use specify original_root==NULL, since we don't support running the manager from non-root directory - code in systemctl and other tools should pass arg_root. For any code that is called from tools which support --root, chase_symlinks must be used to look up paths.
Diffstat (limited to 'src/shared/dropin.c')
-rw-r--r--src/shared/dropin.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 3cbfe13f4c..06cf3de620 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -29,6 +29,7 @@
#include "escape.h"
#include "fd-util.h"
#include "fileio-label.h"
+#include "fs-util.h"
#include "hashmap.h"
#include "log.h"
#include "macro.h"
@@ -118,38 +119,46 @@ int write_drop_in_format(const char *dir, const char *unit, unsigned level,
static int iterate_dir(
const char *path,
+ const char *original_root,
UnitDependency dependency,
dependency_consumer_t consumer,
void *arg,
char ***strv) {
+ _cleanup_free_ char *chased = NULL;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r;
assert(path);
+ r = chase_symlinks(path, original_root, 0, &chased);
+ if (r < 0)
+ return log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING,
+ r, "Failed to canonicalize path %s: %m", path);
+
/* The config directories are special, since the order of the
* drop-ins matters */
if (dependency < 0) {
- r = strv_extend(strv, path);
+ r = strv_push(strv, chased);
if (r < 0)
return log_oom();
+ chased = NULL;
return 0;
}
assert(consumer);
- d = opendir(path);
+ d = opendir(chased);
if (!d) {
if (errno == ENOENT)
return 0;
- return log_error_errno(errno, "Failed to open directory %s: %m", path);
+ return log_warning_errno(errno, "Failed to open directory %s: %m", path);
}
- FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read directory %s: %m", path)) {
+ FOREACH_DIRENT(de, d, return log_warning_errno(errno, "Failed to read directory %s: %m", path)) {
_cleanup_free_ char *f = NULL;
f = strjoin(path, "/", de->d_name);
@@ -165,6 +174,7 @@ static int iterate_dir(
}
int unit_file_process_dir(
+ const char *original_root,
Set *unit_path_cache,
const char *unit_path,
const char *name,
@@ -186,7 +196,7 @@ int unit_file_process_dir(
return log_oom();
if (!unit_path_cache || set_get(unit_path_cache, path))
- (void) iterate_dir(path, dependency, consumer, arg, strv);
+ (void) iterate_dir(path, original_root, dependency, consumer, arg, strv);
if (unit_name_is_valid(name, UNIT_NAME_INSTANCE)) {
_cleanup_free_ char *template = NULL, *p = NULL;
@@ -201,13 +211,14 @@ int unit_file_process_dir(
return log_oom();
if (!unit_path_cache || set_get(unit_path_cache, p))
- (void) iterate_dir(p, dependency, consumer, arg, strv);
+ (void) iterate_dir(p, original_root, dependency, consumer, arg, strv);
}
return 0;
}
int unit_file_find_dropin_paths(
+ const char *original_root,
char **lookup_path,
Set *unit_path_cache,
Set *names,
@@ -224,7 +235,8 @@ int unit_file_find_dropin_paths(
char **p;
STRV_FOREACH(p, lookup_path)
- unit_file_process_dir(unit_path_cache, *p, t, ".d", _UNIT_DEPENDENCY_INVALID, NULL, NULL, &strv);
+ unit_file_process_dir(original_root, unit_path_cache, *p, t, ".d",
+ _UNIT_DEPENDENCY_INVALID, NULL, NULL, &strv);
}
if (strv_isempty(strv))