From 7ddc01a5e03ccb068382aa1df9934591ec9824fb Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 4 Dec 2017 11:36:17 +0100 Subject: [PATCH 1/3] delta: check if a prefix needs to be skipped only once The condition is already tested later by process_fix() therefore there's no need the check in process_suffix_chop() since it will end up calling process_fix() anyways. --- src/delta/delta.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/delta/delta.c b/src/delta/delta.c index d286881698..f626537438 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -520,13 +520,6 @@ static int process_suffix_chop(const char *arg) { /* Strip prefix from the suffix */ NULSTR_FOREACH(p, prefixes) { const char *suffix; - int skip; - - skip = should_skip_prefix(p); - if (skip < 0) - return skip; - if (skip) - continue; suffix = startswith(arg, p); if (suffix) { From 4cc893e742d0e4f0e29f383f0a29f44ef0a2e7b8 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 4 Dec 2017 09:36:22 +0100 Subject: [PATCH 2/3] delta: extend skip logic to work on full directory paths (prefix+suffix) Rather than only checking that a prefix path is a symlink to another prefix path (this can happen with split-usr=true and /lib a symlink to /usr/lib), extend the logic in should_skip_prefix() so that the check is done on the full directory path (prefix + suffix). This allows to catch such cases as well: # ls -ld /lib /lib/udev drwxr-xr-x 1 root root 86 Nov 22 13:14 /lib lrwxrwxrwx 1 root root 13 Sep 4 17:47 /lib/udev -> /usr/lib/udev where prefix=/lib and suffix=udev/rules.d --- src/delta/delta.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/delta/delta.c b/src/delta/delta.c index f626537438..6d99d75d3d 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -392,19 +392,28 @@ static int enumerate_dir( return 0; } -static int should_skip_prefix(const char* p) { +static bool should_skip_path(const char *prefix, const char *suffix) { #if HAVE_SPLIT_USR - int r; _cleanup_free_ char *target = NULL; + const char *p; + char *dirname; - r = chase_symlinks(p, NULL, 0, &target); - if (r < 0) - return r; + dirname = strjoina(prefix, "/", suffix); - return !streq(p, target) && nulstr_contains(prefixes, target); -#else - return 0; + if (chase_symlinks(dirname, NULL, 0, &target) < 0) + return false; + + NULSTR_FOREACH(p, prefixes) { + if (path_startswith(dirname, p)) + continue; + + if (path_equal(target, strjoina(p, "/", suffix))) { + log_debug("%s redirects to %s, skipping.", dirname, target); + return true; + } + } #endif + return false; } static int process_suffix(const char *suffix, const char *onlyprefix) { @@ -434,14 +443,8 @@ static int process_suffix(const char *suffix, const char *onlyprefix) { NULSTR_FOREACH(p, prefixes) { _cleanup_free_ char *t = NULL; - int skip; - skip = should_skip_prefix(p); - if (skip < 0) { - r = skip; - goto finish; - } - if (skip) + if (should_skip_path(p, suffix)) continue; t = strjoin(p, "/", suffix); From a9d041fa47bed53cc324462726af20007a72ad27 Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Thu, 7 Dec 2017 21:17:56 +0100 Subject: [PATCH 3/3] delta: don't ignore PREFIX when the given argument is PREFIX/SUFFIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch, when systemd-delta was asked for overwritten configuration files in a directory specified by PREFIX/SUFFIX, it ignored the given PREFIX and listed all overwritten files matching the subdirectory specified by SUFFIX. Hence we could get the following: $ ./build/systemd-delta /usr/local/lib/systemd/system [REDIRECTED] /etc/systemd/system/default.target → /usr/lib/systemd/system/default.target [EXTENDED] /usr/lib/systemd/system/systemd-sysctl.service → /usr/lib/systemd/system/systemd-sysctl.service.d/50-kernel-uname_r.conf systemd-delta showed overwritten configuration files in /usr/lib whereas only overwritten ones in /usr/local/lib should have been reported (none in my case). With the patch applied, we now get: $ ./build/systemd-delta /usr/local/lib/systemd/system 0 overridden configuration files found. --- src/delta/delta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/delta/delta.c b/src/delta/delta.c index 6d99d75d3d..9c8841d46d 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -528,7 +528,7 @@ static int process_suffix_chop(const char *arg) { if (suffix) { suffix += strspn(suffix, "/"); if (*suffix) - return process_suffix(suffix, NULL); + return process_suffix(suffix, p); else return process_suffixes(arg); }