sys_generic.c (189708) | sys_generic.c (192080) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/sys_generic.c 189708 2009-03-11 22:00:03Z rwatson $"); | 38__FBSDID("$FreeBSD: head/sys/kern/sys_generic.c 192080 2009-05-14 03:24:22Z jeff $"); |
39 40#include "opt_compat.h" 41#include "opt_ktrace.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/sysproto.h> 46#include <sys/filedesc.h> --- 936 unchanged lines hidden (view full) --- 983 struct selfd *sfn; 984 struct file *fp; 985 fd_mask bit; 986 int fd, ev, n, idx; 987 988 fdp = td->td_proc->p_fd; 989 stp = td->td_sel; 990 n = 0; | 39 40#include "opt_compat.h" 41#include "opt_ktrace.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/sysproto.h> 46#include <sys/filedesc.h> --- 936 unchanged lines hidden (view full) --- 983 struct selfd *sfn; 984 struct file *fp; 985 fd_mask bit; 986 int fd, ev, n, idx; 987 988 fdp = td->td_proc->p_fd; 989 stp = td->td_sel; 990 n = 0; |
991 FILEDESC_SLOCK(fdp); | |
992 STAILQ_FOREACH_SAFE(sfp, &stp->st_selq, sf_link, sfn) { 993 fd = (int)(uintptr_t)sfp->sf_cookie; 994 si = sfp->sf_si; 995 selfdfree(stp, sfp); 996 /* If the selinfo wasn't cleared the event didn't fire. */ 997 if (si != NULL) 998 continue; | 991 STAILQ_FOREACH_SAFE(sfp, &stp->st_selq, sf_link, sfn) { 992 fd = (int)(uintptr_t)sfp->sf_cookie; 993 si = sfp->sf_si; 994 selfdfree(stp, sfp); 995 /* If the selinfo wasn't cleared the event didn't fire. */ 996 if (si != NULL) 997 continue; |
999 if ((fp = fget_locked(fdp, fd)) == NULL) { 1000 FILEDESC_SUNLOCK(fdp); | 998 if ((fp = fget_unlocked(fdp, fd)) == NULL) |
1001 return (EBADF); | 999 return (EBADF); |
1002 } | |
1003 idx = fd / NFDBITS; 1004 bit = (fd_mask)1 << (fd % NFDBITS); 1005 ev = fo_poll(fp, selflags(ibits, idx, bit), td->td_ucred, td); | 1000 idx = fd / NFDBITS; 1001 bit = (fd_mask)1 << (fd % NFDBITS); 1002 ev = fo_poll(fp, selflags(ibits, idx, bit), td->td_ucred, td); |
1003 fdrop(fp, td); |
|
1006 if (ev != 0) 1007 n += selsetbits(ibits, obits, idx, bit, ev); 1008 } | 1004 if (ev != 0) 1005 n += selsetbits(ibits, obits, idx, bit, ev); 1006 } |
1009 FILEDESC_SUNLOCK(fdp); | |
1010 stp->st_flags = 0; 1011 td->td_retval[0] = n; 1012 return (0); 1013} 1014 1015/* 1016 * Perform the initial filedescriptor scan and register ourselves with 1017 * each selinfo. --- 7 unchanged lines hidden (view full) --- 1025 struct filedesc *fdp; 1026 struct file *fp; 1027 fd_mask bit; 1028 int ev, flags, end, fd; 1029 int n, idx; 1030 1031 fdp = td->td_proc->p_fd; 1032 n = 0; | 1007 stp->st_flags = 0; 1008 td->td_retval[0] = n; 1009 return (0); 1010} 1011 1012/* 1013 * Perform the initial filedescriptor scan and register ourselves with 1014 * each selinfo. --- 7 unchanged lines hidden (view full) --- 1022 struct filedesc *fdp; 1023 struct file *fp; 1024 fd_mask bit; 1025 int ev, flags, end, fd; 1026 int n, idx; 1027 1028 fdp = td->td_proc->p_fd; 1029 n = 0; |
1033 FILEDESC_SLOCK(fdp); | |
1034 for (idx = 0, fd = 0; fd < nfd; idx++) { 1035 end = imin(fd + NFDBITS, nfd); 1036 for (bit = 1; fd < end; bit <<= 1, fd++) { 1037 /* Compute the list of events we're interested in. */ 1038 flags = selflags(ibits, idx, bit); 1039 if (flags == 0) 1040 continue; | 1030 for (idx = 0, fd = 0; fd < nfd; idx++) { 1031 end = imin(fd + NFDBITS, nfd); 1032 for (bit = 1; fd < end; bit <<= 1, fd++) { 1033 /* Compute the list of events we're interested in. */ 1034 flags = selflags(ibits, idx, bit); 1035 if (flags == 0) 1036 continue; |
1041 if ((fp = fget_locked(fdp, fd)) == NULL) { 1042 FILEDESC_SUNLOCK(fdp); | 1037 if ((fp = fget_unlocked(fdp, fd)) == NULL) |
1043 return (EBADF); | 1038 return (EBADF); |
1044 } | |
1045 selfdalloc(td, (void *)(uintptr_t)fd); 1046 ev = fo_poll(fp, flags, td->td_ucred, td); | 1039 selfdalloc(td, (void *)(uintptr_t)fd); 1040 ev = fo_poll(fp, flags, td->td_ucred, td); |
1041 fdrop(fp, td); |
|
1047 if (ev != 0) 1048 n += selsetbits(ibits, obits, idx, bit, ev); 1049 } 1050 } 1051 | 1042 if (ev != 0) 1043 n += selsetbits(ibits, obits, idx, bit, ev); 1044 } 1045 } 1046 |
1052 FILEDESC_SUNLOCK(fdp); | |
1053 td->td_retval[0] = n; 1054 return (0); 1055} 1056 1057#ifndef _SYS_SYSPROTO_H_ 1058struct poll_args { 1059 struct pollfd *fds; 1060 u_int nfds; --- 480 unchanged lines hidden --- | 1047 td->td_retval[0] = n; 1048 return (0); 1049} 1050 1051#ifndef _SYS_SYSPROTO_H_ 1052struct poll_args { 1053 struct pollfd *fds; 1054 u_int nfds; --- 480 unchanged lines hidden --- |