diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c index 2f5c2a92be..91474ad95c 100644 --- a/src/basic/rm-rf.c +++ b/src/basic/rm-rf.c @@ -13,6 +13,7 @@ #include #include +#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; } @@ -171,7 +174,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; } @@ -189,7 +192,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; @@ -198,7 +200,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; } } diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 95c40cc91d..9919b2f2c2 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -828,14 +828,14 @@ void lookup_paths_flush_generator(LookupPaths *p) { /* Flush the generated unit files in full */ if (p->generator) - (void) rm_rf(p->generator, REMOVE_ROOT); + (void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL); if (p->generator_early) - (void) rm_rf(p->generator_early, REMOVE_ROOT); + (void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL); if (p->generator_late) - (void) rm_rf(p->generator_late, REMOVE_ROOT); + (void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL); if (p->temporary_dir) - (void) rm_rf(p->temporary_dir, REMOVE_ROOT); + (void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL); } char **generator_binary_paths(UnitFileScope scope) {