1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-26 03:22:00 +03:00

shared/clean-ipc: improve error message a bit

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-10-20 17:57:03 +02:00
parent c4b843473a
commit aecdef08be

View File

@ -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) {