os: fdtable: restore errno if optional locking ioctl fails
The `zvfs_finalize_typed_fd()` function notifies some backends via `ioctl()` with `ZFD_IOCTL_SET_LOCK`. However, support for this method and functionality is optional. In backends that do not support locking, this benign failure can set `errno` to 95 (`EOPNOTSUPP`) in many circumstances where a change in `errno` (indicating some kind of failure) is not appropriate. Prevent errno poisoning by backing-up and restoring `errno`. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
ba8025fcd4
commit
2a2806bb40
1 changed files with 6 additions and 0 deletions
|
@ -280,8 +280,14 @@ void zvfs_finalize_typed_fd(int fd, void *obj, const struct fd_op_vtable *vtable
|
|||
* variables to avoid keeping the lock for a long period of time.
|
||||
*/
|
||||
if (vtable && vtable->ioctl) {
|
||||
int prev_errno = errno;
|
||||
|
||||
(void)zvfs_fdtable_call_ioctl(vtable, obj, ZFD_IOCTL_SET_LOCK,
|
||||
&fdtable[fd].lock);
|
||||
if ((prev_errno != EOPNOTSUPP) && (errno == EOPNOTSUPP)) {
|
||||
/* restore backed-up errno value if the backend does not support locking */
|
||||
errno = prev_errno;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue