/usr/include/X11/Xtrans/Xtranslcl.c is in xtrans-dev 1.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 | /*
Copyright 1993, 1994, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
*
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name NCR not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission. NCR makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* NCR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL NCR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
*
* The connection code/ideas in lib/X and server/os for SVR4/Intel
* environments was contributed by the following companies/groups:
*
* MetroLink Inc
* NCR
* Pittsburgh Powercomputing Corporation (PPc)/Quarterdeck Office Systems
* SGCS
* Unix System Laboratories (USL) / Novell
* XFree86
*
* The goal is to have common connection code among all SVR4/Intel vendors.
*
* ALL THE ABOVE COMPANIES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
* IN NO EVENT SHALL THESE COMPANIES * BE LIABLE FOR ANY SPECIAL, INDIRECT
* OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
* OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <ctype.h>
#include <sys/signal.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#if defined(SVR4) || defined(__SVR4)
#include <sys/filio.h>
#endif
#ifdef sun
# include <stropts.h>
#else
# include <sys/stropts.h>
#endif
#include <sys/wait.h>
#include <sys/types.h>
/*
* The local transports should be treated the same as a UNIX domain socket
* wrt authentication, etc. Because of this, we will use struct sockaddr_un
* for the address format. This will simplify the code in other places like
* The X Server.
*/
#include <sys/socket.h>
#ifndef X_NO_SYS_UN
#include <sys/un.h>
#endif
/* Types of local connections supported:
* - PTS
* - named pipes
* - SCO
*/
#if !defined(sun)
# define LOCAL_TRANS_PTS
#endif
#if defined(SVR4) || defined(__SVR4)
# define LOCAL_TRANS_NAMED
#endif
#if defined(__SCO__) || defined(__UNIXWARE__)
# define LOCAL_TRANS_SCO
#endif
static int TRANS(LocalClose)(XtransConnInfo ciptr);
/*
* These functions actually implement the local connection mechanisms.
*/
/* Type Not Supported */
static int
TRANS(OpenFail)(XtransConnInfo ciptr _X_UNUSED, const char *port _X_UNUSED)
{
return -1;
}
#ifdef TRANS_REOPEN
static int
TRANS(ReopenFail)(XtransConnInfo ciptr _X_UNUSED, int fd _X_UNUSED,
const char *port _X_UNUSED)
{
return 0;
}
#endif /* TRANS_REOPEN */
#if XTRANS_SEND_FDS
static int
TRANS(LocalRecvFdInvalid)(XtransConnInfo ciptr)
{
errno = EINVAL;
return -1;
}
static int
TRANS(LocalSendFdInvalid)(XtransConnInfo ciptr, int fd, int do_close)
{
errno = EINVAL;
return -1;
}
#endif
static int
TRANS(FillAddrInfo)(XtransConnInfo ciptr,
const char *sun_path, const char *peer_sun_path)
{
struct sockaddr_un *sunaddr;
struct sockaddr_un *p_sunaddr;
ciptr->family = AF_UNIX;
ciptr->addrlen = sizeof (struct sockaddr_un);
if ((sunaddr = malloc (ciptr->addrlen)) == NULL)
{
prmsg(1,"FillAddrInfo: failed to allocate memory for addr\n");
return 0;
}
sunaddr->sun_family = AF_UNIX;
if (strlen(sun_path) > sizeof(sunaddr->sun_path) - 1) {
prmsg(1, "FillAddrInfo: path too long\n");
free((char *) sunaddr);
return 0;
}
strcpy (sunaddr->sun_path, sun_path);
#if defined(BSD44SOCKETS)
sunaddr->sun_len = strlen (sunaddr->sun_path);
#endif
ciptr->addr = (char *) sunaddr;
ciptr->peeraddrlen = sizeof (struct sockaddr_un);
if ((p_sunaddr = malloc (ciptr->peeraddrlen)) == NULL)
{
prmsg(1,
"FillAddrInfo: failed to allocate memory for peer addr\n");
free (sunaddr);
ciptr->addr = NULL;
return 0;
}
p_sunaddr->sun_family = AF_UNIX;
if (strlen(peer_sun_path) > sizeof(p_sunaddr->sun_path) - 1) {
prmsg(1, "FillAddrInfo: peer path too long\n");
free((char *) p_sunaddr);
return 0;
}
strcpy (p_sunaddr->sun_path, peer_sun_path);
#if defined(BSD44SOCKETS)
p_sunaddr->sun_len = strlen (p_sunaddr->sun_path);
#endif
ciptr->peeraddr = (char *) p_sunaddr;
return 1;
}
#ifdef LOCAL_TRANS_PTS
/* PTS */
#if defined(SYSV) && !defined(__SCO__)
#define SIGNAL_T int
#else
#define SIGNAL_T void
#endif /* SYSV */
typedef SIGNAL_T (*PFV)();
extern PFV signal();
extern char *ptsname(
int
);
static void _dummy(int sig _X_UNUSED)
{
}
#endif /* LOCAL_TRANS_PTS */
#ifndef sun
#define X_STREAMS_DIR "/dev/X"
#define DEV_SPX "/dev/spx"
#else
#ifndef X11_t
#define X_STREAMS_DIR "/dev/X"
#else
#define X_STREAMS_DIR "/tmp/.X11-pipe"
#endif
#endif
#define DEV_PTMX "/dev/ptmx"
#if defined(X11_t)
#define PTSNODENAME "/dev/X/server."
#ifdef sun
#define NAMEDNODENAME "/tmp/.X11-pipe/X"
#else
#define NAMEDNODENAME "/dev/X/Nserver."
#define SCORNODENAME "/dev/X%1sR"
#define SCOSNODENAME "/dev/X%1sS"
#endif /* !sun */
#endif
#if defined(XIM_t)
#ifdef sun
#define NAMEDNODENAME "/tmp/.XIM-pipe/XIM"
#else
#define PTSNODENAME "/dev/X/XIM."
#define NAMEDNODENAME "/dev/X/NXIM."
#define SCORNODENAME "/dev/XIM.%sR"
#define SCOSNODENAME "/dev/XIM.%sS"
#endif
#endif
#if defined(FS_t) || defined (FONT_t)
#ifdef sun
#define NAMEDNODENAME "/tmp/.font-pipe/fs"
#else
/*
* USL has already defined something here. We need to check with them
* and see if their choice is usable here.
*/
#define PTSNODENAME "/dev/X/fontserver."
#define NAMEDNODENAME "/dev/X/Nfontserver."
#define SCORNODENAME "/dev/fontserver.%sR"
#define SCOSNODENAME "/dev/fontserver.%sS"
#endif
#endif
#if defined(ICE_t)
#ifdef sun
#define NAMEDNODENAME "/tmp/.ICE-pipe/"
#else
#define PTSNODENAME "/dev/X/ICE."
#define NAMEDNODENAME "/dev/X/NICE."
#define SCORNODENAME "/dev/ICE.%sR"
#define SCOSNODENAME "/dev/ICE.%sS"
#endif
#endif
#if defined(TEST_t)
#ifdef sun
#define NAMEDNODENAME "/tmp/.Test-unix/test"
#endif
#define PTSNODENAME "/dev/X/transtest."
#define NAMEDNODENAME "/dev/X/Ntranstest."
#define SCORNODENAME "/dev/transtest.%sR"
#define SCOSNODENAME "/dev/transtest.%sS"
#endif
#ifdef LOCAL_TRANS_PTS
#ifdef TRANS_CLIENT
static int
TRANS(PTSOpenClient)(XtransConnInfo ciptr, const char *port)
{
#ifdef PTSNODENAME
int fd,server,exitval,alarm_time,ret;
char server_path[64];
char *slave, namelen;
char buf[20]; /* MAX_PATH_LEN?? */
PFV savef;
pid_t saved_pid;
#endif
prmsg(2,"PTSOpenClient(%s)\n", port);
#if !defined(PTSNODENAME)
prmsg(1,"PTSOpenClient: Protocol is not supported by a pts connection\n");
return -1;
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
snprintf(server_path, sizeof(server_path), "%s", port);
} else {
snprintf(server_path, sizeof(server_path), "%s%s",
PTSNODENAME, port);
}
} else {
snprintf(server_path, sizeof(server_path), "%s%d",
PTSNODENAME, getpid());
}
/*
* Open the node the on which the server is listening.
*/
if ((server = open (server_path, O_RDWR)) < 0) {
prmsg(1,"PTSOpenClient: failed to open %s\n", server_path);
return -1;
}
/*
* Open the streams based pipe that will be this connection.
*/
if ((fd = open(DEV_PTMX, O_RDWR)) < 0) {
prmsg(1,"PTSOpenClient: failed to open %s\n", DEV_PTMX);
close(server);
return(-1);
}
(void) grantpt(fd);
(void) unlockpt(fd);
slave = ptsname(fd); /* get name */
if( slave == NULL ) {
prmsg(1,"PTSOpenClient: failed to get ptsname()\n");
close(fd);
close(server);
return -1;
}
/*
* This is neccesary for the case where a program is setuid to non-root.
* grantpt() calls /usr/lib/pt_chmod which is set-uid root. This program will
* set the owner of the pt device incorrectly if the uid is not restored
* before it is called. The problem is that once it gets restored, it
* cannot be changed back to its original condition, hence the fork().
*/
if(!(saved_pid=fork())) {
uid_t saved_euid;
saved_euid = geteuid();
/** sets the euid to the actual/real uid **/
if (setuid( getuid() ) == -1) {
exit(1);
}
if( chown( slave, saved_euid, -1 ) < 0 ) {
exit( 1 );
}
exit( 0 );
}
waitpid(saved_pid, &exitval, 0);
if (WIFEXITED(exitval) && WEXITSTATUS(exitval) != 0) {
close(fd);
close(server);
prmsg(1, "PTSOpenClient: cannot set the owner of %s\n",
slave);
return(-1);
}
if (chmod(slave, 0666) < 0) {
close(fd);
close(server);
prmsg(1,"PTSOpenClient: Cannot chmod %s\n", slave);
return(-1);
}
/*
* write slave name to server
*/
namelen = strlen(slave);
buf[0] = namelen;
(void) sprintf(&buf[1], slave);
(void) write(server, buf, namelen+1);
(void) close(server);
/*
* wait for server to respond
*/
savef = signal(SIGALRM, _dummy);
alarm_time = alarm (30); /* CONNECT_TIMEOUT */
ret = read(fd, buf, 1);
(void) alarm(alarm_time);
(void) signal(SIGALRM, savef);
if (ret != 1) {
prmsg(1,
"PTSOpenClient: failed to get acknoledgement from server\n");
(void) close(fd);
fd = -1;
}
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
if (TRANS(FillAddrInfo) (ciptr, slave, server_path) == 0)
{
prmsg(1,"PTSOpenClient: failed to fill in addr info\n");
close(fd);
return -1;
}
return(fd);
#endif /* !PTSNODENAME */
}
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
static int
TRANS(PTSOpenServer)(XtransConnInfo ciptr, const char *port)
{
#ifdef PTSNODENAME
int fd, server;
char server_path[64], *slave;
int mode;
#endif
prmsg(2,"PTSOpenServer(%s)\n", port);
#if !defined(PTSNODENAME)
prmsg(1,"PTSOpenServer: Protocol is not supported by a pts connection\n");
return -1;
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
(void) sprintf(server_path, "%s", port);
} else {
(void) sprintf(server_path, "%s%s", PTSNODENAME, port);
}
} else {
(void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());
}
#ifdef HAS_STICKY_DIR_BIT
mode = 01777;
#else
mode = 0777;
#endif
if (trans_mkdir(X_STREAMS_DIR, mode) == -1) {
prmsg (1, "PTSOpenServer: mkdir(%s) failed, errno = %d\n",
X_STREAMS_DIR, errno);
return(-1);
}
#if 0
if( (fd=open(server_path, O_RDWR)) >= 0 ) {
/*
* This doesn't prevent the server from starting up, and doesn't
* prevent clients from trying to connect to the in-use PTS (which
* is often in use by something other than another server).
*/
prmsg(1, "PTSOpenServer: A server is already running on port %s\n", port);
prmsg(1, "PTSOpenServer: Remove %s if this is incorrect.\n", server_path);
close(fd);
return(-1);
}
#else
/* Just remove the old path (which is what happens with UNIXCONN) */
#endif
unlink(server_path);
if( (fd=open(DEV_PTMX, O_RDWR)) < 0) {
prmsg(1, "PTSOpenServer: Unable to open %s\n", DEV_PTMX);
return(-1);
}
grantpt(fd);
unlockpt(fd);
if( (slave=ptsname(fd)) == NULL) {
prmsg(1, "PTSOpenServer: Unable to get slave device name\n");
close(fd);
return(-1);
}
if( link(slave,server_path) < 0 ) {
prmsg(1, "PTSOpenServer: Unable to link %s to %s\n", slave, server_path);
close(fd);
return(-1);
}
if( chmod(server_path, 0666) < 0 ) {
prmsg(1, "PTSOpenServer: Unable to chmod %s to 0666\n", server_path);
close(fd);
return(-1);
}
if( (server=open(server_path, O_RDWR)) < 0 ) {
prmsg(1, "PTSOpenServer: Unable to open server device %s\n", server_path);
close(fd);
return(-1);
}
close(server);
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
prmsg(1,"PTSOpenServer: failed to fill in addr info\n");
close(fd);
return -1;
}
return fd;
#endif /* !PTSNODENAME */
}
static int
TRANS(PTSAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
{
int newfd;
int in;
unsigned char length;
char buf[256];
struct sockaddr_un *sunaddr;
prmsg(2,"PTSAccept(%x->%d)\n",ciptr,ciptr->fd);
if( (in=read(ciptr->fd,&length,1)) <= 0 ){
if( !in ) {
prmsg(2,
"PTSAccept: Incoming connection closed\n");
}
else {
prmsg(1,
"PTSAccept: Error reading incoming connection. errno=%d \n",
errno);
}
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
}
if( (in=read(ciptr->fd,buf,length)) <= 0 ){
if( !in ) {
prmsg(2,
"PTSAccept: Incoming connection closed\n");
}
else {
prmsg(1,
"PTSAccept: Error reading device name for new connection. errno=%d \n",
errno);
}
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
}
buf[length] = '\0';
if( (newfd=open(buf,O_RDWR)) < 0 ) {
prmsg(1, "PTSAccept: Failed to open %s\n",buf);
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
}
write(newfd,"1",1);
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
newciptr->addrlen=ciptr->addrlen;
if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n");
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
}
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
newciptr->peeraddrlen=sizeof(struct sockaddr_un);
if( (sunaddr = malloc(newciptr->peeraddrlen)) == NULL ) {
prmsg(1,"PTSAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(newfd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
}
sunaddr->sun_family=AF_UNIX;
strcpy(sunaddr->sun_path,buf);
#if defined(BSD44SOCKETS)
sunaddr->sun_len=strlen(sunaddr->sun_path);
#endif
newciptr->peeraddr=(char *)sunaddr;
*status = 0;
return newfd;
}
#endif /* TRANS_SERVER */
#endif /* LOCAL_TRANS_PTS */
#ifdef LOCAL_TRANS_NAMED
/* NAMED */
#ifdef TRANS_CLIENT
static int
TRANS(NAMEDOpenClient)(XtransConnInfo ciptr, const char *port)
{
#ifdef NAMEDNODENAME
int fd;
char server_path[64];
struct stat filestat;
# ifndef sun
extern int isastream(int);
# endif
#endif
prmsg(2,"NAMEDOpenClient(%s)\n", port);
#if !defined(NAMEDNODENAME)
prmsg(1,"NAMEDOpenClient: Protocol is not supported by a NAMED connection\n");
return -1;
#else
if ( port && *port ) {
if( *port == '/' ) { /* A full pathname */
(void) snprintf(server_path, sizeof(server_path), "%s", port);
} else {
(void) snprintf(server_path, sizeof(server_path), "%s%s", NAMEDNODENAME, port);
}
} else {
(void) snprintf(server_path, sizeof(server_path), "%s%ld", NAMEDNODENAME, (long)getpid());
}
if ((fd = open(server_path, O_RDWR)) < 0) {
prmsg(1,"NAMEDOpenClient: Cannot open %s for NAMED connection\n", server_path);
return -1;
}
if (fstat(fd, &filestat) < 0 ) {
prmsg(1,"NAMEDOpenClient: Cannot stat %s for NAMED connection\n", server_path);
(void) close(fd);
return -1;
}
if ((filestat.st_mode & S_IFMT) != S_IFIFO) {
prmsg(1,"NAMEDOpenClient: Device %s is not a FIFO\n", server_path);
/* Is this really a failure? */
(void) close(fd);
return -1;
}
if (isastream(fd) <= 0) {
prmsg(1,"NAMEDOpenClient: %s is not a streams device\n", server_path);
(void) close(fd);
return -1;
}
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
prmsg(1,"NAMEDOpenClient: failed to fill in addr info\n");
close(fd);
return -1;
}
return(fd);
#endif /* !NAMEDNODENAME */
}
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
#ifdef NAMEDNODENAME
static int
TRANS(NAMEDOpenPipe)(const char *server_path)
{
int fd, pipefd[2];
struct stat sbuf;
int mode;
prmsg(2,"NAMEDOpenPipe(%s)\n", server_path);
#ifdef HAS_STICKY_DIR_BIT
mode = 01777;
#else
mode = 0777;
#endif
if (trans_mkdir(X_STREAMS_DIR, mode) == -1) {
prmsg (1, "NAMEDOpenPipe: mkdir(%s) failed, errno = %d\n",
X_STREAMS_DIR, errno);
return(-1);
}
if(stat(server_path, &sbuf) != 0) {
if (errno == ENOENT) {
if ((fd = creat(server_path, (mode_t)0666)) == -1) {
prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path);
return(-1);
}
close(fd);
if (chmod(server_path, (mode_t)0666) < 0) {
prmsg(1, "NAMEDOpenPipe: Can't open %s\n", server_path);
return(-1);
}
} else {
prmsg(1, "NAMEDOpenPipe: stat on %s failed\n", server_path);
return(-1);
}
}
if( pipe(pipefd) != 0) {
prmsg(1, "NAMEDOpenPipe: pipe() failed, errno=%d\n",errno);
return(-1);
}
if( ioctl(pipefd[0], I_PUSH, "connld") != 0) {
prmsg(1, "NAMEDOpenPipe: ioctl(I_PUSH,\"connld\") failed, errno=%d\n",errno);
close(pipefd[0]);
close(pipefd[1]);
return(-1);
}
if( fattach(pipefd[0], server_path) != 0) {
prmsg(1, "NAMEDOpenPipe: fattach(%s) failed, errno=%d\n", server_path,errno);
close(pipefd[0]);
close(pipefd[1]);
return(-1);
}
return(pipefd[1]);
}
#endif
static int
TRANS(NAMEDOpenServer)(XtransConnInfo ciptr, const char *port)
{
#ifdef NAMEDNODENAME
int fd;
char server_path[64];
#endif
prmsg(2,"NAMEDOpenServer(%s)\n", port);
#if !defined(NAMEDNODENAME)
prmsg(1,"NAMEDOpenServer: Protocol is not supported by a NAMED connection\n");
return -1;
#else
if ( port && *port ) {
if( *port == '/' ) { /* A full pathname */
(void) snprintf(server_path, sizeof(server_path), "%s", port);
} else {
(void) snprintf(server_path, sizeof(server_path), "%s%s",
NAMEDNODENAME, port);
}
} else {
(void) snprintf(server_path, sizeof(server_path), "%s%ld",
NAMEDNODENAME, (long)getpid());
}
fd = TRANS(NAMEDOpenPipe)(server_path);
if (fd < 0) {
return -1;
}
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
prmsg(1,"NAMEDOpenServer: failed to fill in addr info\n");
TRANS(LocalClose)(ciptr);
return -1;
}
return fd;
#endif /* !NAMEDNODENAME */
}
static int
TRANS(NAMEDResetListener) (XtransConnInfo ciptr)
{
struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr;
struct stat statb;
prmsg(2,"NAMEDResetListener(%p, %d)\n", ciptr, ciptr->fd);
if (ciptr->fd != -1) {
/*
* see if the pipe has disappeared
*/
if (stat (sockname->sun_path, &statb) == -1 ||
(statb.st_mode & S_IFMT) != S_IFIFO) {
prmsg(3, "Pipe %s trashed, recreating\n", sockname->sun_path);
TRANS(LocalClose)(ciptr);
ciptr->fd = TRANS(NAMEDOpenPipe)(sockname->sun_path);
if (ciptr->fd >= 0)
return TRANS_RESET_NEW_FD;
else
return TRANS_CREATE_LISTENER_FAILED;
}
}
return TRANS_RESET_NOOP;
}
static int
TRANS(NAMEDAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
{
struct strrecvfd str;
prmsg(2,"NAMEDAccept(%p->%d)\n", ciptr, ciptr->fd);
if( ioctl(ciptr->fd, I_RECVFD, &str ) < 0 ) {
prmsg(1, "NAMEDAccept: ioctl(I_RECVFD) failed, errno=%d\n", errno);
*status = TRANS_ACCEPT_MISC_ERROR;
return(-1);
}
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
newciptr->family=ciptr->family;
newciptr->addrlen=ciptr->addrlen;
if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
prmsg(1,
"NAMEDAccept: failed to allocate memory for pipe addr\n");
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
}
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
newciptr->peeraddrlen=newciptr->addrlen;
if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) {
prmsg(1,
"NAMEDAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(str.fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
}
memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);
*status = 0;
return str.fd;
}
#endif /* TRANS_SERVER */
#endif /* LOCAL_TRANS_NAMED */
#if defined(LOCAL_TRANS_SCO)
/*
* connect_spipe is used by the SCO connection type.
*/
static int
connect_spipe(int fd1, int fd2)
{
long temp;
struct strfdinsert sbuf;
sbuf.databuf.maxlen = -1;
sbuf.databuf.len = -1;
sbuf.databuf.buf = NULL;
sbuf.ctlbuf.maxlen = sizeof(long);
sbuf.ctlbuf.len = sizeof(long);
sbuf.ctlbuf.buf = (caddr_t)&temp;
sbuf.offset = 0;
sbuf.fildes = fd2;
sbuf.flags = 0;
if( ioctl(fd1, I_FDINSERT, &sbuf) < 0 )
return(-1);
return(0);
}
/*
* named_spipe is used by the SCO connection type.
*/
static int
named_spipe(int fd, char *path)
{
int oldUmask, ret;
struct stat sbuf;
oldUmask = umask(0);
(void) fstat(fd, &sbuf);
ret = mknod(path, 0020666, sbuf.st_rdev);
umask(oldUmask);
if (ret < 0) {
ret = -1;
} else {
ret = fd;
}
return(ret);
}
#endif /* defined(LOCAL_TRANS_SCO) */
#ifdef LOCAL_TRANS_SCO
/* SCO */
/*
* 2002-11-09 (jkj@sco.com)
*
* This code has been modified to match what is in the actual SCO X server.
* This greatly helps inter-operability between X11R6 and X11R5 (the native
* SCO server). Mainly, it relies on streams nodes existing in /dev, not
* creating them or unlinking them, which breaks the native X server.
*
* However, this is only for the X protocol. For all other protocols, we
* do in fact create the nodes, as only X11R6 will use them, and this makes
* it possible to have both types of clients running, otherwise we get all
* kinds of nasty errors on startup for anything that doesnt use the X
* protocol (like SM, when KDE starts up).
*/
#ifdef TRANS_CLIENT
static int
TRANS(SCOOpenClient)(XtransConnInfo ciptr, const char *port)
{
#ifdef SCORNODENAME
int fd, server, fl, ret;
char server_path[64];
struct strbuf ctlbuf;
unsigned long alarm_time;
void (*savef)();
long temp;
extern int getmsg(), putmsg();
#endif
prmsg(2,"SCOOpenClient(%s)\n", port);
if (!port || !port[0])
port = "0";
#if !defined(SCORNODENAME)
prmsg(2,"SCOOpenClient: Protocol is not supported by a SCO connection\n");
return -1;
#else
(void) sprintf(server_path, SCORNODENAME, port);
if ((server = open(server_path, O_RDWR)) < 0) {
prmsg(1,"SCOOpenClient: failed to open %s\n", server_path);
return -1;
}
if ((fd = open(DEV_SPX, O_RDWR)) < 0) {
prmsg(1,"SCOOpenClient: failed to open %s\n", DEV_SPX);
close(server);
return -1;
}
(void) write(server, &server, 1);
ctlbuf.len = 0;
ctlbuf.maxlen = sizeof(long);
ctlbuf.buf = (caddr_t)&temp;
fl = 0;
savef = signal(SIGALRM, _dummy);
alarm_time = alarm(10);
ret = getmsg(server, &ctlbuf, 0, &fl);
(void) alarm(alarm_time);
(void) signal(SIGALRM, savef);
if (ret < 0) {
prmsg(1,"SCOOpenClient: error from getmsg\n");
close(fd);
close(server);
return -1;
}
/* The msg we got via getmsg is the result of an
* I_FDINSERT, so if we do a putmsg with whatever
* we recieved, we're doing another I_FDINSERT ...
*/
(void) putmsg(fd, &ctlbuf, 0, 0);
(void) fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0)|O_NDELAY);
(void) close(server);
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
#if defined(X11_t) && defined(__SCO__)
ciptr->flags |= TRANS_NOUNLINK;
#endif
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
prmsg(1,"SCOOpenClient: failed to fill addr info\n");
close(fd);
return -1;
}
return(fd);
#endif /* !SCORNODENAME */
}
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
static int
TRANS(SCOOpenServer)(XtransConnInfo ciptr, const char *port)
{
#ifdef SCORNODENAME
char serverR_path[64];
char serverS_path[64];
struct flock mylock;
int fdr = -1;
int fds = -1;
#endif
prmsg(2,"SCOOpenServer(%s)\n", port);
if (!port || !port[0])
port = "0";
#if !defined(SCORNODENAME)
prmsg(1,"SCOOpenServer: Protocol is not supported by a SCO connection\n");
return -1;
#else
(void) sprintf(serverR_path, SCORNODENAME, port);
(void) sprintf(serverS_path, SCOSNODENAME, port);
#if !defined(X11_t) || !defined(__SCO__)
unlink(serverR_path);
unlink(serverS_path);
if ((fds = open(DEV_SPX, O_RDWR)) < 0 ||
(fdr = open(DEV_SPX, O_RDWR)) < 0 ) {
prmsg(1,"SCOOpenServer: failed to open %s\n", DEV_SPX);
if (fds >= 0)
close(fds);
if (fdr >= 0)
close(fdr);
return -1;
}
if (named_spipe (fds, serverS_path) == -1) {
prmsg(1,"SCOOpenServer: failed to create %s\n", serverS_path);
close (fdr);
close (fds);
return -1;
}
if (named_spipe (fdr, serverR_path) == -1) {
prmsg(1,"SCOOpenServer: failed to create %s\n", serverR_path);
close (fdr);
close (fds);
return -1;
}
#else /* X11_t */
fds = open (serverS_path, O_RDWR | O_NDELAY);
if (fds < 0) {
prmsg(1,"SCOOpenServer: failed to open %s\n", serverS_path);
return -1;
}
/*
* Lock the connection device for the duration of the server.
* This resolves multiple server starts especially on SMP machines.
*/
mylock.l_type = F_WRLCK;
mylock.l_whence = 0;
mylock.l_start = 0;
mylock.l_len = 0;
if (fcntl (fds, F_SETLK, &mylock) < 0) {
prmsg(1,"SCOOpenServer: failed to lock %s\n", serverS_path);
close (fds);
return -1;
}
fdr = open (serverR_path, O_RDWR | O_NDELAY);
if (fdr < 0) {
prmsg(1,"SCOOpenServer: failed to open %s\n", serverR_path);
close (fds);
return -1;
}
#endif /* X11_t */
if (connect_spipe(fds, fdr)) {
prmsg(1,"SCOOpenServer: ioctl(I_FDINSERT) failed on %s\n",
serverS_path);
close (fdr);
close (fds);
return -1;
}
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
#if defined(X11_t) && defined(__SCO__)
ciptr->flags |= TRANS_NOUNLINK;
#endif
if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0) {
prmsg(1,"SCOOpenServer: failed to fill in addr info\n");
close(fds);
close(fdr);
return -1;
}
return(fds);
#endif /* !SCORNODENAME */
}
static int
TRANS(SCOAccept)(XtransConnInfo ciptr, XtransConnInfo newciptr, int *status)
{
char c;
int fd;
prmsg(2,"SCOAccept(%d)\n", ciptr->fd);
if (read(ciptr->fd, &c, 1) < 0) {
prmsg(1,"SCOAccept: can't read from client\n");
*status = TRANS_ACCEPT_MISC_ERROR;
return(-1);
}
if( (fd = open(DEV_SPX, O_RDWR)) < 0 ) {
prmsg(1,"SCOAccept: can't open \"%s\"\n",DEV_SPX);
*status = TRANS_ACCEPT_MISC_ERROR;
return(-1);
}
if (connect_spipe (ciptr->fd, fd) < 0) {
prmsg(1,"SCOAccept: ioctl(I_FDINSERT) failed\n");
close (fd);
*status = TRANS_ACCEPT_MISC_ERROR;
return -1;
}
/*
* Everything looks good: fill in the XtransConnInfo structure.
*/
newciptr->addrlen=ciptr->addrlen;
if( (newciptr->addr = malloc(newciptr->addrlen)) == NULL ) {
prmsg(1,
"SCOAccept: failed to allocate memory for peer addr\n");
close(fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
}
memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);
#if defined(__SCO__)
newciptr->flags |= TRANS_NOUNLINK;
#endif
newciptr->peeraddrlen=newciptr->addrlen;
if( (newciptr->peeraddr = malloc(newciptr->peeraddrlen)) == NULL ) {
prmsg(1,
"SCOAccept: failed to allocate memory for peer addr\n");
free(newciptr->addr);
close(fd);
*status = TRANS_ACCEPT_BAD_MALLOC;
return -1;
}
memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);
*status = 0;
return(fd);
}
#endif /* TRANS_SERVER */
#endif /* LOCAL_TRANS_SCO */
#ifdef TRANS_REOPEN
#ifdef LOCAL_TRANS_PTS
static int
TRANS(PTSReopenServer)(XtransConnInfo ciptr, int fd, const char *port)
{
#ifdef PTSNODENAME
char server_path[64];
#endif
prmsg(2,"PTSReopenServer(%d,%s)\n", fd, port);
#if !defined(PTSNODENAME)
prmsg(1,"PTSReopenServer: Protocol is not supported by a pts connection\n");
return 0;
#else
if (port && *port ) {
if( *port == '/' ) { /* A full pathname */
snprintf(server_path, sizeof(server_path), "%s", port);
} else {
snprintf(server_path, sizeof(server_path), "%s%s",
PTSNODENAME, port);
}
} else {
snprintf(server_path, sizeof(server_path), "%s%ld",
PTSNODENAME, (long)getpid());
}
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
prmsg(1,"PTSReopenServer: failed to fill in addr info\n");
return 0;
}
return 1;
#endif /* !PTSNODENAME */
}
#endif /* LOCAL_TRANS_PTS */
#ifdef LOCAL_TRANS_NAMED
static int
TRANS(NAMEDReopenServer)(XtransConnInfo ciptr, int fd _X_UNUSED, const char *port)
{
#ifdef NAMEDNODENAME
char server_path[64];
#endif
prmsg(2,"NAMEDReopenServer(%s)\n", port);
#if !defined(NAMEDNODENAME)
prmsg(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n");
return 0;
#else
if ( port && *port ) {
if( *port == '/' ) { /* A full pathname */
snprintf(server_path, sizeof(server_path),"%s", port);
} else {
snprintf(server_path, sizeof(server_path), "%s%s",
NAMEDNODENAME, port);
}
} else {
snprintf(server_path, sizeof(server_path), "%s%ld",
NAMEDNODENAME, (long)getpid());
}
if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)
{
prmsg(1,"NAMEDReopenServer: failed to fill in addr info\n");
return 0;
}
return 1;
#endif /* !NAMEDNODENAME */
}
#endif /* LOCAL_TRANS_NAMED */
#ifdef LOCAL_TRANS_SCO
static int
TRANS(SCOReopenServer)(XtransConnInfo ciptr, int fd, const char *port)
{
#ifdef SCORNODENAME
char serverR_path[64], serverS_path[64];
#endif
prmsg(2,"SCOReopenServer(%s)\n", port);
if (!port || !port[0])
port = "0";
#if !defined(SCORNODENAME)
prmsg(2,"SCOReopenServer: Protocol is not supported by a SCO connection\n");
return 0;
#else
(void) sprintf(serverR_path, SCORNODENAME, port);
(void) sprintf(serverS_path, SCOSNODENAME, port);
#if defined(X11_t) && defined(__SCO__)
ciptr->flags |= TRANS_NOUNLINK;
#endif
if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0)
{
prmsg(1, "SCOReopenServer: failed to fill in addr info\n");
return 0;
}
return 1;
#endif /* SCORNODENAME */
}
#endif /* LOCAL_TRANS_SCO */
#endif /* TRANS_REOPEN */
/*
* This table contains all of the entry points for the different local
* connection mechanisms.
*/
typedef struct _LOCALtrans2dev {
const char *transname;
#ifdef TRANS_CLIENT
int (*devcotsopenclient)(
XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
int (*devcotsopenserver)(
XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
int (*devcltsopenclient)(
XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
int (*devcltsopenserver)(
XtransConnInfo, const char * /*port*/
);
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
int (*devcotsreopenserver)(
XtransConnInfo,
int, /* fd */
const char * /* port */
);
int (*devcltsreopenserver)(
XtransConnInfo,
int, /* fd */
const char * /* port */
);
#endif /* TRANS_REOPEN */
#ifdef TRANS_SERVER
int (*devreset)(
XtransConnInfo /* ciptr */
);
int (*devaccept)(
XtransConnInfo, XtransConnInfo, int *
);
#endif /* TRANS_SERVER */
} LOCALtrans2dev;
static LOCALtrans2dev LOCALtrans2devtab[] = {
#ifdef LOCAL_TRANS_PTS
{"",
#ifdef TRANS_CLIENT
TRANS(PTSOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(PTSOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(PTSReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
{"local",
#ifdef TRANS_CLIENT
TRANS(PTSOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(PTSOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(PTSReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
{"pts",
#ifdef TRANS_CLIENT
TRANS(PTSOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(PTSOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(PTSReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
NULL, /* ResetListener */
TRANS(PTSAccept)
#endif /* TRANS_SERVER */
},
#else /* !LOCAL_TRANS_PTS */
{"",
#ifdef TRANS_CLIENT
TRANS(NAMEDOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(NAMEDOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(NAMEDReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
{"local",
#ifdef TRANS_CLIENT
TRANS(NAMEDOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(NAMEDOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(NAMEDReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
#endif /* !LOCAL_TRANS_PTS */
#ifdef LOCAL_TRANS_NAMED
{"named",
#ifdef TRANS_CLIENT
TRANS(NAMEDOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(NAMEDOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(NAMEDReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
#ifdef sun /* Alias "pipe" to named, since that's what Solaris called it */
{"pipe",
#ifdef TRANS_CLIENT
TRANS(NAMEDOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(NAMEDOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(NAMEDReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
TRANS(NAMEDResetListener),
TRANS(NAMEDAccept)
#endif /* TRANS_SERVER */
},
#endif /* sun */
#endif /* LOCAL_TRANS_NAMED */
#ifdef LOCAL_TRANS_SCO
{"sco",
#ifdef TRANS_CLIENT
TRANS(SCOOpenClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(SCOOpenServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(OpenFail),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(OpenFail),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(SCOReopenServer),
TRANS(ReopenFail),
#endif
#ifdef TRANS_SERVER
NULL, /* ResetListener */
TRANS(SCOAccept)
#endif /* TRANS_SERVER */
},
#endif /* LOCAL_TRANS_SCO */
};
#define NUMTRANSPORTS (sizeof(LOCALtrans2devtab)/sizeof(LOCALtrans2dev))
static const char *XLOCAL=NULL;
static char *workingXLOCAL=NULL;
static char *freeXLOCAL=NULL;
#if defined(__SCO__)
#define DEF_XLOCAL "SCO:UNIX:PTS"
#elif defined(__UNIXWARE__)
#define DEF_XLOCAL "UNIX:PTS:NAMED:SCO"
#elif defined(sun)
#define DEF_XLOCAL "UNIX:NAMED"
#else
#define DEF_XLOCAL "UNIX:PTS:NAMED:SCO"
#endif
static void
TRANS(LocalInitTransports)(const char *protocol)
{
prmsg(3,"LocalInitTransports(%s)\n", protocol);
if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") )
{
workingXLOCAL = freeXLOCAL = strdup (protocol);
}
else {
XLOCAL=(char *)getenv("XLOCAL");
if(XLOCAL==NULL)
XLOCAL=DEF_XLOCAL;
workingXLOCAL = freeXLOCAL = strdup (XLOCAL);
}
}
static void
TRANS(LocalEndTransports)(void)
{
prmsg(3,"LocalEndTransports()\n");
free(freeXLOCAL);
}
#define TYPEBUFSIZE 32
#ifdef TRANS_CLIENT
static LOCALtrans2dev *
TRANS(LocalGetNextTransport)(void)
{
int i,j;
char *typetocheck;
char typebuf[TYPEBUFSIZE];
prmsg(3,"LocalGetNextTransport()\n");
while(1)
{
if( workingXLOCAL == NULL || *workingXLOCAL == '\0' )
return NULL;
typetocheck=workingXLOCAL;
workingXLOCAL=strchr(workingXLOCAL,':');
if(workingXLOCAL && *workingXLOCAL)
*workingXLOCAL++='\0';
for(i=0;i<NUMTRANSPORTS;i++)
{
/*
* This is equivalent to a case insensitive strcmp(),
* but should be more portable.
*/
strncpy(typebuf,typetocheck,TYPEBUFSIZE);
for(j=0;j<TYPEBUFSIZE;j++)
if (isupper(typebuf[j]))
typebuf[j]=tolower(typebuf[j]);
/* Now, see if they match */
if(!strcmp(LOCALtrans2devtab[i].transname,typebuf))
return &LOCALtrans2devtab[i];
}
}
#if 0
/*NOTREACHED*/
return NULL;
#endif
}
#ifdef NEED_UTSNAME
#include <sys/utsname.h>
#endif
/*
* Make sure 'host' is really local.
*/
static int
HostReallyLocal (const char *host)
{
/*
* The 'host' passed to this function may have been generated
* by either uname() or gethostname(). We try both if possible.
*/
#ifdef NEED_UTSNAME
struct utsname name;
#endif
char buf[256];
#ifdef NEED_UTSNAME
if (uname (&name) >= 0 && strcmp (host, name.nodename) == 0)
return (1);
#endif
buf[0] = '\0';
(void) gethostname (buf, 256);
buf[255] = '\0';
if (strcmp (host, buf) == 0)
return (1);
return (0);
}
static XtransConnInfo
TRANS(LocalOpenClient)(int type, const char *protocol,
const char *host, const char *port)
{
LOCALtrans2dev *transptr;
XtransConnInfo ciptr;
int index;
prmsg(3,"LocalOpenClient()\n");
/*
* Make sure 'host' is really local. If not, we return failure.
* The reason we make this check is because a process may advertise
* a "local" address for which it can accept connections, but if a
* process on a remote machine tries to connect to this address,
* we know for sure it will fail.
*/
if (strcmp (host, "unix") != 0 && !HostReallyLocal (host))
{
prmsg (1,
"LocalOpenClient: Cannot connect to non-local host %s\n",
host);
return NULL;
}
#if defined(X11_t)
/*
* X has a well known port, that is transport dependant. It is easier
* to handle it here, than try and come up with a transport independent
* representation that can be passed in and resolved the usual way.
*
* The port that is passed here is really a string containing the idisplay
* from ConnectDisplay(). Since that is what we want for the local transports,
* we don't have to do anything special.
*/
#endif /* X11_t */
if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
prmsg(1,"LocalOpenClient: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
return NULL;
}
ciptr->fd = -1;
TRANS(LocalInitTransports)(protocol);
index = 0;
for(transptr=TRANS(LocalGetNextTransport)();
transptr!=NULL;transptr=TRANS(LocalGetNextTransport)(), index++)
{
switch( type )
{
case XTRANS_OPEN_COTS_CLIENT:
ciptr->fd=transptr->devcotsopenclient(ciptr,port);
break;
case XTRANS_OPEN_CLTS_CLIENT:
ciptr->fd=transptr->devcltsopenclient(ciptr,port);
break;
case XTRANS_OPEN_COTS_SERVER:
case XTRANS_OPEN_CLTS_SERVER:
prmsg(1,
"LocalOpenClient: Should not be opening a server with this function\n");
break;
default:
prmsg(1,
"LocalOpenClient: Unknown Open type %d\n",
type);
}
if( ciptr->fd >= 0 )
break;
}
TRANS(LocalEndTransports)();
if( ciptr->fd < 0 )
{
free(ciptr);
return NULL;
}
ciptr->priv=(char *)transptr;
ciptr->index = index;
return ciptr;
}
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
static XtransConnInfo
TRANS(LocalOpenServer)(int type, const char *protocol,
const char *host _X_UNUSED, const char *port)
{
int i;
XtransConnInfo ciptr;
prmsg(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port);
#if defined(X11_t)
/*
* For X11, the port will be in the format xserverN where N is the
* display number. All of the local connections just need to know
* the display number because they don't do any name resolution on
* the port. This just truncates port to the display portion.
*/
#endif /* X11_t */
if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
prmsg(1,"LocalOpenServer: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
return NULL;
}
for(i=1;i<NUMTRANSPORTS;i++)
{
if( strcmp(protocol,LOCALtrans2devtab[i].transname) != 0 )
continue;
switch( type )
{
case XTRANS_OPEN_COTS_CLIENT:
case XTRANS_OPEN_CLTS_CLIENT:
prmsg(1,
"LocalOpenServer: Should not be opening a client with this function\n");
break;
case XTRANS_OPEN_COTS_SERVER:
ciptr->fd=LOCALtrans2devtab[i].devcotsopenserver(ciptr,port);
break;
case XTRANS_OPEN_CLTS_SERVER:
ciptr->fd=LOCALtrans2devtab[i].devcltsopenserver(ciptr,port);
break;
default:
prmsg(1,"LocalOpenServer: Unknown Open type %d\n",
type );
}
if( ciptr->fd >= 0 ) {
ciptr->priv=(char *)&LOCALtrans2devtab[i];
ciptr->index=i;
ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS);
return ciptr;
}
}
free(ciptr);
return NULL;
}
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
static XtransConnInfo
TRANS(LocalReopenServer)(int type, int index, int fd, const char *port)
{
XtransConnInfo ciptr;
int stat = 0;
prmsg(2,"LocalReopenServer(%d,%d,%d)\n", type, index, fd);
if( (ciptr = calloc(1,sizeof(struct _XtransConnInfo))) == NULL )
{
prmsg(1,"LocalReopenServer: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
return NULL;
}
ciptr->fd = fd;
switch( type )
{
case XTRANS_OPEN_COTS_SERVER:
stat = LOCALtrans2devtab[index].devcotsreopenserver(ciptr,fd,port);
break;
case XTRANS_OPEN_CLTS_SERVER:
stat = LOCALtrans2devtab[index].devcltsreopenserver(ciptr,fd,port);
break;
default:
prmsg(1,"LocalReopenServer: Unknown Open type %d\n",
type );
}
if( stat > 0 ) {
ciptr->priv=(char *)&LOCALtrans2devtab[index];
ciptr->index=index;
ciptr->flags = 1 | (ciptr->flags & TRANS_KEEPFLAGS);
return ciptr;
}
free(ciptr);
return NULL;
}
#endif /* TRANS_REOPEN */
/*
* This is the Local implementation of the X Transport service layer
*/
#ifdef TRANS_CLIENT
static XtransConnInfo
TRANS(LocalOpenCOTSClient)(Xtransport *thistrans _X_UNUSED, const char *protocol,
const char *host, const char *port)
{
prmsg(2,"LocalOpenCOTSClient(%s,%s,%s)\n",protocol,host,port);
return TRANS(LocalOpenClient)(XTRANS_OPEN_COTS_CLIENT, protocol, host, port);
}
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
static XtransConnInfo
TRANS(LocalOpenCOTSServer)(Xtransport *thistrans, const char *protocol,
const char *host, const char *port)
{
char *typetocheck = NULL;
int found = 0;
char typebuf[TYPEBUFSIZE];
prmsg(2,"LocalOpenCOTSServer(%s,%s,%s)\n",protocol,host,port);
/* Check if this local type is in the XLOCAL list */
TRANS(LocalInitTransports)("local");
typetocheck = workingXLOCAL;
while (typetocheck && !found) {
int j;
workingXLOCAL = strchr(workingXLOCAL, ':');
if (workingXLOCAL && *workingXLOCAL)
*workingXLOCAL++ = '\0';
strncpy(typebuf, typetocheck, TYPEBUFSIZE);
for (j = 0; j < TYPEBUFSIZE; j++)
if (isupper(typebuf[j]))
typebuf[j] = tolower(typebuf[j]);
if (!strcmp(thistrans->TransName, typebuf))
found = 1;
typetocheck = workingXLOCAL;
}
TRANS(LocalEndTransports)();
if (!found) {
prmsg(3,"LocalOpenCOTSServer: disabling %s\n",thistrans->TransName);
thistrans->flags |= TRANS_DISABLED;
return NULL;
}
return TRANS(LocalOpenServer)(XTRANS_OPEN_COTS_SERVER, protocol, host, port);
}
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
static XtransConnInfo
TRANS(LocalOpenCLTSClient)(Xtransport *thistrans _X_UNUSED, const char *protocol,
const char *host, const char *port)
{
prmsg(2,"LocalOpenCLTSClient(%s,%s,%s)\n",protocol,host,port);
return TRANS(LocalOpenClient)(XTRANS_OPEN_CLTS_CLIENT, protocol, host, port);
}
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
static XtransConnInfo
TRANS(LocalOpenCLTSServer)(Xtransport *thistrans _X_UNUSED, const char *protocol,
const char *host, const char *port)
{
prmsg(2,"LocalOpenCLTSServer(%s,%s,%s)\n",protocol,host,port);
return TRANS(LocalOpenServer)(XTRANS_OPEN_CLTS_SERVER, protocol, host, port);
}
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
static XtransConnInfo
TRANS(LocalReopenCOTSServer)(Xtransport *thistrans, int fd, const char *port)
{
int index;
prmsg(2,"LocalReopenCOTSServer(%d,%s)\n", fd, port);
for(index=1;index<NUMTRANSPORTS;index++)
{
if( strcmp(thistrans->TransName,
LOCALtrans2devtab[index].transname) == 0 )
break;
}
if (index >= NUMTRANSPORTS)
{
return (NULL);
}
return TRANS(LocalReopenServer)(XTRANS_OPEN_COTS_SERVER,
index, fd, port);
}
static XtransConnInfo
TRANS(LocalReopenCLTSServer)(Xtransport *thistrans, int fd, const char *port)
{
int index;
prmsg(2,"LocalReopenCLTSServer(%d,%s)\n", fd, port);
for(index=1;index<NUMTRANSPORTS;index++)
{
if( strcmp(thistrans->TransName,
LOCALtrans2devtab[index].transname) == 0 )
break;
}
if (index >= NUMTRANSPORTS)
{
return (NULL);
}
return TRANS(LocalReopenServer)(XTRANS_OPEN_CLTS_SERVER,
index, fd, port);
}
#endif /* TRANS_REOPEN */
static int
TRANS(LocalSetOption)(XtransConnInfo ciptr, int option, int arg)
{
prmsg(2,"LocalSetOption(%d,%d,%d)\n",ciptr->fd,option,arg);
return -1;
}
#ifdef TRANS_SERVER
static int
TRANS(LocalCreateListener)(XtransConnInfo ciptr, const char *port,
unsigned int flags _X_UNUSED)
{
prmsg(2,"LocalCreateListener(%p->%d,%s)\n",ciptr,ciptr->fd,port);
return 0;
}
static int
TRANS(LocalResetListener)(XtransConnInfo ciptr)
{
LOCALtrans2dev *transptr;
prmsg(2,"LocalResetListener(%p)\n",ciptr);
transptr=(LOCALtrans2dev *)ciptr->priv;
if (transptr->devreset != NULL) {
return transptr->devreset(ciptr);
}
return TRANS_RESET_NOOP;
}
static XtransConnInfo
TRANS(LocalAccept)(XtransConnInfo ciptr, int *status)
{
XtransConnInfo newciptr;
LOCALtrans2dev *transptr;
prmsg(2,"LocalAccept(%p->%d)\n", ciptr, ciptr->fd);
transptr=(LOCALtrans2dev *)ciptr->priv;
if( (newciptr = calloc(1,sizeof(struct _XtransConnInfo)))==NULL )
{
prmsg(1,"LocalAccept: calloc(1,%lu) failed\n",
sizeof(struct _XtransConnInfo));
*status = TRANS_ACCEPT_BAD_MALLOC;
return NULL;
}
newciptr->fd=transptr->devaccept(ciptr,newciptr,status);
if( newciptr->fd < 0 )
{
free(newciptr);
return NULL;
}
newciptr->priv=(char *)transptr;
newciptr->index = ciptr->index;
*status = 0;
return newciptr;
}
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
static int
TRANS(LocalConnect)(XtransConnInfo ciptr,
const char *host _X_UNUSED, const char *port)
{
prmsg(2,"LocalConnect(%p->%d,%s)\n", ciptr, ciptr->fd, port);
return 0;
}
#endif /* TRANS_CLIENT */
static int
TRANS(LocalBytesReadable)(XtransConnInfo ciptr, BytesReadable_t *pend )
{
prmsg(2,"LocalBytesReadable(%p->%d,%p)\n", ciptr, ciptr->fd, pend);
#if defined(SCO325)
return ioctl(ciptr->fd, I_NREAD, (char *)pend);
#else
return ioctl(ciptr->fd, FIONREAD, (char *)pend);
#endif
}
static int
TRANS(LocalRead)(XtransConnInfo ciptr, char *buf, int size)
{
prmsg(2,"LocalRead(%d,%p,%d)\n", ciptr->fd, buf, size );
return read(ciptr->fd,buf,size);
}
static int
TRANS(LocalWrite)(XtransConnInfo ciptr, char *buf, int size)
{
prmsg(2,"LocalWrite(%d,%p,%d)\n", ciptr->fd, buf, size );
return write(ciptr->fd,buf,size);
}
static int
TRANS(LocalReadv)(XtransConnInfo ciptr, struct iovec *buf, int size)
{
prmsg(2,"LocalReadv(%d,%p,%d)\n", ciptr->fd, buf, size );
return READV(ciptr,buf,size);
}
static int
TRANS(LocalWritev)(XtransConnInfo ciptr, struct iovec *buf, int size)
{
prmsg(2,"LocalWritev(%d,%p,%d)\n", ciptr->fd, buf, size );
return WRITEV(ciptr,buf,size);
}
static int
TRANS(LocalDisconnect)(XtransConnInfo ciptr)
{
prmsg(2,"LocalDisconnect(%p->%d)\n", ciptr, ciptr->fd);
return 0;
}
static int
TRANS(LocalClose)(XtransConnInfo ciptr)
{
struct sockaddr_un *sockname=(struct sockaddr_un *) ciptr->addr;
int ret;
prmsg(2,"LocalClose(%p->%d)\n", ciptr, ciptr->fd );
ret=close(ciptr->fd);
if(ciptr->flags
&& sockname
&& sockname->sun_family == AF_UNIX
&& sockname->sun_path[0] )
{
if (!(ciptr->flags & TRANS_NOUNLINK))
unlink(sockname->sun_path);
}
return ret;
}
static int
TRANS(LocalCloseForCloning)(XtransConnInfo ciptr)
{
int ret;
prmsg(2,"LocalCloseForCloning(%p->%d)\n", ciptr, ciptr->fd );
/* Don't unlink path */
ret=close(ciptr->fd);
return ret;
}
/*
* MakeAllCOTSServerListeners() will go through the entire Xtransports[]
* array defined in Xtrans.c and try to OpenCOTSServer() for each entry.
* We will add duplicate entries to that table so that the OpenCOTSServer()
* function will get called once for each type of local transport.
*
* The TransName is in lowercase, so it will never match during a normal
* call to SelectTransport() in Xtrans.c.
*/
#ifdef TRANS_SERVER
static const char * local_aliases[] = {
# ifdef LOCAL_TRANS_PTS
"pts",
# endif
"named",
# ifdef sun
"pipe", /* compatibility with Solaris Xlib */
# endif
# ifdef LOCAL_TRANS_SCO
"sco",
# endif
NULL };
#endif
Xtransport TRANS(LocalFuncs) = {
/* Local Interface */
"local",
TRANS_ALIAS | TRANS_LOCAL,
#ifdef TRANS_CLIENT
TRANS(LocalOpenCOTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
local_aliases,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalOpenCLTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(LocalOpenCLTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalConnect),
#endif /* TRANS_CLIENT */
TRANS(LocalBytesReadable),
TRANS(LocalRead),
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
#if XTRANS_SEND_FDS
TRANS(LocalSendFdInvalid),
TRANS(LocalRecvFdInvalid),
#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
#ifdef LOCAL_TRANS_PTS
Xtransport TRANS(PTSFuncs) = {
/* Local Interface */
"pts",
TRANS_LOCAL,
#ifdef TRANS_CLIENT
TRANS(LocalOpenCOTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalOpenCLTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(LocalOpenCLTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalConnect),
#endif /* TRANS_CLIENT */
TRANS(LocalBytesReadable),
TRANS(LocalRead),
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
#if XTRANS_SEND_FDS
TRANS(LocalSendFdInvalid),
TRANS(LocalRecvFdInvalid),
#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
#endif /* LOCAL_TRANS_PTS */
#ifdef LOCAL_TRANS_NAMED
Xtransport TRANS(NAMEDFuncs) = {
/* Local Interface */
"named",
TRANS_LOCAL,
#ifdef TRANS_CLIENT
TRANS(LocalOpenCOTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalOpenCLTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(LocalOpenCLTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalConnect),
#endif /* TRANS_CLIENT */
TRANS(LocalBytesReadable),
TRANS(LocalRead),
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
#if XTRANS_SEND_FDS
TRANS(LocalSendFdInvalid),
TRANS(LocalRecvFdInvalid),
#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
#ifdef sun
Xtransport TRANS(PIPEFuncs) = {
/* Local Interface */
"pipe",
TRANS_ALIAS | TRANS_LOCAL,
#ifdef TRANS_CLIENT
TRANS(LocalOpenCOTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalOpenCLTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(LocalOpenCLTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalConnect),
#endif /* TRANS_CLIENT */
TRANS(LocalBytesReadable),
TRANS(LocalRead),
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
#if XTRANS_SEND_FDS
TRANS(LocalSendFdInvalid),
TRANS(LocalRecvFdInvalid),
#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
#endif /* sun */
#endif /* LOCAL_TRANS_NAMED */
#ifdef LOCAL_TRANS_SCO
Xtransport TRANS(SCOFuncs) = {
/* Local Interface */
"sco",
TRANS_LOCAL,
#ifdef TRANS_CLIENT
TRANS(LocalOpenCOTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
NULL,
TRANS(LocalOpenCOTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalOpenCLTSClient),
#endif /* TRANS_CLIENT */
#ifdef TRANS_SERVER
TRANS(LocalOpenCLTSServer),
#endif /* TRANS_SERVER */
#ifdef TRANS_REOPEN
TRANS(LocalReopenCOTSServer),
TRANS(LocalReopenCLTSServer),
#endif
TRANS(LocalSetOption),
#ifdef TRANS_SERVER
TRANS(LocalCreateListener),
TRANS(LocalResetListener),
TRANS(LocalAccept),
#endif /* TRANS_SERVER */
#ifdef TRANS_CLIENT
TRANS(LocalConnect),
#endif /* TRANS_CLIENT */
TRANS(LocalBytesReadable),
TRANS(LocalRead),
TRANS(LocalWrite),
TRANS(LocalReadv),
TRANS(LocalWritev),
#if XTRANS_SEND_FDS
TRANS(LocalSendFdInvalid),
TRANS(LocalRecvFdInvalid),
#endif
TRANS(LocalDisconnect),
TRANS(LocalClose),
TRANS(LocalCloseForCloning),
};
#endif /* LOCAL_TRANS_SCO */
|