aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorChen Yu <yu.chen3@zte.com.cn>2018-09-04 15:26:22 +0800
committerDenys Vlasenko <vda.linux@googlemail.com>2018-09-09 20:16:04 +0200
commit05b18065ab9c375f6185b65a3631d4c6cc1a4be9 (patch)
tree83a87ccb2a13c2279676c20b72fb1c79428e5724 /libbb
parent3d6f95ede6e98cd245cfbdc4c429a184f6c0d717 (diff)
downloadbusybox-05b18065ab9c375f6185b65a3631d4c6cc1a4be9.tar.gz
remove_file: don't call rmdir if remove_file return failure
When deleting a directory, the directory should not be removed if the file in the subdirectory fails to be deleted. Background information: When I tested the kernel using LTP (linux-test-project).I found the mv command have some issue. The LTP test case use the mv command to move the directory t1 in the cgroup file system to the /tmp directory. becase files in the cgroup file system are not allowed to be removed. so the mv reported "Permission denied", but I used the ls command to view the results and found that the directory t1 had been removed from the cgroup file system. For the same test case, I used the mv tool in the GNU coreutils, and the directory t1 will not be removed. the following testcase use busybox mv: / # mount -t cgroup -o cpu cgroup /cpu / # cd /cpu /cpu # mkdir -p t1 /cpu # ls cgroup.clone_children cpu.cfs_period_us cpu.stat t1 cgroup.procs cpu.cfs_quota_us notify_on_release tasks cgroup.sane_behavior cpu.shares release_agent /cpu # mv t1 /tmp mv: can't remove 't1/cgroup.procs': Operation not permitted mv: can't remove 't1/cpu.cfs_period_us': Operation not permitted mv: can't remove 't1/cpu.stat': Operation not permitted mv: can't remove 't1/cpu.shares': Operation not permitted mv: can't remove 't1/cpu.cfs_quota_us': Operation not permitted mv: can't remove 't1/tasks': Operation not permitted mv: can't remove 't1/notify_on_release': Operation not permitted mv: can't remove 't1/cgroup.clone_children': Operation not permitted /cpu # ls cgroup.clone_children cpu.cfs_period_us cpu.stat cgroup.procs cpu.cfs_quota_us notify_on_release tasks cgroup.sane_behavior cpu.shares release_agent /cpu # This patch fixed it, don't call rmdir if remove_file return failure, and under certain file systems, the mv could work normally. Signed-off-by: Chen Yu <yu.chen3@zte.com.cn> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/remove_file.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 86c9a5c56..cea5d47e6 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -73,7 +73,7 @@ int FAST_FUNC remove_file(const char *path, int flags)
return status;
}
- if (rmdir(path) < 0) {
+ if (status == 0 && rmdir(path) < 0) {
bb_perror_msg("can't remove '%s'", path);
return -1;
}