diff options
author | Rob Landley <rob@landley.net> | 2014-10-02 07:24:38 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-10-02 07:24:38 -0500 |
commit | 2ccab0260f6812f78cc0bafdf2bb2a92942ee6f3 (patch) | |
tree | f788c94bd29a139f139abf74dfbd93700c01205e | |
parent | 76678fa5730dfced54c95696e77fdbc6c9c9e839 (diff) | |
download | toybox-0.5.0.tar.gz |
Workaround for musl's faccessat bug (the rm -r "error: is a directory" thing).0.5.0
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.
-rw-r--r-- | lib/portability.h | 6 |
1 files changed, 6 insertions, 0 deletions
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 <unistd.h> +// 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__ |