changeset 1512:7afd32673a5c 0.5.0

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.
author Rob Landley <>
date Thu, 02 Oct 2014 07:24:38 -0500
parents df792340e3f7
children 7a0ea74c2e0c
files lib/portability.h
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/portability.h	Wed Oct 01 19:57:34 2014 -0500
+++ b/lib/portability.h	Thu Oct 02 07:24:38 2014 -0500
@@ -126,6 +126,12 @@
+#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)
 // Work out how to do endianness
 #ifndef __APPLE__