summaryrefslogtreecommitdiff
path: root/src/stat/fchmodat.c
AgeCommit message (Collapse)AuthorLines
2024-02-22use new SYS_fchmodat2 syscall to implement fchmodat with flagsGaël PORTAY-1/+4
commit 0dc4824479e357a3e23a02d35527e23fca920343 worked around for lack of flags argument in syscall for fchmodat. linux 6.6 introduced a new syscall, SYS_fchmodat2, fixing this deficiency. use it if any flags are passed, and fallback to the old strategy on ENOSYS. continue using the old syscall when there are no flags. this is the exact same strategy used when SYS_faccessat2 was used to implement faccessat with flags.
2024-02-22remove flag argument from fchmodat syscallGaël PORTAY-1/+1
linux's does not have the flag argument for fchmodat syscall.
2022-05-01drop direct use of stat syscalls in fchmodatRich Felker-8/+7
instead, use the fstatat/stat functions, so that the logic for which syscalls are present and usable is all in fstatat. this results in a slight increase in cost for old kernels on 32-bit archs: now statx will be attempted first rather than just using the legacy time32 syscalls, despite us not caring about timestamps. however, it's not even clear that the legacy syscalls *should* succeed if the timestamps are out of range; arguably they should fail with EOVERFLOW. as such, paying a small cost here on old kernels seems well-motivated. with this change, fchmodat itself is no longer blocking ports to new archs that lack the legacy syscalls.
2020-02-12fix remaining direct use of stat syscalls outside fstatat.cRich Felker-1/+2
because struct stat is no longer assumed to correspond to the structure used by the stat-family syscalls, it's not valid to make any of these syscalls directly using a buffer of type struct stat. commit 9493892021eac4edf1776d945bcdd3f7a96f6978 moved all logic around this change for stat-family functions into fstatat.c, making the others wrappers for it. but a few other direct uses of the syscall were overlooked. the ones in tmpnam/tempnam are harmless since the syscalls are just used to test for file existence. however, the uses in fchmodat and __map_file depend on getting accurate file properties, and these functions may actually have been broken one or more mips variants due to removal of conversion hacks from syscall_arch.h. as a low-risk fix, simply use struct kstat in place of struct stat in the affected places.
2018-09-12move and deduplicate declarations of __procfdname to make it checkableRich Felker-2/+0
syscall.h was chosen as the header to declare it, since its intended usage is alongside syscalls as a fallback for operations the direct syscall does not support.
2015-02-05fix failure of fchmodat to report EOPNOTSUPP in the race pathRich Felker-2/+4
in the case where a non-symlink file was replaced by a symlink during the fchmodat operation with AT_SYMLINK_NOFOLLOW, mode change on the new symlink target was successfully suppressed, but the error was not reported. instead, fchmodat simply returned 0.
2015-02-04fix fd leak race (missing O_CLOEXEC) in fchmodatRich Felker-1/+1
2014-05-29support linux kernel apis (new archs) with old syscalls removedRich Felker-2/+3
such archs are expected to omit definitions of the SYS_* macros for syscalls their kernels lack from arch/$ARCH/bits/syscall.h. the preprocessor is then able to select the an appropriate implementation for affected functions. two basic strategies are used on a case-by-case basis: where the old syscalls correspond to deprecated library-level functions, the deprecated functions have been converted to wrappers for the modern function, and the modern function has fallback code (omitted at the preprocessor level on new archs) to make use of the old syscalls if the new syscall fails with ENOSYS. this also improves functionality on older kernels and eliminates the incentive to program with deprecated library-level functions for the sake of compatibility with older kernels. in other situations where the old syscalls correspond to library-level functions which are not deprecated but merely lack some new features, such as the *at functions, the old syscalls are still used on archs which support them. this may change at some point in the future if or when fallback code is added to the new functions to make them usable (possibly with reduced functionality) on old kernels.
2013-12-12include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy-1/+0
2013-08-02debloat code that depends on /proc/self/fd/%d with shared functionRich Felker-1/+3
I intend to add more Linux workarounds that depend on using these pathnames, and some of them will be in "syscall" functions that, from an anti-bloat standpoint, should not depend on the whole snprintf framework.
2013-08-02work around linux's lack of flags argument to fchmodat syscallRich Felker-1/+29
previously, the AT_SYMLINK_NOFOLLOW flag was ignored, giving dangerously incorrect behavior -- the target of the symlink had its modes changed to the modes (usually 0777) intended for the symlink). this issue was amplified by the fact that musl provides lchmod, as a wrapper for fchmodat, which some archival programs take as a sign that symlink modes are supported and thus attempt to use. emulating AT_SYMLINK_NOFOLLOW was a difficult problem, and I originally believed it could not be solved, at least not without depending on kernels newer than 3.5.x or so where O_PATH works halfway well. however, it turns out that accessing O_PATH file descriptors via their pseudo-symlink entries in /proc/self/fd works much better than trying to use the fd directly, and works even on older kernels. moreover, the kernel has permanently pegged these references to the inode obtained by the O_PATH open, so there should not be race conditions with the file being moved, deleted, replaced, etc.
2011-03-20global cleanup to use the new syscall interfaceRich Felker-1/+1
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+7