]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/clean-ipc: improve error message a bit
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Oct 2020 15:57:03 +0000 (17:57 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Oct 2020 16:06:28 +0000 (18:06 +0200)
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

index e4cd2d30d0a34748e5075989072deae94c36cc8a..5d8f66c6028c3b65a3e7bad338ebacfed4eed1f7 100644 (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) {