After upgrading from SLES12 SP5 to SLES15 SP6 I noticed that the %clean phase of some RPM spec files fail for some strange reason when using rpmbuild -ba.
The RPMs (SRPM, RPMs) are written correctly, but when cleaning up I see errors like this:
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.IXMkuS
+ umask 022
+ cd /home/windl/rpmbuild/BUILD
+ cd iredir-0.5.1n
+ for d in "/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64"
+ '[' -n /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64 -a /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64 '!=' / ']'
+ ls -l /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64
total 12
drwxr-xr-x 6 windl dvmed 4096 Mar 10 10:40 etc
drwxr-xr-x 6 windl dvmed 4096 Mar 10 10:40 usr
drwxr-xr-x 5 windl dvmed 4096 Mar 10 10:40 var
+ rm -rf /home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64
rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/usr/lib/ocf/resource.d/xola': Directory not empty
rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/usr/lib/iredir': Directory not empty
rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/etc/ocf/xola/isredir': Directory not empty
rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/etc/ocf/xola/idredir': Directory not empty
rm: cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.1n-0.0.x86_64/etc/init.d': Directory not empty
error: Bad exit status from /var/tmp/rpm-tmp.IXMkuS (%clean)
This is very strange as rm -rf is supposed to remove non-empty directories.
I added the ls command after having experienced the issue:
%clean
# called for %install
for d in "%{buildroot}"
do
[ -n "$d" -a "$d" != / ] && ls -l "$d" && rm -rf "$d"
done
What might cause this?
It seems like some asynchronous effect tto me. ~ is on NFS (also hosted by SLES15 (but SP5) (nfs-kernel-server-2.1.1-150500.22.3.1.x86_64, kernel 5.14.21-150500.55.83-default)).
/usr/bin/rm is from coreutils-8.32-150400.9.6.1.x86_64.
More Details
I changed the RPM spec file to recursively list the whole directory, also adding -v to the rm command.
When I see is that a directory contains four (normal) files that are deleted just before rm complains the directory isn't empty.
More tests
The effect is strange:
When I created a test script that creates a directory, adds four files, and then removed that directory, it always works, while the rpmbuild -ba always fails for the same directory.
Well, the total length of the paths for the rpmbuild is somewhat longer, but still smaller than say 120 characters.
So I ran the whole thing under strace -f -s64with these results:
1079 newfstatat(7, "xola", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
1079 openat(7, "xola", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_DIRECTORY) = 3
1079 fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
1079 fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_NOFOLLOW|O_DIRECTORY)
1079 fcntl(3, F_SETFD, FD_CLOEXEC) = 0
1079 getdents64(3, 0x55d729e27910 /* 6 entries */, 1048576) = 176
1079 close(3) = 0
1079 openat(7, "xola", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 3
1079 fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
1079 fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_NOFOLLOW|O_DIRECTORY)
1079 fcntl(3, F_SETFD, FD_CLOEXEC) = 0
1079 fcntl(3, F_DUPFD_CLOEXEC, 3) = 8
1079 getdents64(3, 0x55d729e27910 /* 6 entries */, 1048576) = 176
1079 getdents64(3, 0x55d729e27910 /* 0 entries */, 1048576) = 0
1079 close(3) = 0
1079 unlinkat(8, "isredir", 0) = 0
1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 102) = 102
1079 unlinkat(8, "idredir.xml", 0) = 0
1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 106) = 106
1079 unlinkat(8, "isredir.xml", 0) = 0
1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 106) = 106
1079 unlinkat(8, "idredir", 0) = 0
1079 write(1, "removed '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64"..., 102) = 102
1079 close(8) = 0
1079 unlinkat(7, "xola", AT_REMOVEDIR) = -1 ENOTEMPTY (Directory not empty)
1079 write(2, "rm: ", 4) = 4
1079 write(2, "cannot remove '/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0."..., 99) = 99
1079 write(2, ": Directory not empty", 21) = 21
1079 write(2, "\n", 1) = 1
1079 close(7) = 0
1079 close(6) = 0
So in my interpretation the xolasubdirectory has four files (with . and .. that are six directory entries).
Before ls -lR showed
/home/windl/rpmbuild/BUILDROOT/iredir-0.5.3n-0.0.x86_64/usr/lib/ocf/resource.d/xola:
total 56
drwxr-xr-x 2 windl dvmed 4096 Mar 12 08:03 .
drwxr-xr-x 3 windl dvmed 4096 Mar 12 08:03 ..
-r-xr-xr-x 1 windl dvmed 13228 Oct 21 2019 idredir
-r--r--r-- 1 windl dvmed 5543 Oct 10 2019 idredir.xml
-r-xr-xr-x 1 windl dvmed 13507 Oct 21 2019 isredir
-r--r--r-- 1 windl dvmed 5774 Oct 10 2019 isredir.xml
The four files were deleted successfully (rm -vrf being used), but then the directory could not be deleted.
Somewhow I suspect the NFS attribute cache on either the client or on the server to cause this.