svn commit: r305093 - in head/sys: kern sys
Mateusz Guzik
mjg at FreeBSD.org
Tue Aug 30 21:53:23 UTC 2016
Author: mjg
Date: Tue Aug 30 21:53:22 2016
New Revision: 305093
URL: https://svnweb.freebsd.org/changeset/base/305093
Log:
fd: add fdeget_locked and use in kern_descrip
Modified:
head/sys/kern/kern_descrip.c
head/sys/sys/filedesc.h
Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c Tue Aug 30 21:51:53 2016 (r305092)
+++ head/sys/kern/kern_descrip.c Tue Aug 30 21:53:22 2016 (r305093)
@@ -517,28 +517,26 @@ kern_fcntl(struct thread *td, int fd, in
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;
Modified: head/sys/sys/filedesc.h
==============================================================================
--- head/sys/sys/filedesc.h Tue Aug 30 21:51:53 2016 (r305092)
+++ head/sys/sys/filedesc.h Tue Aug 30 21:53:22 2016 (r305093)
@@ -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)
{
More information about the svn-src-head
mailing list