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.
`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.
I copied the constants and definitions from musl which we can presume is
correct. Relibc is missing some features which affects our sysconf as
well, such as constants in limits.h or a working resources.h.
Most platforms use a c_int though glibc uses a u32. GNU defines a type,
__rlimit_resource_t, for the RLIMIT enum that is a u32.
Using a c_int is nicer for a few reasons. The first is that our
(unimplemented) functions receive a c_int for the enum - using a u32 is
technically wrong but doesn't affect anything since the constants are
turned into macros by cbindgen.
The second reason is that a c_int is nicer for libc and nix (the crate)
too since we don't need to pollute the crates with guards for Redox.
Fish only requires BSHELL. The constants are implementation specific so
this header will evolve as needed.
Cbindgen doesn't emit defines for strings (even CStrs) so I only
provided what's needed for Fish in a C header for now with the ideal
implementation, in Rust, unbuilt.
%m is a format specifier that prints an error string for errno. The
specifier is technically only for syslog, but musl and glibc implement
it for printf itself. Parsing for a single specifier in a single
function is error prone, especially when syslog itself is variadic.
* Fix PERROR to match musl/glibc better
* More unit tests + enabled on Linux
* Pack priority and facility into one i32 and check the bits with
bitflags
* Add LOG_UPTO (logic is straight from musl)
Not done:
* "%m" - this could just be added to printf
* LOG_CONS