From 2ccab0260f6812f78cc0bafdf2bb2a92942ee6f3 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 2 Oct 2014 07:24:38 -0500 Subject: Workaround for musl's faccessat bug (the rm -r "error: is a directory" thing). The Linux man page says I can use AT_SYMLINK_NOFOLLOW. It works in glibc, uclibc, and klibc, but musl returns -EINVAL any time you pass in that flag and the maintainer says that's not a bug and insists the man page and those other libraries all change to match musl's behavior. Toybox uses it to avoid scheduling unnecessary metadata writes for things we're about to delete (have to chmod unreadable directories so we can descend into them to delete their contents, the chmod happens before we descend so the disk I/O has plenty of time to be scheduled) because the extra writes wear out SSD faster. It's just an optimization and I don't really care if it works _well_ (the fchmodat call _also_ takes AT_SYMLINK_NOFOLLOW so that's covered), but musl's behavior uniquely makes the check always error and thus breaks normal "rm -r". Yes this workaround is checking #ifdef __MUSL__ which the library does not supply (because its code is perfect and will thus never need to be worked around). You can CFLAGS=-D__MUSL__ if you don't echo "#define __MUSL__" >> include/features.h when installing the library. --- lib/portability.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/portability.h b/lib/portability.h index b38d8812..b7a7c794 100644 --- a/lib/portability.h +++ b/lib/portability.h @@ -126,6 +126,12 @@ int utimensat(int fd, const char *path, const struct timespec times[2], int flag #endif +#ifdef __MUSL__ +#include +// Without this "rm -r dir" fails with "is directory". +#define faccessat(A, B, C, D) faccessat(A, B, C, 0) +#endif + // Work out how to do endianness #ifndef __APPLE__ -- cgit v1.2.3