mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-23 16:01:42 +00:00
fd: add fdeget_locked and use in kern_descrip
This commit is contained in:
parent
1ca1e01360
commit
4cbafea09c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=305093
@ -517,28 +517,26 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
|
||||
break;
|
||||
|
||||
case F_GETFD:
|
||||
error = EBADF;
|
||||
FILEDESC_SLOCK(fdp);
|
||||
if (fget_locked(fdp, fd) == NULL) {
|
||||
FILEDESC_SUNLOCK(fdp);
|
||||
error = EBADF;
|
||||
break;
|
||||
fde = fdeget_locked(fdp, fd);
|
||||
if (fde != NULL) {
|
||||
td->td_retval[0] =
|
||||
(fde->fde_flags & UF_EXCLOSE) ? FD_CLOEXEC : 0;
|
||||
error = 0;
|
||||
}
|
||||
fde = &fdp->fd_ofiles[fd];
|
||||
td->td_retval[0] =
|
||||
(fde->fde_flags & UF_EXCLOSE) ? FD_CLOEXEC : 0;
|
||||
FILEDESC_SUNLOCK(fdp);
|
||||
break;
|
||||
|
||||
case F_SETFD:
|
||||
error = EBADF;
|
||||
FILEDESC_XLOCK(fdp);
|
||||
if (fget_locked(fdp, fd) == NULL) {
|
||||
FILEDESC_XUNLOCK(fdp);
|
||||
error = EBADF;
|
||||
break;
|
||||
fde = fdeget_locked(fdp, fd);
|
||||
if (fde != NULL) {
|
||||
fde->fde_flags = (fde->fde_flags & ~UF_EXCLOSE) |
|
||||
(arg & FD_CLOEXEC ? UF_EXCLOSE : 0);
|
||||
error = 0;
|
||||
}
|
||||
fde = &fdp->fd_ofiles[fd];
|
||||
fde->fde_flags = (fde->fde_flags & ~UF_EXCLOSE) |
|
||||
(arg & FD_CLOEXEC ? UF_EXCLOSE : 0);
|
||||
FILEDESC_XUNLOCK(fdp);
|
||||
break;
|
||||
|
||||
|
@ -207,6 +207,18 @@ fget_locked(struct filedesc *fdp, int fd)
|
||||
return (fdp->fd_ofiles[fd].fde_file);
|
||||
}
|
||||
|
||||
static __inline struct filedescent *
|
||||
fdeget_locked(struct filedesc *fdp, int fd)
|
||||
{
|
||||
|
||||
FILEDESC_LOCK_ASSERT(fdp);
|
||||
|
||||
if ((u_int)fd > fdp->fd_lastfile)
|
||||
return (NULL);
|
||||
|
||||
return (&fdp->fd_ofiles[fd]);
|
||||
}
|
||||
|
||||
static __inline bool
|
||||
fd_modified(struct filedesc *fdp, int fd, seq_t seq)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user