]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/rm-rf.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / rm-rf.c
index ff040e7a5516c24a158597b7e2e01e5e9c051203..2839f37cd9f23750c55bce60966575e150e62a54 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -132,7 +133,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
 
                                 r = btrfs_subvol_remove_fd(fd, de->d_name, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA);
                                 if (r < 0) {
-                                        if (r != -ENOTTY && r != -EINVAL) {
+                                        if (!IN_SET(r, -ENOTTY, -EINVAL)) {
                                                 if (ret == 0)
                                                         ret = r;
 
@@ -182,7 +183,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
         /* We refuse to clean the root file system with this
          * call. This is extra paranoia to never cause a really
          * seriously broken system. */
-        if (path_equal_or_files_same(path, "/")) {
+        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.");
                 return -EPERM;
         }
@@ -193,7 +194,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
                 if (r >= 0)
                         return r;
 
-                if (r != -ENOTTY && r != -EINVAL && r != -ENOTDIR)
+                if (!IN_SET(r, -ENOTTY, -EINVAL, -ENOTDIR))
                         return r;
 
                 /* Not btrfs or not a subvolume */
@@ -202,7 +203,7 @@ 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 (errno != ENOTDIR && errno != ELOOP)
+                if (!IN_SET(errno, ENOTDIR, ELOOP))
                         return -errno;
 
                 if (!(flags & REMOVE_PHYSICAL)) {