Deleted Added
full compact
uipc_usrreq.c (248534) uipc_usrreq.c (249480)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2004-2009 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 43 unchanged lines hidden (view full) ---

52 * TODO:
53 * RDM
54 * distinguish datagram size limits from flow control limits in SEQPACKET
55 * rethink name space problems
56 * need a proper out-of-band
57 */
58
59#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2004-2009 Robert N. M. Watson
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 43 unchanged lines hidden (view full) ---

52 * TODO:
53 * RDM
54 * distinguish datagram size limits from flow control limits in SEQPACKET
55 * rethink name space problems
56 * need a proper out-of-band
57 */
58
59#include <sys/cdefs.h>
60__FBSDID("$FreeBSD: head/sys/kern/uipc_usrreq.c 248534 2013-03-19 20:58:17Z jilles $");
60__FBSDID("$FreeBSD: head/sys/kern/uipc_usrreq.c 249480 2013-04-14 17:08:34Z mjg $");
61
62#include "opt_ddb.h"
63
64#include <sys/param.h>
65#include <sys/capability.h>
66#include <sys/domain.h>
67#include <sys/fcntl.h>
68#include <sys/malloc.h> /* XXX must be before <sys/file.h> */

--- 1632 unchanged lines hidden (view full) ---

1701 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1702 int i;
1703 int *fdp;
1704 struct filedesc *fdesc = td->td_proc->p_fd;
1705 struct filedescent *fde, **fdep;
1706 void *data;
1707 socklen_t clen = control->m_len, datalen;
1708 int error, newfds;
61
62#include "opt_ddb.h"
63
64#include <sys/param.h>
65#include <sys/capability.h>
66#include <sys/domain.h>
67#include <sys/fcntl.h>
68#include <sys/malloc.h> /* XXX must be before <sys/file.h> */

--- 1632 unchanged lines hidden (view full) ---

1701 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1702 int i;
1703 int *fdp;
1704 struct filedesc *fdesc = td->td_proc->p_fd;
1705 struct filedescent *fde, **fdep;
1706 void *data;
1707 socklen_t clen = control->m_len, datalen;
1708 int error, newfds;
1709 int f;
1710 u_int newlen;
1711
1712 UNP_LINK_UNLOCK_ASSERT();
1713
1714 error = 0;
1715 if (controlp != NULL) /* controlp == NULL => free control messages */
1716 *controlp = NULL;
1717 while (cm != NULL) {

--- 9 unchanged lines hidden (view full) ---

1727 fdep = data;
1728
1729 /* If we're not outputting the descriptors free them. */
1730 if (error || controlp == NULL) {
1731 unp_freerights(fdep, newfds);
1732 goto next;
1733 }
1734 FILEDESC_XLOCK(fdesc);
1709 u_int newlen;
1710
1711 UNP_LINK_UNLOCK_ASSERT();
1712
1713 error = 0;
1714 if (controlp != NULL) /* controlp == NULL => free control messages */
1715 *controlp = NULL;
1716 while (cm != NULL) {

--- 9 unchanged lines hidden (view full) ---

1726 fdep = data;
1727
1728 /* If we're not outputting the descriptors free them. */
1729 if (error || controlp == NULL) {
1730 unp_freerights(fdep, newfds);
1731 goto next;
1732 }
1733 FILEDESC_XLOCK(fdesc);
1735 /* if the new FD's will not fit free them. */
1736 if (!fdavail(td, newfds)) {
1737 FILEDESC_XUNLOCK(fdesc);
1738 error = EMSGSIZE;
1739 unp_freerights(fdep, newfds);
1740 goto next;
1741 }
1742
1743 /*
1744 * Now change each pointer to an fd in the global
1745 * table to an integer that is the index to the local
1746 * fd table entry that we set up to point to the
1747 * global one we are transferring.
1748 */
1749 newlen = newfds * sizeof(int);
1750 *controlp = sbcreatecontrol(NULL, newlen,
1751 SCM_RIGHTS, SOL_SOCKET);
1752 if (*controlp == NULL) {
1753 FILEDESC_XUNLOCK(fdesc);
1754 error = E2BIG;
1755 unp_freerights(fdep, newfds);
1756 goto next;
1757 }
1758
1759 fdp = (int *)
1760 CMSG_DATA(mtod(*controlp, struct cmsghdr *));
1734
1735 /*
1736 * Now change each pointer to an fd in the global
1737 * table to an integer that is the index to the local
1738 * fd table entry that we set up to point to the
1739 * global one we are transferring.
1740 */
1741 newlen = newfds * sizeof(int);
1742 *controlp = sbcreatecontrol(NULL, newlen,
1743 SCM_RIGHTS, SOL_SOCKET);
1744 if (*controlp == NULL) {
1745 FILEDESC_XUNLOCK(fdesc);
1746 error = E2BIG;
1747 unp_freerights(fdep, newfds);
1748 goto next;
1749 }
1750
1751 fdp = (int *)
1752 CMSG_DATA(mtod(*controlp, struct cmsghdr *));
1753 if (fdallocn(td, 0, fdp, newfds) != 0) {
1754 FILEDESC_XUNLOCK(td->td_proc->p_fd);
1755 error = EMSGSIZE;
1756 unp_freerights(fdep, newfds);
1757 m_freem(*controlp);
1758 *controlp = NULL;
1759 goto next;
1760 }
1761 for (i = 0; i < newfds; i++, fdp++) {
1761 for (i = 0; i < newfds; i++, fdp++) {
1762 if (fdalloc(td, 0, &f))
1763 panic("unp_externalize fdalloc failed");
1764 fde = &fdesc->fd_ofiles[f];
1762 fde = &fdesc->fd_ofiles[*fdp];
1765 fde->fde_file = fdep[0]->fde_file;
1766 filecaps_move(&fdep[0]->fde_caps,
1767 &fde->fde_caps);
1768 if ((flags & MSG_CMSG_CLOEXEC) != 0)
1769 fde->fde_flags |= UF_EXCLOSE;
1770 unp_externalize_fp(fde->fde_file);
1763 fde->fde_file = fdep[0]->fde_file;
1764 filecaps_move(&fdep[0]->fde_caps,
1765 &fde->fde_caps);
1766 if ((flags & MSG_CMSG_CLOEXEC) != 0)
1767 fde->fde_flags |= UF_EXCLOSE;
1768 unp_externalize_fp(fde->fde_file);
1771 *fdp = f;
1772 }
1773 FILEDESC_XUNLOCK(fdesc);
1774 free(fdep[0], M_FILECAPS);
1775 } else {
1776 /* We can just copy anything else across. */
1777 if (error || controlp == NULL)
1778 goto next;
1779 *controlp = sbcreatecontrol(NULL, datalen,

--- 721 unchanged lines hidden ---
1769 }
1770 FILEDESC_XUNLOCK(fdesc);
1771 free(fdep[0], M_FILECAPS);
1772 } else {
1773 /* We can just copy anything else across. */
1774 if (error || controlp == NULL)
1775 goto next;
1776 *controlp = sbcreatecontrol(NULL, datalen,

--- 721 unchanged lines hidden ---