* unp_pcblist() walks the global list of struct unpcb's to generate a * pointer list, bumping the refcount on each unpcb. It then copies them out * sequentially, validating the generation number on each to see if it has * been detached. All of this is necessary because copyout() may sleep on * disk I/O. */
| 1792 | * disk I/O. |
| 1793 | */ |
| 1794 | static int |
| 1795 | unp_pcblist(SYSCTL_HANDLER_ARGS) |
| 1796 | { |
| 1797 | struct unpcb *unp, **unp_list; |
| 1798 | unp_gen_t gencnt; |
| 1799 | struct xunpgen *xug; |
| 1800 | struct unp_head *head; |
| 1801 | struct xunpcb *xu; |
| 1802 | u_int i; |
| 1803 | int error, n; |
| 1804 | |
| 1805 | switch ((intptr_t)arg1) { |
| 1806 | case SOCK_STREAM: |
| 1807 | head = &unp_shead; |
| 1808 | break; |
| 1809 | |
| 1810 | case SOCK_DGRAM: |
| 1811 | head = &unp_dhead; |
| 1812 | break; |
| 1813 | |
| 1814 | case SOCK_SEQPACKET: |
| 1815 | head = &unp_sphead; |
| 1816 | break; |
| 1817 | |
| 1818 | default: |
| 1819 | panic("unp_pcblist: arg1 %d", (int)(intptr_t)arg1); |
| 1820 | } |
| 1821 | |
| 1822 | /* |
| 1823 | * The process of preparing the PCB list is too time-consuming and |
| 1824 | * resource-intensive to repeat twice on every request. |
| 1825 | */ |
| 1826 | if (req->oldptr == NULL) { |
| 1827 | n = unp_count; |
| 1828 | req->oldidx = 2 * (sizeof *xug) |
| 1829 | + (n + n/8) * sizeof(struct xunpcb); |
| 1830 | return (0); |
| 1831 | } |
| 1832 | |
| 1833 | if (req->newptr != NULL) |
| 1834 | return (EPERM); |
| 1835 | |
| 1836 | /* |
| 1837 | * OK, now we're committed to doing something. |
| 1838 | */ |
| 1839 | xug = malloc(sizeof(*xug), M_TEMP, M_WAITOK | M_ZERO); |
| 1840 | UNP_LINK_RLOCK(); |
| 1841 | gencnt = unp_gencnt; |
| 1842 | n = unp_count; |
| 1843 | UNP_LINK_RUNLOCK(); |
| 1844 | |
| 1845 | xug->xug_len = sizeof *xug; |
| 1846 | xug->xug_count = n; |
| 1847 | xug->xug_gen = gencnt; |
| 1848 | xug->xug_sogen = so_gencnt; |
| 1849 | error = SYSCTL_OUT(req, xug, sizeof *xug); |
| 1850 | if (error) { |
| 1851 | free(xug, M_TEMP); |
nothing calls this directly
no test coverage detected