From 113ed3be37ef788497ed3b84a792099441b94da4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Jun 2019 12:41:02 +0200 Subject: [PATCH 1/3] tmpfiles: use path_join() where we can --- src/tmpfiles/tmpfiles.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index eabc51101d9..a3c6847de0d 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -563,7 +563,7 @@ static int dir_cleanup( continue; } - sub_path = strjoin(p, "/", dent->d_name); + sub_path = path_join(p, dent->d_name); if (!sub_path) { r = log_oom(); goto finish; From 20b6bb9560e6e9afb2688faea5324e8d192666be Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Jun 2019 12:41:31 +0200 Subject: [PATCH 2/3] tmpfiles: merge two nested if checks into one --- src/tmpfiles/tmpfiles.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index a3c6847de0d..321edb3034f 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -656,14 +656,16 @@ static int dir_cleanup( continue; } - if (mountpoint && S_ISREG(s.st_mode)) - if (s.st_uid == 0 && STR_IN_SET(dent->d_name, - ".journal", - "aquota.user", - "aquota.group")) { - log_debug("Skipping \"%s\".", sub_path); - continue; - } + if (mountpoint && + S_ISREG(s.st_mode) && + s.st_uid == 0 && + STR_IN_SET(dent->d_name, + ".journal", + "aquota.user", + "aquota.group")) { + log_debug("Skipping \"%s\".", sub_path); + continue; + } /* Ignore sockets that are listed in /proc/net/unix */ if (S_ISSOCK(s.st_mode) && unix_socket_alive(sub_path)) { From 60bdc0ca225534c695190e24e016fea7324919d8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Jun 2019 12:42:30 +0200 Subject: [PATCH 3/3] tmpfiles: use common fd_is_mount_point() implementation in tmpfiles.c No need to have a private reimplementation here. Let's just use the common one, which supports "fdinfo" as fallback. --- src/tmpfiles/tmpfiles.c | 46 +++++++++-------------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 321edb3034f..b859d94b921 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -461,38 +461,6 @@ static bool unix_socket_alive(const char *fn) { return !!set_get(unix_sockets, (char*) fn); } -static int dir_is_mount_point(DIR *d, const char *subdir) { - - int mount_id_parent, mount_id; - int r_p, r; - - r_p = name_to_handle_at_loop(dirfd(d), ".", NULL, &mount_id_parent, 0); - if (r_p < 0) - r_p = -errno; - - r = name_to_handle_at_loop(dirfd(d), subdir, NULL, &mount_id, 0); - if (r < 0) - r = -errno; - - /* got no handle; make no assumptions, return error */ - if (r_p < 0 && r < 0) - return r_p; - - /* got both handles; if they differ, it is a mount point */ - if (r_p >= 0 && r >= 0) - return mount_id_parent != mount_id; - - /* got only one handle; assume different mount points if one - * of both queries was not supported by the filesystem */ - if (IN_SET(r_p, -ENOSYS, -EOPNOTSUPP) || IN_SET(r, -ENOSYS, -EOPNOTSUPP)) - return true; - - /* return error */ - if (r_p < 0) - return r_p; - return r; -} - static DIR* xopendirat_nomod(int dirfd, const char *path) { DIR *dir; @@ -557,10 +525,16 @@ static int dir_cleanup( /* Try to detect bind mounts of the same filesystem instance; they * do not differ in device major/minors. This type of query is not * supported on all kernels or filesystem types though. */ - if (S_ISDIR(s.st_mode) && dir_is_mount_point(d, dent->d_name) > 0) { - log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.", - p, dent->d_name); - continue; + if (S_ISDIR(s.st_mode)) { + int q; + + q = fd_is_mount_point(dirfd(d), dent->d_name, 0); + if (q < 0) + log_debug_errno(q, "Failed to determine whether \"%s/%s\" is a mount point, ignoring: %m", p, dent->d_name); + else if (q > 0) { + log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.", p, dent->d_name); + continue; + } } sub_path = path_join(p, dent->d_name);