From aecdef08be06d0881e0bc996361a46fe34dc9a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Oct 2020 17:57:03 +0200 Subject: [PATCH] shared/clean-ipc: improve error message a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Failed to enter shared memory directory multipath: Permission denied → Failed to enter shared memory directory /dev/shm/multipath: Permission denied When looking at nested directories, we will print only the final two elements of the path. That is still more useful than just the last component of the path. To print the full path, we'd have to allocate the string, and since the error occurs so very rarely, I think the current best-effort approach is enough. --- src/shared/clean-ipc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c index e4cd2d30d0..5d8f66c602 100644 --- a/src/shared/clean-ipc.c +++ b/src/shared/clean-ipc.c @@ -218,7 +218,7 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid, bool rm) { return ret; } -static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) { +static int clean_posix_shm_internal(const char *dirname, DIR *dir, uid_t uid, gid_t gid, bool rm) { struct dirent *de; int ret = 0, r; @@ -234,7 +234,8 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) { if (errno == ENOENT) continue; - ret = log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s: %m", de->d_name); + ret = log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s/%s: %m", + dirname, de->d_name); continue; } @@ -244,9 +245,10 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) { kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME); if (!kid) { if (errno != ENOENT) - ret = log_warning_errno(errno, "Failed to enter shared memory directory %s: %m", de->d_name); + ret = log_warning_errno(errno, "Failed to enter shared memory directory %s/%s: %m", + dirname, de->d_name); } else { - r = clean_posix_shm_internal(kid, uid, gid, rm); + r = clean_posix_shm_internal(de->d_name, kid, uid, gid, rm); if (r < 0) ret = r; } @@ -262,7 +264,8 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid, gid_t gid, bool rm) { if (errno == ENOENT) continue; - ret = log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s: %m", de->d_name); + ret = log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s/%s: %m", + dirname, de->d_name); } else { log_debug("Removed POSIX shared memory directory %s", de->d_name); if (ret == 0) @@ -307,7 +310,7 @@ static int clean_posix_shm(uid_t uid, gid_t gid, bool rm) { return log_warning_errno(errno, "Failed to open /dev/shm: %m"); } - return clean_posix_shm_internal(dir, uid, gid, rm); + return clean_posix_shm_internal("/dev/shm", dir, uid, gid, rm); } static int clean_posix_mq(uid_t uid, gid_t gid, bool rm) {