Capability based `fchmod`. I also implemented unit tests for chmod,
fchmod, and fchmodat.
The unit tests check Redox-specific behavior, so some of the tests are
disabled for Linux.
`fdopendir` takes ownership of a directory file descriptor instead of
opening one with a path. `fdclosedir` is a FreeBSD extension that
transfers ownership of the file descriptor in DIR to the user.
AT_SYMLINK_NOFOLLOW acts on the symlink itself rather than following it.
AT_EMPTY_PATH acts on the directory if path is empty.
Currently, this is implemented in fstatat itself but the code is general
enough to be refactored once we get the other *at functions. It could
likely just live in openat itself.
Uses a `spin::Mutex` for the global static `_r_debug` instance to remove
warning about a global mutable static.
Guarantees exclusive mutable access to the `_r_debug` variable.
Closes: #212
The fix is simply to not follow links when opening a file to be renamed.
O_NOFOLLOW, a non-POSIX extension, does exactly that while not needing
renameat or openat.
`pthread_atfork` should be exported in pthread.h according to the
standard. We only exported our function in unistd.h. `glibc` exports it
in both pthread.h and unistd.h whereas musl only exports it in pthread.h
(which is standards compliant).
I exported it in both headers. Cbindgen doesn't seem to reexport `pub
use` so I declared the function twice. We might have to reexamine our
`pub use` to check what's exported and what isn't.
Linux's variant uses the syscall as intended. Redox's variant uses fpath
to build a path to pass to fstat from the file descriptor plus the file
name. Unlike the syscall, this isn't atomic so the liminal space between
fpath/getcwd and fstat is subject to TOCTOU.
Beyond fstatat, I moved the stat test to its correct location and added
an assert since the output of the test is unchecked.
I also added AT_FDCWD which seems to be -100 across Unixes. The other
AT_* constants are unimplemented for now.
The implementation for confstr is straightforward. Most of the constants
return 1 on both musl and glibc. The only constant that doesn't is
required for Fish.
I also switched an #[unsafe(no_mangle)] from my last patch back
to a #[no_mangle] because we need to bump cbindgen. #[unsafe(no_mangle)]
is required for Rust 2024.