chiark / gitweb /
basic/rm-rf: include the path in error messages
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 22 May 2018 09:33:01 +0000 (11:33 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
Attempted to remove disk file system under "/tmp/systemd-temporary-aWPkbQ", and we can't allow that.

src/basic/rm-rf.c

index 5165fcea3317e0827d298f628207c7e952150de5..4ebc5c60a35936d5af4392b6c8b131e8fd6c748c 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/statfs.h>
 #include <unistd.h>
 
+//#include "alloc-util.h"
 //#include "btrfs-util.h"
 #include "cgroup-util.h"
 #include "dirent-util.h"
@@ -49,13 +50,15 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
                 }
 
                 if (is_physical_fs(&sfs)) {
-                        /* We refuse to clean physical file systems
-                         * with this call, unless explicitly
-                         * requested. This is extra paranoia just to
-                         * be sure we never ever remove non-state
-                         * data */
+                        /* We refuse to clean physical file systems with this call,
+                         * unless explicitly requested. This is extra paranoia just
+                         * to be sure we never ever remove non-state data. */
+                        _cleanup_free_ char *path = NULL;
+
+                        (void) fd_get_path(fd, &path);
+                        log_error("Attempted to remove disk file system under \"%s\", and we can't allow that.",
+                                  strna(path));
 
-                        log_error("Attempted to remove disk file system, and we can't allow that.");
                         safe_close(fd);
                         return -EPERM;
                 }
@@ -173,7 +176,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
          * call. This is extra paranoia to never cause a really
          * seriously broken system. */
         if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW)) {
-                log_error("Attempted to remove entire root file system, and we can't allow that.");
+                log_error("Attempted to remove entire root file system (\"%s\"), and we can't allow that.", path);
                 return -EPERM;
         }
 
@@ -193,7 +196,6 @@ int rm_rf(const char *path, RemoveFlags flags) {
 
         fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
         if (fd < 0) {
-
                 if (!IN_SET(errno, ENOTDIR, ELOOP))
                         return -errno;
 
@@ -202,7 +204,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
                                 return -errno;
 
                         if (is_physical_fs(&s)) {
-                                log_error("Attempted to remove disk file system, and we can't allow that.");
+                                log_error("Attempted to remove files from a disk file system under \"%s\", refusing.", path);
                                 return -EPERM;
                         }
                 }