Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/uipc_usrreq.c
Show First 20 Lines • Show All 2,148 Lines • ▼ Show 20 Lines | unp_internalize(struct mbuf **controlp, struct thread *td) | ||||
struct cmsghdr *cm; | struct cmsghdr *cm; | ||||
struct cmsgcred *cmcred; | struct cmsgcred *cmcred; | ||||
struct filedescent *fde, **fdep, *fdev; | struct filedescent *fde, **fdep, *fdev; | ||||
struct file *fp; | struct file *fp; | ||||
struct timeval *tv; | struct timeval *tv; | ||||
struct timespec *ts; | struct timespec *ts; | ||||
void *data; | void *data; | ||||
socklen_t clen, datalen; | socklen_t clen, datalen; | ||||
int i, error, *fdp, oldfds; | int i, j, error, *fdp, oldfds; | ||||
u_int newlen; | u_int newlen; | ||||
UNP_LINK_UNLOCK_ASSERT(); | UNP_LINK_UNLOCK_ASSERT(); | ||||
p = td->td_proc; | p = td->td_proc; | ||||
fdesc = p->p_fd; | fdesc = p->p_fd; | ||||
error = 0; | error = 0; | ||||
control = *controlp; | control = *controlp; | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | case SCM_RIGHTS: | ||||
*controlp = sbcreatecontrol(NULL, newlen, | *controlp = sbcreatecontrol(NULL, newlen, | ||||
SCM_RIGHTS, SOL_SOCKET); | SCM_RIGHTS, SOL_SOCKET); | ||||
if (*controlp == NULL) { | if (*controlp == NULL) { | ||||
FILEDESC_SUNLOCK(fdesc); | FILEDESC_SUNLOCK(fdesc); | ||||
error = E2BIG; | error = E2BIG; | ||||
goto out; | goto out; | ||||
} | } | ||||
fdp = data; | fdp = data; | ||||
for (i = 0; i < oldfds; i++, fdp++) { | |||||
if (!fhold(fdesc->fd_ofiles[*fdp].fde_file)) { | |||||
fdp = data; | |||||
for (j = 0; j < i; j++, fdp++) { | |||||
fdrop(fdesc->fd_ofiles[*fdp]. | |||||
fde_file, td); | |||||
} | |||||
FILEDESC_SUNLOCK(fdesc); | |||||
error = EBADF; | |||||
goto out; | |||||
} | |||||
} | |||||
fdp = data; | |||||
fdep = (struct filedescent **) | fdep = (struct filedescent **) | ||||
CMSG_DATA(mtod(*controlp, struct cmsghdr *)); | CMSG_DATA(mtod(*controlp, struct cmsghdr *)); | ||||
fdev = malloc(sizeof(*fdev) * oldfds, M_FILECAPS, | fdev = malloc(sizeof(*fdev) * oldfds, M_FILECAPS, | ||||
M_WAITOK); | M_WAITOK); | ||||
for (i = 0; i < oldfds; i++, fdev++, fdp++) { | for (i = 0; i < oldfds; i++, fdev++, fdp++) { | ||||
fde = &fdesc->fd_ofiles[*fdp]; | fde = &fdesc->fd_ofiles[*fdp]; | ||||
fdep[i] = fdev; | fdep[i] = fdev; | ||||
fdep[i]->fde_file = fde->fde_file; | fdep[i]->fde_file = fde->fde_file; | ||||
▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
struct unpcb *unp; | struct unpcb *unp; | ||||
UNP_LINK_WLOCK(); | UNP_LINK_WLOCK(); | ||||
if ((unp = fptounp(fp)) != NULL) { | if ((unp = fptounp(fp)) != NULL) { | ||||
unp->unp_file = fp; | unp->unp_file = fp; | ||||
unp->unp_msgcount++; | unp->unp_msgcount++; | ||||
} | } | ||||
fhold(fp); | |||||
unp_rights++; | unp_rights++; | ||||
UNP_LINK_WUNLOCK(); | UNP_LINK_WUNLOCK(); | ||||
} | } | ||||
static int | static int | ||||
unp_externalize_fp(struct file *fp) | unp_externalize_fp(struct file *fp) | ||||
{ | { | ||||
struct unpcb *unp; | struct unpcb *unp; | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | unp_gc(__unused void *arg, int pending) | ||||
* as as unreachable and store them locally. | * as as unreachable and store them locally. | ||||
*/ | */ | ||||
UNP_LINK_RLOCK(); | UNP_LINK_RLOCK(); | ||||
for (total = 0, head = heads; *head != NULL; head++) | for (total = 0, head = heads; *head != NULL; head++) | ||||
LIST_FOREACH(unp, *head, unp_link) | LIST_FOREACH(unp, *head, unp_link) | ||||
if ((unp->unp_gcflag & UNPGC_DEAD) != 0) { | if ((unp->unp_gcflag & UNPGC_DEAD) != 0) { | ||||
f = unp->unp_file; | f = unp->unp_file; | ||||
if (unp->unp_msgcount == 0 || f == NULL || | if (unp->unp_msgcount == 0 || f == NULL || | ||||
f->f_count != unp->unp_msgcount) | f->f_count != unp->unp_msgcount || | ||||
!fhold(f)) | |||||
continue; | continue; | ||||
unref[total++] = f; | unref[total++] = f; | ||||
fhold(f); | |||||
KASSERT(total <= unp_unreachable, | KASSERT(total <= unp_unreachable, | ||||
("unp_gc: incorrect unreachable count.")); | ("unp_gc: incorrect unreachable count.")); | ||||
} | } | ||||
UNP_LINK_RUNLOCK(); | UNP_LINK_RUNLOCK(); | ||||
/* | /* | ||||
* Now flush all sockets, free'ing rights. This will free the | * Now flush all sockets, free'ing rights. This will free the | ||||
* struct files associated with these sockets but leave each socket | * struct files associated with these sockets but leave each socket | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |