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 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958
|
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mflag/LICENSE
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mflag/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2014-2015 The Docker & Go Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags.go
@@ -0,0 +1,69 @@
+package mount
+
+import (
+ "strings"
+)
+
+// Parse fstab type mount options into mount() flags
+// and device specific data
+func parseOptions(options string) (int, string) {
+ var (
+ flag int
+ data []string
+ )
+
+ flags := map[string]struct {
+ clear bool
+ flag int
+ }{
+ "defaults": {false, 0},
+ "ro": {false, RDONLY},
+ "rw": {true, RDONLY},
+ "suid": {true, NOSUID},
+ "nosuid": {false, NOSUID},
+ "dev": {true, NODEV},
+ "nodev": {false, NODEV},
+ "exec": {true, NOEXEC},
+ "noexec": {false, NOEXEC},
+ "sync": {false, SYNCHRONOUS},
+ "async": {true, SYNCHRONOUS},
+ "dirsync": {false, DIRSYNC},
+ "remount": {false, REMOUNT},
+ "mand": {false, MANDLOCK},
+ "nomand": {true, MANDLOCK},
+ "atime": {true, NOATIME},
+ "noatime": {false, NOATIME},
+ "diratime": {true, NODIRATIME},
+ "nodiratime": {false, NODIRATIME},
+ "bind": {false, BIND},
+ "rbind": {false, RBIND},
+ "unbindable": {false, UNBINDABLE},
+ "runbindable": {false, RUNBINDABLE},
+ "private": {false, PRIVATE},
+ "rprivate": {false, RPRIVATE},
+ "shared": {false, SHARED},
+ "rshared": {false, RSHARED},
+ "slave": {false, SLAVE},
+ "rslave": {false, RSLAVE},
+ "relatime": {false, RELATIME},
+ "norelatime": {true, RELATIME},
+ "strictatime": {false, STRICTATIME},
+ "nostrictatime": {true, STRICTATIME},
+ }
+
+ for _, o := range strings.Split(options, ",") {
+ // If the option does not exist in the flags table or the flag
+ // is not supported on the platform,
+ // then it is a data value for a specific fs type
+ if f, exists := flags[o]; exists && f.flag != 0 {
+ if f.clear {
+ flag &= ^f.flag
+ } else {
+ flag |= f.flag
+ }
+ } else {
+ data = append(data, o)
+ }
+ }
+ return flag, strings.Join(data, ",")
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags_freebsd.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags_freebsd.go
@@ -0,0 +1,48 @@
+// +build freebsd,cgo
+
+package mount
+
+/*
+#include <sys/mount.h>
+*/
+import "C"
+
+const (
+ // RDONLY will mount the filesystem as read-only.
+ RDONLY = C.MNT_RDONLY
+
+ // NOSUID will not allow set-user-identifier or set-group-identifier bits to
+ // take effect.
+ NOSUID = C.MNT_NOSUID
+
+ // NOEXEC will not allow execution of any binaries on the mounted file system.
+ NOEXEC = C.MNT_NOEXEC
+
+ // SYNCHRONOUS will allow any I/O to the file system to be done synchronously.
+ SYNCHRONOUS = C.MNT_SYNCHRONOUS
+
+ // NOATIME will not update the file access time when reading from a file.
+ NOATIME = C.MNT_NOATIME
+)
+
+// These flags are unsupported.
+const (
+ BIND = 0
+ DIRSYNC = 0
+ MANDLOCK = 0
+ NODEV = 0
+ NODIRATIME = 0
+ UNBINDABLE = 0
+ RUNBINDABLE = 0
+ PRIVATE = 0
+ RPRIVATE = 0
+ SHARED = 0
+ RSHARED = 0
+ SLAVE = 0
+ RSLAVE = 0
+ RBIND = 0
+ RELATIVE = 0
+ RELATIME = 0
+ REMOUNT = 0
+ STRICTATIME = 0
+)
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags_linux.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags_linux.go
@@ -0,0 +1,85 @@
+package mount
+
+import (
+ "syscall"
+)
+
+const (
+ // RDONLY will mount the file system read-only.
+ RDONLY = syscall.MS_RDONLY
+
+ // NOSUID will not allow set-user-identifier or set-group-identifier bits to
+ // take effect.
+ NOSUID = syscall.MS_NOSUID
+
+ // NODEV will not interpret character or block special devices on the file
+ // system.
+ NODEV = syscall.MS_NODEV
+
+ // NOEXEC will not allow execution of any binaries on the mounted file system.
+ NOEXEC = syscall.MS_NOEXEC
+
+ // SYNCHRONOUS will allow I/O to the file system to be done synchronously.
+ SYNCHRONOUS = syscall.MS_SYNCHRONOUS
+
+ // DIRSYNC will force all directory updates within the file system to be done
+ // synchronously. This affects the following system calls: creat, link,
+ // unlink, symlink, mkdir, rmdir, mknod and rename.
+ DIRSYNC = syscall.MS_DIRSYNC
+
+ // REMOUNT will attempt to remount an already-mounted file system. This is
+ // commonly used to change the mount flags for a file system, especially to
+ // make a readonly file system writeable. It does not change device or mount
+ // point.
+ REMOUNT = syscall.MS_REMOUNT
+
+ // MANDLOCK will force mandatory locks on a filesystem.
+ MANDLOCK = syscall.MS_MANDLOCK
+
+ // NOATIME will not update the file access time when reading from a file.
+ NOATIME = syscall.MS_NOATIME
+
+ // NODIRATIME will not update the directory access time.
+ NODIRATIME = syscall.MS_NODIRATIME
+
+ // BIND remounts a subtree somewhere else.
+ BIND = syscall.MS_BIND
+
+ // RBIND remounts a subtree and all possible submounts somewhere else.
+ RBIND = syscall.MS_BIND | syscall.MS_REC
+
+ // UNBINDABLE creates a mount which cannot be cloned through a bind operation.
+ UNBINDABLE = syscall.MS_UNBINDABLE
+
+ // RUNBINDABLE marks the entire mount tree as UNBINDABLE.
+ RUNBINDABLE = syscall.MS_UNBINDABLE | syscall.MS_REC
+
+ // PRIVATE creates a mount which carries no propagation abilities.
+ PRIVATE = syscall.MS_PRIVATE
+
+ // RPRIVATE marks the entire mount tree as PRIVATE.
+ RPRIVATE = syscall.MS_PRIVATE | syscall.MS_REC
+
+ // SLAVE creates a mount which receives propagation from its master, but not
+ // vice versa.
+ SLAVE = syscall.MS_SLAVE
+
+ // RSLAVE marks the entire mount tree as SLAVE.
+ RSLAVE = syscall.MS_SLAVE | syscall.MS_REC
+
+ // SHARED creates a mount which provides the ability to create mirrors of
+ // that mount such that mounts and unmounts within any of the mirrors
+ // propagate to the other mirrors.
+ SHARED = syscall.MS_SHARED
+
+ // RSHARED marks the entire mount tree as SHARED.
+ RSHARED = syscall.MS_SHARED | syscall.MS_REC
+
+ // RELATIME updates inode access times relative to modify or change time.
+ RELATIME = syscall.MS_RELATIME
+
+ // STRICTATIME allows to explicitly request full atime updates. This makes
+ // it possible for the kernel to default to relatime or noatime but still
+ // allow userspace to override it.
+ STRICTATIME = syscall.MS_STRICTATIME
+)
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags_unsupported.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/flags_unsupported.go
@@ -0,0 +1,30 @@
+// +build !linux,!freebsd freebsd,!cgo
+
+package mount
+
+// These flags are unsupported.
+const (
+ BIND = 0
+ DIRSYNC = 0
+ MANDLOCK = 0
+ NOATIME = 0
+ NODEV = 0
+ NODIRATIME = 0
+ NOEXEC = 0
+ NOSUID = 0
+ UNBINDABLE = 0
+ RUNBINDABLE = 0
+ PRIVATE = 0
+ RPRIVATE = 0
+ SHARED = 0
+ RSHARED = 0
+ SLAVE = 0
+ RSLAVE = 0
+ RBIND = 0
+ RELATIME = 0
+ RELATIVE = 0
+ REMOUNT = 0
+ STRICTATIME = 0
+ SYNCHRONOUS = 0
+ RDONLY = 0
+)
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mount.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mount.go
@@ -0,0 +1,74 @@
+package mount
+
+import (
+ "time"
+)
+
+// GetMounts retrieves a list of mounts for the current running process.
+func GetMounts() ([]*Info, error) {
+ return parseMountTable()
+}
+
+// Mounted looks at /proc/self/mountinfo to determine of the specified
+// mountpoint has been mounted
+func Mounted(mountpoint string) (bool, error) {
+ entries, err := parseMountTable()
+ if err != nil {
+ return false, err
+ }
+
+ // Search the table for the mountpoint
+ for _, e := range entries {
+ if e.Mountpoint == mountpoint {
+ return true, nil
+ }
+ }
+ return false, nil
+}
+
+// Mount will mount filesystem according to the specified configuration, on the
+// condition that the target path is *not* already mounted. Options must be
+// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See
+// flags.go for supported option flags.
+func Mount(device, target, mType, options string) error {
+ flag, _ := parseOptions(options)
+ if flag&REMOUNT != REMOUNT {
+ if mounted, err := Mounted(target); err != nil || mounted {
+ return err
+ }
+ }
+ return ForceMount(device, target, mType, options)
+}
+
+// ForceMount will mount a filesystem according to the specified configuration,
+// *regardless* if the target path is not already mounted. Options must be
+// specified like the mount or fstab unix commands: "opt1=val1,opt2=val2". See
+// flags.go for supported option flags.
+func ForceMount(device, target, mType, options string) error {
+ flag, data := parseOptions(options)
+ if err := mount(device, target, mType, uintptr(flag), data); err != nil {
+ return err
+ }
+ return nil
+}
+
+// Unmount will unmount the target filesystem, so long as it is mounted.
+func Unmount(target string) error {
+ if mounted, err := Mounted(target); err != nil || !mounted {
+ return err
+ }
+ return ForceUnmount(target)
+}
+
+// ForceUnmount will force an unmount of the target filesystem, regardless if
+// it is mounted or not.
+func ForceUnmount(target string) (err error) {
+ // Simple retry logic for unmount
+ for i := 0; i < 10; i++ {
+ if err = unmount(target, 0); err == nil {
+ return nil
+ }
+ time.Sleep(100 * time.Millisecond)
+ }
+ return
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mounter_freebsd.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mounter_freebsd.go
@@ -0,0 +1,59 @@
+package mount
+
+/*
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/_iovec.h>
+#include <sys/mount.h>
+#include <sys/param.h>
+*/
+import "C"
+
+import (
+ "fmt"
+ "strings"
+ "syscall"
+ "unsafe"
+)
+
+func allocateIOVecs(options []string) []C.struct_iovec {
+ out := make([]C.struct_iovec, len(options))
+ for i, option := range options {
+ out[i].iov_base = unsafe.Pointer(C.CString(option))
+ out[i].iov_len = C.size_t(len(option) + 1)
+ }
+ return out
+}
+
+func mount(device, target, mType string, flag uintptr, data string) error {
+ isNullFS := false
+
+ xs := strings.Split(data, ",")
+ for _, x := range xs {
+ if x == "bind" {
+ isNullFS = true
+ }
+ }
+
+ options := []string{"fspath", target}
+ if isNullFS {
+ options = append(options, "fstype", "nullfs", "target", device)
+ } else {
+ options = append(options, "fstype", mType, "from", device)
+ }
+ rawOptions := allocateIOVecs(options)
+ for _, rawOption := range rawOptions {
+ defer C.free(rawOption.iov_base)
+ }
+
+ if errno := C.nmount(&rawOptions[0], C.uint(len(options)), C.int(flag)); errno != 0 {
+ reason := C.GoString(C.strerror(*C.__error()))
+ return fmt.Errorf("Failed to call nmount: %s", reason)
+ }
+ return nil
+}
+
+func unmount(target string, flag int) error {
+ return syscall.Unmount(target, flag)
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mounter_linux.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mounter_linux.go
@@ -0,0 +1,21 @@
+package mount
+
+import (
+ "syscall"
+)
+
+func mount(device, target, mType string, flag uintptr, data string) error {
+ if err := syscall.Mount(device, target, mType, flag, data); err != nil {
+ return err
+ }
+
+ // If we have a bind mount or remount, remount...
+ if flag&syscall.MS_BIND == syscall.MS_BIND && flag&syscall.MS_RDONLY == syscall.MS_RDONLY {
+ return syscall.Mount(device, target, mType, flag|syscall.MS_REMOUNT, data)
+ }
+ return nil
+}
+
+func unmount(target string, flag int) error {
+ return syscall.Unmount(target, flag)
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mounter_unsupported.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mounter_unsupported.go
@@ -0,0 +1,11 @@
+// +build !linux,!freebsd freebsd,!cgo
+
+package mount
+
+func mount(device, target, mType string, flag uintptr, data string) error {
+ panic("Not implemented")
+}
+
+func unmount(target string, flag int) error {
+ panic("Not implemented")
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo.go
@@ -0,0 +1,40 @@
+package mount
+
+// Info reveals information about a particular mounted filesystem. This
+// struct is populated from the content in the /proc/<pid>/mountinfo file.
+type Info struct {
+ // ID is a unique identifier of the mount (may be reused after umount).
+ ID int
+
+ // Parent indicates the ID of the mount parent (or of self for the top of the
+ // mount tree).
+ Parent int
+
+ // Major indicates one half of the device ID which identifies the device class.
+ Major int
+
+ // Minor indicates one half of the device ID which identifies a specific
+ // instance of device.
+ Minor int
+
+ // Root of the mount within the filesystem.
+ Root string
+
+ // Mountpoint indicates the mount point relative to the process's root.
+ Mountpoint string
+
+ // Opts represents mount-specific options.
+ Opts string
+
+ // Optional represents optional fields.
+ Optional string
+
+ // Fstype indicates the type of filesystem, such as EXT3.
+ Fstype string
+
+ // Source indicates filesystem specific information or "none".
+ Source string
+
+ // VfsOpts represents per super block options.
+ VfsOpts string
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo_freebsd.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo_freebsd.go
@@ -0,0 +1,41 @@
+package mount
+
+/*
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+*/
+import "C"
+
+import (
+ "fmt"
+ "reflect"
+ "unsafe"
+)
+
+// Parse /proc/self/mountinfo because comparing Dev and ino does not work from
+// bind mounts.
+func parseMountTable() ([]*Info, error) {
+ var rawEntries *C.struct_statfs
+
+ count := int(C.getmntinfo(&rawEntries, C.MNT_WAIT))
+ if count == 0 {
+ return nil, fmt.Errorf("Failed to call getmntinfo")
+ }
+
+ var entries []C.struct_statfs
+ header := (*reflect.SliceHeader)(unsafe.Pointer(&entries))
+ header.Cap = count
+ header.Len = count
+ header.Data = uintptr(unsafe.Pointer(rawEntries))
+
+ var out []*Info
+ for _, entry := range entries {
+ var mountinfo Info
+ mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0])
+ mountinfo.Source = C.GoString(&entry.f_mntfromname[0])
+ mountinfo.Fstype = C.GoString(&entry.f_fstypename[0])
+ out = append(out, &mountinfo)
+ }
+ return out, nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo_linux.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo_linux.go
@@ -0,0 +1,95 @@
+// +build linux
+
+package mount
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "os"
+ "strings"
+)
+
+const (
+ /* 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
+ (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)
+
+ (1) mount ID: unique identifier of the mount (may be reused after umount)
+ (2) parent ID: ID of parent (or of self for the top of the mount tree)
+ (3) major:minor: value of st_dev for files on filesystem
+ (4) root: root of the mount within the filesystem
+ (5) mount point: mount point relative to the process's root
+ (6) mount options: per mount options
+ (7) optional fields: zero or more fields of the form "tag[:value]"
+ (8) separator: marks the end of the optional fields
+ (9) filesystem type: name of filesystem of the form "type[.subtype]"
+ (10) mount source: filesystem specific information or "none"
+ (11) super options: per super block options*/
+ mountinfoFormat = "%d %d %d:%d %s %s %s %s"
+)
+
+// Parse /proc/self/mountinfo because comparing Dev and ino does not work from
+// bind mounts
+func parseMountTable() ([]*Info, error) {
+ f, err := os.Open("/proc/self/mountinfo")
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+
+ return parseInfoFile(f)
+}
+
+func parseInfoFile(r io.Reader) ([]*Info, error) {
+ var (
+ s = bufio.NewScanner(r)
+ out = []*Info{}
+ )
+
+ for s.Scan() {
+ if err := s.Err(); err != nil {
+ return nil, err
+ }
+
+ var (
+ p = &Info{}
+ text = s.Text()
+ optionalFields string
+ )
+
+ if _, err := fmt.Sscanf(text, mountinfoFormat,
+ &p.ID, &p.Parent, &p.Major, &p.Minor,
+ &p.Root, &p.Mountpoint, &p.Opts, &optionalFields); err != nil {
+ return nil, fmt.Errorf("Scanning '%s' failed: %s", text, err)
+ }
+ // Safe as mountinfo encodes mountpoints with spaces as \040.
+ index := strings.Index(text, " - ")
+ postSeparatorFields := strings.Fields(text[index+3:])
+ if len(postSeparatorFields) < 3 {
+ return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
+ }
+
+ if optionalFields != "-" {
+ p.Optional = optionalFields
+ }
+
+ p.Fstype = postSeparatorFields[0]
+ p.Source = postSeparatorFields[1]
+ p.VfsOpts = strings.Join(postSeparatorFields[2:], " ")
+ out = append(out, p)
+ }
+ return out, nil
+}
+
+// PidMountInfo collects the mounts for a specific process ID. If the process
+// ID is unknown, it is better to use `GetMounts` which will inspect
+// "/proc/self/mountinfo" instead.
+func PidMountInfo(pid int) ([]*Info, error) {
+ f, err := os.Open(fmt.Sprintf("/proc/%d/mountinfo", pid))
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+
+ return parseInfoFile(f)
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo_unsupported.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/mountinfo_unsupported.go
@@ -0,0 +1,12 @@
+// +build !linux,!freebsd freebsd,!cgo
+
+package mount
+
+import (
+ "fmt"
+ "runtime"
+)
+
+func parseMountTable() ([]*Info, error) {
+ return nil, fmt.Errorf("mount.parseMountTable is not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/sharedsubtree_linux.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/mount/sharedsubtree_linux.go
@@ -0,0 +1,70 @@
+// +build linux
+
+package mount
+
+// MakeShared ensures a mounted filesystem has the SHARED mount option enabled.
+// See the supported options in flags.go for further reference.
+func MakeShared(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "shared")
+}
+
+// MakeRShared ensures a mounted filesystem has the RSHARED mount option enabled.
+// See the supported options in flags.go for further reference.
+func MakeRShared(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "rshared")
+}
+
+// MakePrivate ensures a mounted filesystem has the PRIVATE mount option enabled.
+// See the supported options in flags.go for further reference.
+func MakePrivate(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "private")
+}
+
+// MakeRPrivate ensures a mounted filesystem has the RPRIVATE mount option
+// enabled. See the supported options in flags.go for further reference.
+func MakeRPrivate(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "rprivate")
+}
+
+// MakeSlave ensures a mounted filesystem has the SLAVE mount option enabled.
+// See the supported options in flags.go for further reference.
+func MakeSlave(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "slave")
+}
+
+// MakeRSlave ensures a mounted filesystem has the RSLAVE mount option enabled.
+// See the supported options in flags.go for further reference.
+func MakeRSlave(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "rslave")
+}
+
+// MakeUnbindable ensures a mounted filesystem has the UNBINDABLE mount option
+// enabled. See the supported options in flags.go for further reference.
+func MakeUnbindable(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "unbindable")
+}
+
+// MakeRUnbindable ensures a mounted filesystem has the RUNBINDABLE mount
+// option enabled. See the supported options in flags.go for further reference.
+func MakeRUnbindable(mountPoint string) error {
+ return ensureMountedAs(mountPoint, "runbindable")
+}
+
+func ensureMountedAs(mountPoint, options string) error {
+ mounted, err := Mounted(mountPoint)
+ if err != nil {
+ return err
+ }
+
+ if !mounted {
+ if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
+ return err
+ }
+ }
+ mounted, err = Mounted(mountPoint)
+ if err != nil {
+ return err
+ }
+
+ return ForceMount("", mountPoint, "none", options)
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/LICENSE.APACHE
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/LICENSE.APACHE
@@ -0,0 +1,191 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ Copyright 2014-2015 Docker, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/LICENSE.BSD
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/LICENSE.BSD
@@ -0,0 +1,27 @@
+Copyright (c) 2014-2015 The Docker & Go Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/README.md
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/README.md
@@ -0,0 +1,5 @@
+Package symlink implements EvalSymlinksInScope which is an extension of filepath.EvalSymlinks
+from the [Go standard library](https://golang.org/pkg/path/filepath).
+
+The code from filepath.EvalSymlinks has been adapted in fs.go.
+Please read the LICENSE.BSD file that governs fs.go and LICENSE.APACHE for fs_test.go.
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/fs.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/symlink/fs.go
@@ -0,0 +1,131 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE.BSD file.
+
+// This code is a modified version of path/filepath/symlink.go from the Go standard library.
+
+package symlink
+
+import (
+ "bytes"
+ "errors"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+// FollowSymlinkInScope is a wrapper around evalSymlinksInScope that returns an absolute path
+func FollowSymlinkInScope(path, root string) (string, error) {
+ path, err := filepath.Abs(path)
+ if err != nil {
+ return "", err
+ }
+ root, err = filepath.Abs(root)
+ if err != nil {
+ return "", err
+ }
+ return evalSymlinksInScope(path, root)
+}
+
+// evalSymlinksInScope will evaluate symlinks in `path` within a scope `root` and return
+// a result guaranteed to be contained within the scope `root`, at the time of the call.
+// Symlinks in `root` are not evaluated and left as-is.
+// Errors encountered while attempting to evaluate symlinks in path will be returned.
+// Non-existing paths are valid and do not constitute an error.
+// `path` has to contain `root` as a prefix, or else an error will be returned.
+// Trying to break out from `root` does not constitute an error.
+//
+// Example:
+// If /foo/bar -> /outside,
+// FollowSymlinkInScope("/foo/bar", "/foo") == "/foo/outside" instead of "/oustide"
+//
+// IMPORTANT: it is the caller's responsibility to call evalSymlinksInScope *after* relevant symlinks
+// are created and not to create subsequently, additional symlinks that could potentially make a
+// previously-safe path, unsafe. Example: if /foo/bar does not exist, evalSymlinksInScope("/foo/bar", "/foo")
+// would return "/foo/bar". If one makes /foo/bar a symlink to /baz subsequently, then "/foo/bar" should
+// no longer be considered safely contained in "/foo".
+func evalSymlinksInScope(path, root string) (string, error) {
+ root = filepath.Clean(root)
+ if path == root {
+ return path, nil
+ }
+ if !strings.HasPrefix(path, root) {
+ return "", errors.New("evalSymlinksInScope: " + path + " is not in " + root)
+ }
+ const maxIter = 255
+ originalPath := path
+ // given root of "/a" and path of "/a/b/../../c" we want path to be "/b/../../c"
+ path = path[len(root):]
+ if root == string(filepath.Separator) {
+ path = string(filepath.Separator) + path
+ }
+ if !strings.HasPrefix(path, string(filepath.Separator)) {
+ return "", errors.New("evalSymlinksInScope: " + path + " is not in " + root)
+ }
+ path = filepath.Clean(path)
+ // consume path by taking each frontmost path element,
+ // expanding it if it's a symlink, and appending it to b
+ var b bytes.Buffer
+ // b here will always be considered to be the "current absolute path inside
+ // root" when we append paths to it, we also append a slash and use
+ // filepath.Clean after the loop to trim the trailing slash
+ for n := 0; path != ""; n++ {
+ if n > maxIter {
+ return "", errors.New("evalSymlinksInScope: too many links in " + originalPath)
+ }
+
+ // find next path component, p
+ i := strings.IndexRune(path, filepath.Separator)
+ var p string
+ if i == -1 {
+ p, path = path, ""
+ } else {
+ p, path = path[:i], path[i+1:]
+ }
+
+ if p == "" {
+ continue
+ }
+
+ // this takes a b.String() like "b/../" and a p like "c" and turns it
+ // into "/b/../c" which then gets filepath.Cleaned into "/c" and then
+ // root gets prepended and we Clean again (to remove any trailing slash
+ // if the first Clean gave us just "/")
+ cleanP := filepath.Clean(string(filepath.Separator) + b.String() + p)
+ if cleanP == string(filepath.Separator) {
+ // never Lstat "/" itself
+ b.Reset()
+ continue
+ }
+ fullP := filepath.Clean(root + cleanP)
+
+ fi, err := os.Lstat(fullP)
+ if os.IsNotExist(err) {
+ // if p does not exist, accept it
+ b.WriteString(p)
+ b.WriteRune(filepath.Separator)
+ continue
+ }
+ if err != nil {
+ return "", err
+ }
+ if fi.Mode()&os.ModeSymlink == 0 {
+ b.WriteString(p + string(filepath.Separator))
+ continue
+ }
+
+ // it's a symlink, put it at the front of path
+ dest, err := os.Readlink(fullP)
+ if err != nil {
+ return "", err
+ }
+ if filepath.IsAbs(dest) {
+ b.Reset()
+ }
+ path = dest + string(filepath.Separator) + path
+ }
+
+ // see note above on "fullP := ..." for why this is double-cleaned and
+ // what's happening here
+ return filepath.Clean(root + filepath.Clean(string(filepath.Separator)+b.String())), nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/tc_linux_cgo.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/tc_linux_cgo.go
@@ -0,0 +1,48 @@
+// +build linux,cgo
+
+package term
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+// #include <termios.h>
+import "C"
+
+type Termios syscall.Termios
+
+// MakeRaw put the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func MakeRaw(fd uintptr) (*State, error) {
+ var oldState State
+ if err := tcget(fd, &oldState.termios); err != 0 {
+ return nil, err
+ }
+
+ newState := oldState.termios
+
+ C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&newState)))
+ newState.Oflag = newState.Oflag | C.OPOST
+ if err := tcset(fd, &newState); err != 0 {
+ return nil, err
+ }
+ return &oldState, nil
+}
+
+func tcget(fd uintptr, p *Termios) syscall.Errno {
+ ret, err := C.tcgetattr(C.int(fd), (*C.struct_termios)(unsafe.Pointer(p)))
+ if ret != 0 {
+ return err.(syscall.Errno)
+ }
+ return 0
+}
+
+func tcset(fd uintptr, p *Termios) syscall.Errno {
+ ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(p)))
+ if ret != 0 {
+ return err.(syscall.Errno)
+ }
+ return 0
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/tc_other.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/tc_other.go
@@ -0,0 +1,19 @@
+// +build !windows
+// +build !linux !cgo
+
+package term
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+func tcget(fd uintptr, p *Termios) syscall.Errno {
+ _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(p)))
+ return err
+}
+
+func tcset(fd uintptr, p *Termios) syscall.Errno {
+ _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(p)))
+ return err
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/term.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/term.go
@@ -0,0 +1,118 @@
+// +build !windows
+
+package term
+
+import (
+ "errors"
+ "io"
+ "os"
+ "os/signal"
+ "syscall"
+ "unsafe"
+)
+
+var (
+ ErrInvalidState = errors.New("Invalid terminal state")
+)
+
+type State struct {
+ termios Termios
+}
+
+type Winsize struct {
+ Height uint16
+ Width uint16
+ x uint16
+ y uint16
+}
+
+func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
+ return os.Stdin, os.Stdout, os.Stderr
+}
+
+func GetFdInfo(in interface{}) (uintptr, bool) {
+ var inFd uintptr
+ var isTerminalIn bool
+ if file, ok := in.(*os.File); ok {
+ inFd = file.Fd()
+ isTerminalIn = IsTerminal(inFd)
+ }
+ return inFd, isTerminalIn
+}
+
+func GetWinsize(fd uintptr) (*Winsize, error) {
+ ws := &Winsize{}
+ _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(ws)))
+ // Skipp errno = 0
+ if err == 0 {
+ return ws, nil
+ }
+ return ws, err
+}
+
+func SetWinsize(fd uintptr, ws *Winsize) error {
+ _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCSWINSZ), uintptr(unsafe.Pointer(ws)))
+ // Skipp errno = 0
+ if err == 0 {
+ return nil
+ }
+ return err
+}
+
+// IsTerminal returns true if the given file descriptor is a terminal.
+func IsTerminal(fd uintptr) bool {
+ var termios Termios
+ return tcget(fd, &termios) == 0
+}
+
+// Restore restores the terminal connected to the given file descriptor to a
+// previous state.
+func RestoreTerminal(fd uintptr, state *State) error {
+ if state == nil {
+ return ErrInvalidState
+ }
+ if err := tcset(fd, &state.termios); err != 0 {
+ return err
+ }
+ return nil
+}
+
+func SaveState(fd uintptr) (*State, error) {
+ var oldState State
+ if err := tcget(fd, &oldState.termios); err != 0 {
+ return nil, err
+ }
+
+ return &oldState, nil
+}
+
+func DisableEcho(fd uintptr, state *State) error {
+ newState := state.termios
+ newState.Lflag &^= syscall.ECHO
+
+ if err := tcset(fd, &newState); err != 0 {
+ return err
+ }
+ handleInterrupt(fd, state)
+ return nil
+}
+
+func SetRawTerminal(fd uintptr) (*State, error) {
+ oldState, err := MakeRaw(fd)
+ if err != nil {
+ return nil, err
+ }
+ handleInterrupt(fd, oldState)
+ return oldState, err
+}
+
+func handleInterrupt(fd uintptr, state *State) {
+ sigchan := make(chan os.Signal, 1)
+ signal.Notify(sigchan, os.Interrupt)
+
+ go func() {
+ _ = <-sigchan
+ RestoreTerminal(fd, state)
+ os.Exit(0)
+ }()
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/term_windows.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/term_windows.go
@@ -0,0 +1,139 @@
+// +build windows
+
+package term
+
+import (
+ "io"
+ "os"
+
+ "github.com/Sirupsen/logrus"
+ "github.com/docker/docker/pkg/term/winconsole"
+)
+
+// State holds the console mode for the terminal.
+type State struct {
+ mode uint32
+}
+
+// Winsize is used for window size.
+type Winsize struct {
+ Height uint16
+ Width uint16
+ x uint16
+ y uint16
+}
+
+func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
+ switch {
+ case os.Getenv("ConEmuANSI") == "ON":
+ // The ConEmu shell emulates ANSI well by default.
+ return os.Stdin, os.Stdout, os.Stderr
+ case os.Getenv("MSYSTEM") != "":
+ // MSYS (mingw) does not emulate ANSI well.
+ return winconsole.WinConsoleStreams()
+ default:
+ return winconsole.WinConsoleStreams()
+ }
+}
+
+// GetFdInfo returns file descriptor and bool indicating whether the file is a terminal.
+func GetFdInfo(in interface{}) (uintptr, bool) {
+ return winconsole.GetHandleInfo(in)
+}
+
+// GetWinsize retrieves the window size of the terminal connected to the passed file descriptor.
+func GetWinsize(fd uintptr) (*Winsize, error) {
+ info, err := winconsole.GetConsoleScreenBufferInfo(fd)
+ if err != nil {
+ return nil, err
+ }
+
+ // TODO(azlinux): Set the pixel width / height of the console (currently unused by any caller)
+ return &Winsize{
+ Width: uint16(info.Window.Right - info.Window.Left + 1),
+ Height: uint16(info.Window.Bottom - info.Window.Top + 1),
+ x: 0,
+ y: 0}, nil
+}
+
+// SetWinsize sets the size of the given terminal connected to the passed file descriptor.
+func SetWinsize(fd uintptr, ws *Winsize) error {
+ // TODO(azlinux): Implement SetWinsize
+ logrus.Debugf("[windows] SetWinsize: WARNING -- Unsupported method invoked")
+ return nil
+}
+
+// IsTerminal returns true if the given file descriptor is a terminal.
+func IsTerminal(fd uintptr) bool {
+ return winconsole.IsConsole(fd)
+}
+
+// RestoreTerminal restores the terminal connected to the given file descriptor to a
+// previous state.
+func RestoreTerminal(fd uintptr, state *State) error {
+ return winconsole.SetConsoleMode(fd, state.mode)
+}
+
+// SaveState saves the state of the terminal connected to the given file descriptor.
+func SaveState(fd uintptr) (*State, error) {
+ mode, e := winconsole.GetConsoleMode(fd)
+ if e != nil {
+ return nil, e
+ }
+ return &State{mode}, nil
+}
+
+// DisableEcho disables echo for the terminal connected to the given file descriptor.
+// -- See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
+func DisableEcho(fd uintptr, state *State) error {
+ mode := state.mode
+ mode &^= winconsole.ENABLE_ECHO_INPUT
+ mode |= winconsole.ENABLE_PROCESSED_INPUT | winconsole.ENABLE_LINE_INPUT
+ // TODO(azlinux): Core code registers a goroutine to catch os.Interrupt and reset the terminal state.
+ return winconsole.SetConsoleMode(fd, mode)
+}
+
+// SetRawTerminal puts the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func SetRawTerminal(fd uintptr) (*State, error) {
+ state, err := MakeRaw(fd)
+ if err != nil {
+ return nil, err
+ }
+ // TODO(azlinux): Core code registers a goroutine to catch os.Interrupt and reset the terminal state.
+ return state, err
+}
+
+// MakeRaw puts the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func MakeRaw(fd uintptr) (*State, error) {
+ state, err := SaveState(fd)
+ if err != nil {
+ return nil, err
+ }
+
+ // See
+ // -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
+ // -- https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx
+ mode := state.mode
+
+ // Disable these modes
+ mode &^= winconsole.ENABLE_ECHO_INPUT
+ mode &^= winconsole.ENABLE_LINE_INPUT
+ mode &^= winconsole.ENABLE_MOUSE_INPUT
+ mode &^= winconsole.ENABLE_WINDOW_INPUT
+ mode &^= winconsole.ENABLE_PROCESSED_INPUT
+
+ // Enable these modes
+ mode |= winconsole.ENABLE_EXTENDED_FLAGS
+ mode |= winconsole.ENABLE_INSERT_MODE
+ mode |= winconsole.ENABLE_QUICK_EDIT_MODE
+
+ err = winconsole.SetConsoleMode(fd, mode)
+ if err != nil {
+ return nil, err
+ }
+ return state, nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/termios_darwin.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/termios_darwin.go
@@ -0,0 +1,65 @@
+package term
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+const (
+ getTermios = syscall.TIOCGETA
+ setTermios = syscall.TIOCSETA
+
+ IGNBRK = syscall.IGNBRK
+ PARMRK = syscall.PARMRK
+ INLCR = syscall.INLCR
+ IGNCR = syscall.IGNCR
+ ECHONL = syscall.ECHONL
+ CSIZE = syscall.CSIZE
+ ICRNL = syscall.ICRNL
+ ISTRIP = syscall.ISTRIP
+ PARENB = syscall.PARENB
+ ECHO = syscall.ECHO
+ ICANON = syscall.ICANON
+ ISIG = syscall.ISIG
+ IXON = syscall.IXON
+ BRKINT = syscall.BRKINT
+ INPCK = syscall.INPCK
+ OPOST = syscall.OPOST
+ CS8 = syscall.CS8
+ IEXTEN = syscall.IEXTEN
+)
+
+type Termios struct {
+ Iflag uint64
+ Oflag uint64
+ Cflag uint64
+ Lflag uint64
+ Cc [20]byte
+ Ispeed uint64
+ Ospeed uint64
+}
+
+// MakeRaw put the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func MakeRaw(fd uintptr) (*State, error) {
+ var oldState State
+ if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
+ return nil, err
+ }
+
+ newState := oldState.termios
+ newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
+ newState.Oflag &^= OPOST
+ newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
+ newState.Cflag &^= (CSIZE | PARENB)
+ newState.Cflag |= CS8
+ newState.Cc[syscall.VMIN] = 1
+ newState.Cc[syscall.VTIME] = 0
+
+ if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
+ return nil, err
+ }
+
+ return &oldState, nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/termios_freebsd.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/termios_freebsd.go
@@ -0,0 +1,65 @@
+package term
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+const (
+ getTermios = syscall.TIOCGETA
+ setTermios = syscall.TIOCSETA
+
+ IGNBRK = syscall.IGNBRK
+ PARMRK = syscall.PARMRK
+ INLCR = syscall.INLCR
+ IGNCR = syscall.IGNCR
+ ECHONL = syscall.ECHONL
+ CSIZE = syscall.CSIZE
+ ICRNL = syscall.ICRNL
+ ISTRIP = syscall.ISTRIP
+ PARENB = syscall.PARENB
+ ECHO = syscall.ECHO
+ ICANON = syscall.ICANON
+ ISIG = syscall.ISIG
+ IXON = syscall.IXON
+ BRKINT = syscall.BRKINT
+ INPCK = syscall.INPCK
+ OPOST = syscall.OPOST
+ CS8 = syscall.CS8
+ IEXTEN = syscall.IEXTEN
+)
+
+type Termios struct {
+ Iflag uint32
+ Oflag uint32
+ Cflag uint32
+ Lflag uint32
+ Cc [20]byte
+ Ispeed uint32
+ Ospeed uint32
+}
+
+// MakeRaw put the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func MakeRaw(fd uintptr) (*State, error) {
+ var oldState State
+ if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
+ return nil, err
+ }
+
+ newState := oldState.termios
+ newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
+ newState.Oflag &^= OPOST
+ newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
+ newState.Cflag &^= (CSIZE | PARENB)
+ newState.Cflag |= CS8
+ newState.Cc[syscall.VMIN] = 1
+ newState.Cc[syscall.VTIME] = 0
+
+ if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
+ return nil, err
+ }
+
+ return &oldState, nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/termios_linux.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/termios_linux.go
@@ -0,0 +1,46 @@
+// +build !cgo
+
+package term
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+const (
+ getTermios = syscall.TCGETS
+ setTermios = syscall.TCSETS
+)
+
+type Termios struct {
+ Iflag uint32
+ Oflag uint32
+ Cflag uint32
+ Lflag uint32
+ Cc [20]byte
+ Ispeed uint32
+ Ospeed uint32
+}
+
+// MakeRaw put the terminal connected to the given file descriptor into raw
+// mode and returns the previous state of the terminal so that it can be
+// restored.
+func MakeRaw(fd uintptr) (*State, error) {
+ var oldState State
+ if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
+ return nil, err
+ }
+
+ newState := oldState.termios
+
+ newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON)
+ newState.Oflag &^= syscall.OPOST
+ newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN)
+ newState.Cflag &^= (syscall.CSIZE | syscall.PARENB)
+ newState.Cflag |= syscall.CS8
+
+ if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
+ return nil, err
+ }
+ return &oldState, nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/winconsole/console_windows.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/winconsole/console_windows.go
@@ -0,0 +1,1053 @@
+// +build windows
+
+package winconsole
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "os"
+ "strconv"
+ "strings"
+ "sync"
+ "syscall"
+ "unsafe"
+
+ "github.com/Sirupsen/logrus"
+)
+
+const (
+ // Consts for Get/SetConsoleMode function
+ // -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
+ ENABLE_PROCESSED_INPUT = 0x0001
+ ENABLE_LINE_INPUT = 0x0002
+ ENABLE_ECHO_INPUT = 0x0004
+ ENABLE_WINDOW_INPUT = 0x0008
+ ENABLE_MOUSE_INPUT = 0x0010
+ ENABLE_INSERT_MODE = 0x0020
+ ENABLE_QUICK_EDIT_MODE = 0x0040
+ ENABLE_EXTENDED_FLAGS = 0x0080
+
+ // If parameter is a screen buffer handle, additional values
+ ENABLE_PROCESSED_OUTPUT = 0x0001
+ ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002
+
+ //http://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes
+ FOREGROUND_BLUE = 1
+ FOREGROUND_GREEN = 2
+ FOREGROUND_RED = 4
+ FOREGROUND_INTENSITY = 8
+ FOREGROUND_MASK_SET = 0x000F
+ FOREGROUND_MASK_UNSET = 0xFFF0
+
+ BACKGROUND_BLUE = 16
+ BACKGROUND_GREEN = 32
+ BACKGROUND_RED = 64
+ BACKGROUND_INTENSITY = 128
+ BACKGROUND_MASK_SET = 0x00F0
+ BACKGROUND_MASK_UNSET = 0xFF0F
+
+ COMMON_LVB_REVERSE_VIDEO = 0x4000
+ COMMON_LVB_UNDERSCORE = 0x8000
+
+ // http://man7.org/linux/man-pages/man4/console_codes.4.html
+ // ECMA-48 Set Graphics Rendition
+ ANSI_ATTR_RESET = 0
+ ANSI_ATTR_BOLD = 1
+ ANSI_ATTR_DIM = 2
+ ANSI_ATTR_UNDERLINE = 4
+ ANSI_ATTR_BLINK = 5
+ ANSI_ATTR_REVERSE = 7
+ ANSI_ATTR_INVISIBLE = 8
+
+ ANSI_ATTR_UNDERLINE_OFF = 24
+ ANSI_ATTR_BLINK_OFF = 25
+ ANSI_ATTR_REVERSE_OFF = 27
+ ANSI_ATTR_INVISIBLE_OFF = 8
+
+ ANSI_FOREGROUND_BLACK = 30
+ ANSI_FOREGROUND_RED = 31
+ ANSI_FOREGROUND_GREEN = 32
+ ANSI_FOREGROUND_YELLOW = 33
+ ANSI_FOREGROUND_BLUE = 34
+ ANSI_FOREGROUND_MAGENTA = 35
+ ANSI_FOREGROUND_CYAN = 36
+ ANSI_FOREGROUND_WHITE = 37
+ ANSI_FOREGROUND_DEFAULT = 39
+
+ ANSI_BACKGROUND_BLACK = 40
+ ANSI_BACKGROUND_RED = 41
+ ANSI_BACKGROUND_GREEN = 42
+ ANSI_BACKGROUND_YELLOW = 43
+ ANSI_BACKGROUND_BLUE = 44
+ ANSI_BACKGROUND_MAGENTA = 45
+ ANSI_BACKGROUND_CYAN = 46
+ ANSI_BACKGROUND_WHITE = 47
+ ANSI_BACKGROUND_DEFAULT = 49
+
+ ANSI_MAX_CMD_LENGTH = 256
+
+ MAX_INPUT_EVENTS = 128
+ MAX_INPUT_BUFFER = 1024
+ DEFAULT_WIDTH = 80
+ DEFAULT_HEIGHT = 24
+)
+
+// http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
+const (
+ VK_PRIOR = 0x21 // PAGE UP key
+ VK_NEXT = 0x22 // PAGE DOWN key
+ VK_END = 0x23 // END key
+ VK_HOME = 0x24 // HOME key
+ VK_LEFT = 0x25 // LEFT ARROW key
+ VK_UP = 0x26 // UP ARROW key
+ VK_RIGHT = 0x27 // RIGHT ARROW key
+ VK_DOWN = 0x28 // DOWN ARROW key
+ VK_SELECT = 0x29 // SELECT key
+ VK_PRINT = 0x2A // PRINT key
+ VK_EXECUTE = 0x2B // EXECUTE key
+ VK_SNAPSHOT = 0x2C // PRINT SCREEN key
+ VK_INSERT = 0x2D // INS key
+ VK_DELETE = 0x2E // DEL key
+ VK_HELP = 0x2F // HELP key
+ VK_F1 = 0x70 // F1 key
+ VK_F2 = 0x71 // F2 key
+ VK_F3 = 0x72 // F3 key
+ VK_F4 = 0x73 // F4 key
+ VK_F5 = 0x74 // F5 key
+ VK_F6 = 0x75 // F6 key
+ VK_F7 = 0x76 // F7 key
+ VK_F8 = 0x77 // F8 key
+ VK_F9 = 0x78 // F9 key
+ VK_F10 = 0x79 // F10 key
+ VK_F11 = 0x7A // F11 key
+ VK_F12 = 0x7B // F12 key
+)
+
+var kernel32DLL = syscall.NewLazyDLL("kernel32.dll")
+
+var (
+ setConsoleModeProc = kernel32DLL.NewProc("SetConsoleMode")
+ getConsoleScreenBufferInfoProc = kernel32DLL.NewProc("GetConsoleScreenBufferInfo")
+ setConsoleCursorPositionProc = kernel32DLL.NewProc("SetConsoleCursorPosition")
+ setConsoleTextAttributeProc = kernel32DLL.NewProc("SetConsoleTextAttribute")
+ fillConsoleOutputCharacterProc = kernel32DLL.NewProc("FillConsoleOutputCharacterW")
+ writeConsoleOutputProc = kernel32DLL.NewProc("WriteConsoleOutputW")
+ readConsoleInputProc = kernel32DLL.NewProc("ReadConsoleInputW")
+ getNumberOfConsoleInputEventsProc = kernel32DLL.NewProc("GetNumberOfConsoleInputEvents")
+ getConsoleCursorInfoProc = kernel32DLL.NewProc("GetConsoleCursorInfo")
+ setConsoleCursorInfoProc = kernel32DLL.NewProc("SetConsoleCursorInfo")
+ setConsoleWindowInfoProc = kernel32DLL.NewProc("SetConsoleWindowInfo")
+ setConsoleScreenBufferSizeProc = kernel32DLL.NewProc("SetConsoleScreenBufferSize")
+)
+
+// types for calling various windows API
+// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093(v=vs.85).aspx
+type (
+ SHORT int16
+ BOOL int32
+ WORD uint16
+ WCHAR uint16
+ DWORD uint32
+
+ SMALL_RECT struct {
+ Left SHORT
+ Top SHORT
+ Right SHORT
+ Bottom SHORT
+ }
+
+ COORD struct {
+ X SHORT
+ Y SHORT
+ }
+
+ CONSOLE_SCREEN_BUFFER_INFO struct {
+ Size COORD
+ CursorPosition COORD
+ Attributes WORD
+ Window SMALL_RECT
+ MaximumWindowSize COORD
+ }
+
+ CONSOLE_CURSOR_INFO struct {
+ Size DWORD
+ Visible BOOL
+ }
+
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms684166(v=vs.85).aspx
+ KEY_EVENT_RECORD struct {
+ KeyDown BOOL
+ RepeatCount WORD
+ VirtualKeyCode WORD
+ VirtualScanCode WORD
+ UnicodeChar WCHAR
+ ControlKeyState DWORD
+ }
+
+ INPUT_RECORD struct {
+ EventType WORD
+ KeyEvent KEY_EVENT_RECORD
+ }
+
+ CHAR_INFO struct {
+ UnicodeChar WCHAR
+ Attributes WORD
+ }
+)
+
+// TODO(azlinux): Basic type clean-up
+// -- Convert all uses of uintptr to syscall.Handle to be consistent with Windows syscall
+// -- Convert, as appropriate, types to use defined Windows types (e.g., DWORD instead of uint32)
+
+// Implements the TerminalEmulator interface
+type WindowsTerminal struct {
+ outMutex sync.Mutex
+ inMutex sync.Mutex
+ inputBuffer []byte
+ inputSize int
+ inputEvents []INPUT_RECORD
+ screenBufferInfo *CONSOLE_SCREEN_BUFFER_INFO
+ inputEscapeSequence []byte
+}
+
+func getStdHandle(stdhandle int) uintptr {
+ handle, err := syscall.GetStdHandle(stdhandle)
+ if err != nil {
+ panic(fmt.Errorf("could not get standard io handle %d", stdhandle))
+ }
+ return uintptr(handle)
+}
+
+func WinConsoleStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
+ handler := &WindowsTerminal{
+ inputBuffer: make([]byte, MAX_INPUT_BUFFER),
+ inputEscapeSequence: []byte(KEY_ESC_CSI),
+ inputEvents: make([]INPUT_RECORD, MAX_INPUT_EVENTS),
+ }
+
+ if IsConsole(os.Stdin.Fd()) {
+ stdIn = &terminalReader{
+ wrappedReader: os.Stdin,
+ emulator: handler,
+ command: make([]byte, 0, ANSI_MAX_CMD_LENGTH),
+ fd: getStdHandle(syscall.STD_INPUT_HANDLE),
+ }
+ } else {
+ stdIn = os.Stdin
+ }
+
+ if IsConsole(os.Stdout.Fd()) {
+ stdoutHandle := getStdHandle(syscall.STD_OUTPUT_HANDLE)
+
+ // Save current screen buffer info
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(stdoutHandle)
+ if err != nil {
+ // If GetConsoleScreenBufferInfo returns a nil error, it usually means that stdout is not a TTY.
+ // However, this is in the branch where stdout is a TTY, hence the panic.
+ panic("could not get console screen buffer info")
+ }
+ handler.screenBufferInfo = screenBufferInfo
+
+ buffer = make([]CHAR_INFO, screenBufferInfo.MaximumWindowSize.X*screenBufferInfo.MaximumWindowSize.Y)
+
+ stdOut = &terminalWriter{
+ wrappedWriter: os.Stdout,
+ emulator: handler,
+ command: make([]byte, 0, ANSI_MAX_CMD_LENGTH),
+ fd: stdoutHandle,
+ }
+ } else {
+ stdOut = os.Stdout
+ }
+
+ if IsConsole(os.Stderr.Fd()) {
+ stdErr = &terminalWriter{
+ wrappedWriter: os.Stderr,
+ emulator: handler,
+ command: make([]byte, 0, ANSI_MAX_CMD_LENGTH),
+ fd: getStdHandle(syscall.STD_ERROR_HANDLE),
+ }
+ } else {
+ stdErr = os.Stderr
+ }
+
+ return stdIn, stdOut, stdErr
+}
+
+// GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
+func GetHandleInfo(in interface{}) (uintptr, bool) {
+ var inFd uintptr
+ var isTerminalIn bool
+
+ switch t := in.(type) {
+ case *terminalReader:
+ in = t.wrappedReader
+ case *terminalWriter:
+ in = t.wrappedWriter
+ }
+
+ if file, ok := in.(*os.File); ok {
+ inFd = file.Fd()
+ isTerminalIn = IsConsole(inFd)
+ }
+ return inFd, isTerminalIn
+}
+
+func getError(r1, r2 uintptr, lastErr error) error {
+ // If the function fails, the return value is zero.
+ if r1 == 0 {
+ if lastErr != nil {
+ return lastErr
+ }
+ return syscall.EINVAL
+ }
+ return nil
+}
+
+// GetConsoleMode gets the console mode for given file descriptor
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
+func GetConsoleMode(handle uintptr) (uint32, error) {
+ var mode uint32
+ err := syscall.GetConsoleMode(syscall.Handle(handle), &mode)
+ return mode, err
+}
+
+// SetConsoleMode sets the console mode for given file descriptor
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
+func SetConsoleMode(handle uintptr, mode uint32) error {
+ return getError(setConsoleModeProc.Call(handle, uintptr(mode), 0))
+}
+
+// SetCursorVisible sets the cursor visbility
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms686019(v=vs.85).aspx
+func SetCursorVisible(handle uintptr, isVisible BOOL) (bool, error) {
+ var cursorInfo *CONSOLE_CURSOR_INFO = &CONSOLE_CURSOR_INFO{}
+ if err := getError(getConsoleCursorInfoProc.Call(handle, uintptr(unsafe.Pointer(cursorInfo)), 0)); err != nil {
+ return false, err
+ }
+ cursorInfo.Visible = isVisible
+ if err := getError(setConsoleCursorInfoProc.Call(handle, uintptr(unsafe.Pointer(cursorInfo)), 0)); err != nil {
+ return false, err
+ }
+ return true, nil
+}
+
+// SetWindowSize sets the size of the console window.
+func SetWindowSize(handle uintptr, width, height, max SHORT) (bool, error) {
+ window := SMALL_RECT{Left: 0, Top: 0, Right: width - 1, Bottom: height - 1}
+ coord := COORD{X: width - 1, Y: max}
+ if err := getError(setConsoleWindowInfoProc.Call(handle, uintptr(1), uintptr(unsafe.Pointer(&window)))); err != nil {
+ return false, err
+ }
+ if err := getError(setConsoleScreenBufferSizeProc.Call(handle, marshal(coord))); err != nil {
+ return false, err
+ }
+ return true, nil
+}
+
+// GetConsoleScreenBufferInfo retrieves information about the specified console screen buffer.
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx
+func GetConsoleScreenBufferInfo(handle uintptr) (*CONSOLE_SCREEN_BUFFER_INFO, error) {
+ var info CONSOLE_SCREEN_BUFFER_INFO
+ if err := getError(getConsoleScreenBufferInfoProc.Call(handle, uintptr(unsafe.Pointer(&info)), 0)); err != nil {
+ return nil, err
+ }
+ return &info, nil
+}
+
+// setConsoleTextAttribute sets the attributes of characters written to the
+// console screen buffer by the WriteFile or WriteConsole function,
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx
+func setConsoleTextAttribute(handle uintptr, attribute WORD) error {
+ return getError(setConsoleTextAttributeProc.Call(handle, uintptr(attribute), 0))
+}
+
+func writeConsoleOutput(handle uintptr, buffer []CHAR_INFO, bufferSize COORD, bufferCoord COORD, writeRegion *SMALL_RECT) (bool, error) {
+ if err := getError(writeConsoleOutputProc.Call(handle, uintptr(unsafe.Pointer(&buffer[0])), marshal(bufferSize), marshal(bufferCoord), uintptr(unsafe.Pointer(writeRegion)))); err != nil {
+ return false, err
+ }
+ return true, nil
+}
+
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682663(v=vs.85).aspx
+func fillConsoleOutputCharacter(handle uintptr, fillChar byte, length uint32, writeCord COORD) (bool, error) {
+ out := int64(0)
+ if err := getError(fillConsoleOutputCharacterProc.Call(handle, uintptr(fillChar), uintptr(length), marshal(writeCord), uintptr(unsafe.Pointer(&out)))); err != nil {
+ return false, err
+ }
+ return true, nil
+}
+
+// Gets the number of space characters to write for "clearing" the section of terminal
+func getNumberOfChars(fromCoord COORD, toCoord COORD, screenSize COORD) uint32 {
+ // must be valid cursor position
+ if fromCoord.X < 0 || fromCoord.Y < 0 || toCoord.X < 0 || toCoord.Y < 0 {
+ return 0
+ }
+ if fromCoord.X >= screenSize.X || fromCoord.Y >= screenSize.Y || toCoord.X >= screenSize.X || toCoord.Y >= screenSize.Y {
+ return 0
+ }
+ // can't be backwards
+ if fromCoord.Y > toCoord.Y {
+ return 0
+ }
+ // same line
+ if fromCoord.Y == toCoord.Y {
+ return uint32(toCoord.X-fromCoord.X) + 1
+ }
+ // spans more than one line
+ if fromCoord.Y < toCoord.Y {
+ // from start till end of line for first line + from start of line till end
+ retValue := uint32(screenSize.X-fromCoord.X) + uint32(toCoord.X) + 1
+ // don't count first and last line
+ linesBetween := toCoord.Y - fromCoord.Y - 1
+ if linesBetween > 0 {
+ retValue = retValue + uint32(linesBetween*screenSize.X)
+ }
+ return retValue
+ }
+ return 0
+}
+
+var buffer []CHAR_INFO
+
+func clearDisplayRect(handle uintptr, attributes WORD, fromCoord COORD, toCoord COORD) (uint32, error) {
+ var writeRegion SMALL_RECT
+ writeRegion.Left = fromCoord.X
+ writeRegion.Top = fromCoord.Y
+ writeRegion.Right = toCoord.X
+ writeRegion.Bottom = toCoord.Y
+
+ // allocate and initialize buffer
+ width := toCoord.X - fromCoord.X + 1
+ height := toCoord.Y - fromCoord.Y + 1
+ size := uint32(width) * uint32(height)
+ if size > 0 {
+ buffer := make([]CHAR_INFO, size)
+ for i := range buffer {
+ buffer[i] = CHAR_INFO{WCHAR(' '), attributes}
+ }
+
+ // Write to buffer
+ r, err := writeConsoleOutput(handle, buffer, COORD{X: width, Y: height}, COORD{X: 0, Y: 0}, &writeRegion)
+ if !r {
+ if err != nil {
+ return 0, err
+ }
+ return 0, syscall.EINVAL
+ }
+ }
+ return uint32(size), nil
+}
+
+func clearDisplayRange(handle uintptr, attributes WORD, fromCoord COORD, toCoord COORD) (uint32, error) {
+ nw := uint32(0)
+ // start and end on same line
+ if fromCoord.Y == toCoord.Y {
+ return clearDisplayRect(handle, attributes, fromCoord, toCoord)
+ }
+ // TODO(azlinux): if full screen, optimize
+
+ // spans more than one line
+ if fromCoord.Y < toCoord.Y {
+ // from start position till end of line for first line
+ n, err := clearDisplayRect(handle, attributes, fromCoord, COORD{X: toCoord.X, Y: fromCoord.Y})
+ if err != nil {
+ return nw, err
+ }
+ nw += n
+ // lines between
+ linesBetween := toCoord.Y - fromCoord.Y - 1
+ if linesBetween > 0 {
+ n, err = clearDisplayRect(handle, attributes, COORD{X: 0, Y: fromCoord.Y + 1}, COORD{X: toCoord.X, Y: toCoord.Y - 1})
+ if err != nil {
+ return nw, err
+ }
+ nw += n
+ }
+ // lines at end
+ n, err = clearDisplayRect(handle, attributes, COORD{X: 0, Y: toCoord.Y}, toCoord)
+ if err != nil {
+ return nw, err
+ }
+ nw += n
+ }
+ return nw, nil
+}
+
+// setConsoleCursorPosition sets the console cursor position
+// Note The X and Y are zero based
+// If relative is true then the new position is relative to current one
+func setConsoleCursorPosition(handle uintptr, isRelative bool, column int16, line int16) error {
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
+ if err != nil {
+ return err
+ }
+ var position COORD
+ if isRelative {
+ position.X = screenBufferInfo.CursorPosition.X + SHORT(column)
+ position.Y = screenBufferInfo.CursorPosition.Y + SHORT(line)
+ } else {
+ position.X = SHORT(column)
+ position.Y = SHORT(line)
+ }
+ return getError(setConsoleCursorPositionProc.Call(handle, marshal(position), 0))
+}
+
+// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683207(v=vs.85).aspx
+func getNumberOfConsoleInputEvents(handle uintptr) (uint16, error) {
+ var n DWORD
+ if err := getError(getNumberOfConsoleInputEventsProc.Call(handle, uintptr(unsafe.Pointer(&n)))); err != nil {
+ return 0, err
+ }
+ return uint16(n), nil
+}
+
+//http://msdn.microsoft.com/en-us/library/windows/desktop/ms684961(v=vs.85).aspx
+func readConsoleInputKey(handle uintptr, inputBuffer []INPUT_RECORD) (int, error) {
+ var nr DWORD
+ if err := getError(readConsoleInputProc.Call(handle, uintptr(unsafe.Pointer(&inputBuffer[0])), uintptr(len(inputBuffer)), uintptr(unsafe.Pointer(&nr)))); err != nil {
+ return 0, err
+ }
+ return int(nr), nil
+}
+
+func getWindowsTextAttributeForAnsiValue(originalFlag WORD, defaultValue WORD, ansiValue int16) (WORD, error) {
+ flag := WORD(originalFlag)
+ if flag == 0 {
+ flag = defaultValue
+ }
+ switch ansiValue {
+ case ANSI_ATTR_RESET:
+ flag &^= COMMON_LVB_UNDERSCORE
+ flag &^= BACKGROUND_INTENSITY
+ flag = flag | FOREGROUND_INTENSITY
+ case ANSI_ATTR_INVISIBLE:
+ // TODO: how do you reset reverse?
+ case ANSI_ATTR_UNDERLINE:
+ flag = flag | COMMON_LVB_UNDERSCORE
+ case ANSI_ATTR_BLINK:
+ // seems like background intenisty is blink
+ flag = flag | BACKGROUND_INTENSITY
+ case ANSI_ATTR_UNDERLINE_OFF:
+ flag &^= COMMON_LVB_UNDERSCORE
+ case ANSI_ATTR_BLINK_OFF:
+ // seems like background intenisty is blink
+ flag &^= BACKGROUND_INTENSITY
+ case ANSI_ATTR_BOLD:
+ flag = flag | FOREGROUND_INTENSITY
+ case ANSI_ATTR_DIM:
+ flag &^= FOREGROUND_INTENSITY
+ case ANSI_ATTR_REVERSE, ANSI_ATTR_REVERSE_OFF:
+ // swap forground and background bits
+ foreground := flag & FOREGROUND_MASK_SET
+ background := flag & BACKGROUND_MASK_SET
+ flag = (flag & BACKGROUND_MASK_UNSET & FOREGROUND_MASK_UNSET) | (foreground << 4) | (background >> 4)
+
+ // FOREGROUND
+ case ANSI_FOREGROUND_DEFAULT:
+ flag = (flag & FOREGROUND_MASK_UNSET) | (defaultValue & FOREGROUND_MASK_SET)
+ case ANSI_FOREGROUND_BLACK:
+ flag = flag ^ (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
+ case ANSI_FOREGROUND_RED:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED
+ case ANSI_FOREGROUND_GREEN:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_GREEN
+ case ANSI_FOREGROUND_YELLOW:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED | FOREGROUND_GREEN
+ case ANSI_FOREGROUND_BLUE:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_BLUE
+ case ANSI_FOREGROUND_MAGENTA:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED | FOREGROUND_BLUE
+ case ANSI_FOREGROUND_CYAN:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_GREEN | FOREGROUND_BLUE
+ case ANSI_FOREGROUND_WHITE:
+ flag = (flag & FOREGROUND_MASK_UNSET) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
+
+ // Background
+ case ANSI_BACKGROUND_DEFAULT:
+ // Black with no intensity
+ flag = (flag & BACKGROUND_MASK_UNSET) | (defaultValue & BACKGROUND_MASK_SET)
+ case ANSI_BACKGROUND_BLACK:
+ flag = (flag & BACKGROUND_MASK_UNSET)
+ case ANSI_BACKGROUND_RED:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED
+ case ANSI_BACKGROUND_GREEN:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_GREEN
+ case ANSI_BACKGROUND_YELLOW:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED | BACKGROUND_GREEN
+ case ANSI_BACKGROUND_BLUE:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_BLUE
+ case ANSI_BACKGROUND_MAGENTA:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED | BACKGROUND_BLUE
+ case ANSI_BACKGROUND_CYAN:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_GREEN | BACKGROUND_BLUE
+ case ANSI_BACKGROUND_WHITE:
+ flag = (flag & BACKGROUND_MASK_UNSET) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
+ }
+ return flag, nil
+}
+
+// HandleOutputCommand interpretes the Ansi commands and then makes appropriate Win32 calls
+func (term *WindowsTerminal) HandleOutputCommand(handle uintptr, command []byte) (n int, err error) {
+ // always consider all the bytes in command, processed
+ n = len(command)
+
+ parsedCommand := parseAnsiCommand(command)
+ logrus.Debugf("[windows] HandleOutputCommand: %v", parsedCommand)
+
+ // console settings changes need to happen in atomic way
+ term.outMutex.Lock()
+ defer term.outMutex.Unlock()
+
+ switch parsedCommand.Command {
+ case "m":
+ // [Value;...;Valuem
+ // Set Graphics Mode:
+ // Calls the graphics functions specified by the following values.
+ // These specified functions remain active until the next occurrence of this escape sequence.
+ // Graphics mode changes the colors and attributes of text (such as bold and underline) displayed on the screen.
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
+ if err != nil {
+ return n, err
+ }
+ flag := screenBufferInfo.Attributes
+ for _, e := range parsedCommand.Parameters {
+ value, _ := strconv.ParseInt(e, 10, 16) // base 10, 16 bit
+ if value == ANSI_ATTR_RESET {
+ flag = term.screenBufferInfo.Attributes // reset
+ } else {
+ flag, err = getWindowsTextAttributeForAnsiValue(flag, term.screenBufferInfo.Attributes, int16(value))
+ if err != nil {
+ return n, err
+ }
+ }
+ }
+ if err := setConsoleTextAttribute(handle, flag); err != nil {
+ return n, err
+ }
+ case "H", "f":
+ // [line;columnH
+ // [line;columnf
+ // Moves the cursor to the specified position (coordinates).
+ // If you do not specify a position, the cursor moves to the home position at the upper-left corner of the screen (line 0, column 0).
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
+ if err != nil {
+ return n, err
+ }
+ line, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
+ if err != nil {
+ return n, err
+ }
+ if line > int16(screenBufferInfo.Window.Bottom) {
+ line = int16(screenBufferInfo.Window.Bottom) + 1
+ }
+ column, err := parseInt16OrDefault(parsedCommand.getParam(1), 1)
+ if err != nil {
+ return n, err
+ }
+ if column > int16(screenBufferInfo.Window.Right) {
+ column = int16(screenBufferInfo.Window.Right) + 1
+ }
+ // The numbers are not 0 based, but 1 based
+ logrus.Debugf("[windows] HandleOutputCommmand: Moving cursor to (%v,%v)", column-1, line-1)
+ if err := setConsoleCursorPosition(handle, false, column-1, line-1); err != nil {
+ return n, err
+ }
+
+ case "A":
+ // [valueA
+ // Moves the cursor up by the specified number of lines without changing columns.
+ // If the cursor is already on the top line, ignores this sequence.
+ value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
+ if err != nil {
+ return len(command), err
+ }
+ if err := setConsoleCursorPosition(handle, true, 0, -value); err != nil {
+ return n, err
+ }
+ case "B":
+ // [valueB
+ // Moves the cursor down by the specified number of lines without changing columns.
+ // If the cursor is already on the bottom line, ignores this sequence.
+ value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
+ if err != nil {
+ return n, err
+ }
+ if err := setConsoleCursorPosition(handle, true, 0, value); err != nil {
+ return n, err
+ }
+ case "C":
+ // [valueC
+ // Moves the cursor forward by the specified number of columns without changing lines.
+ // If the cursor is already in the rightmost column, ignores this sequence.
+ value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
+ if err != nil {
+ return n, err
+ }
+ if err := setConsoleCursorPosition(handle, true, value, 0); err != nil {
+ return n, err
+ }
+ case "D":
+ // [valueD
+ // Moves the cursor back by the specified number of columns without changing lines.
+ // If the cursor is already in the leftmost column, ignores this sequence.
+ value, err := parseInt16OrDefault(parsedCommand.getParam(0), 1)
+ if err != nil {
+ return n, err
+ }
+ if err := setConsoleCursorPosition(handle, true, -value, 0); err != nil {
+ return n, err
+ }
+ case "J":
+ // [J Erases from the cursor to the end of the screen, including the cursor position.
+ // [1J Erases from the beginning of the screen to the cursor, including the cursor position.
+ // [2J Erases the complete display. The cursor does not move.
+ // Clears the screen and moves the cursor to the home position (line 0, column 0).
+ value, err := parseInt16OrDefault(parsedCommand.getParam(0), 0)
+ if err != nil {
+ return n, err
+ }
+ var start COORD
+ var cursor COORD
+ var end COORD
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(handle)
+ if err != nil {
+ return n, err
+ }
+ switch value {
+ case 0:
+ start = screenBufferInfo.CursorPosition
+ // end of the buffer
+ end.X = screenBufferInfo.Size.X - 1
+ end.Y = screenBufferInfo.Size.Y - 1
+ // cursor
+ cursor = screenBufferInfo.CursorPosition
+ case 1:
+
+ // start of the screen
+ start.X = 0
+ start.Y = 0
+ // end of the screen
+ end = screenBufferInfo.CursorPosition
+ // cursor
+ cursor = screenBufferInfo.CursorPosition
+ case 2:
+ // start of the screen
+ start.X = 0
+ start.Y = 0
+ // end of the buffer
+ end.X = screenBufferInfo.Size.X - 1
+ end.Y = screenBufferInfo.Size.Y - 1
+ // cursor
+ cursor.X = 0
+ cursor.Y = 0
+ }
+ if _, err := clearDisplayRange(uintptr(handle), term.screenBufferInfo.Attributes, start, end); err != nil {
+ return n, err
+ }
+ // remember the the cursor position is 1 based
+ if err := setConsoleCursorPosition(handle, false, int16(cursor.X), int16(cursor.Y)); err != nil {
+ return n, err
+ }
+
+ case "K":
+ // [K
+ // Clears all characters from the cursor position to the end of the line (including the character at the cursor position).
+ // [K Erases from the cursor to the end of the line, including the cursor position.
+ // [1K Erases from the beginning of the line to the cursor, including the cursor position.
+ // [2K Erases the complete line.
+ value, err := parseInt16OrDefault(parsedCommand.getParam(0), 0)
+ var start COORD
+ var cursor COORD
+ var end COORD
+ screenBufferInfo, err := GetConsoleScreenBufferInfo(uintptr(handle))
+ if err != nil {
+ return n, err
+ }
+ switch value {
+ case 0:
+ // start is where cursor is
+ start = screenBufferInfo.CursorPosition
+ // end of line
+ end.X = screenBufferInfo.Size.X - 1
+ end.Y = screenBufferInfo.CursorPosition.Y
+ // cursor remains the same
+ cursor = screenBufferInfo.CursorPosition
+
+ case 1:
+ // beginning of line
+ start.X = 0
+ start.Y = screenBufferInfo.CursorPosition.Y
+ // until cursor
+ end = screenBufferInfo.CursorPosition
+ // cursor remains the same
+ cursor = screenBufferInfo.CursorPosition
+ case 2:
+ // start of the line
+ start.X = 0
+ start.Y = screenBufferInfo.CursorPosition.Y - 1
+ // end of the line
+ end.X = screenBufferInfo.Size.X - 1
+ end.Y = screenBufferInfo.CursorPosition.Y - 1
+ // cursor
+ cursor.X = 0
+ cursor.Y = screenBufferInfo.CursorPosition.Y - 1
+ }
+ if _, err := clearDisplayRange(uintptr(handle), term.screenBufferInfo.Attributes, start, end); err != nil {
+ return n, err
+ }
+ // remember the the cursor position is 1 based
+ if err := setConsoleCursorPosition(uintptr(handle), false, int16(cursor.X), int16(cursor.Y)); err != nil {
+ return n, err
+ }
+
+ case "l":
+ for _, value := range parsedCommand.Parameters {
+ switch value {
+ case "?25", "25":
+ SetCursorVisible(uintptr(handle), BOOL(0))
+ case "?1049", "1049":
+ // TODO (azlinux): Restore terminal
+ case "?1", "1":
+ // If the DECCKM function is reset, then the arrow keys send ANSI cursor sequences to the host.
+ term.inputEscapeSequence = []byte(KEY_ESC_CSI)
+ }
+ }
+ case "h":
+ for _, value := range parsedCommand.Parameters {
+ switch value {
+ case "?25", "25":
+ SetCursorVisible(uintptr(handle), BOOL(1))
+ case "?1049", "1049":
+ // TODO (azlinux): Save terminal
+ case "?1", "1":
+ // If the DECCKM function is set, then the arrow keys send application sequences to the host.
+ // DECCKM (default off): When set, the cursor keys send an ESC O prefix, rather than ESC [.
+ term.inputEscapeSequence = []byte(KEY_ESC_O)
+ }
+ }
+
+ case "]":
+ /*
+ TODO (azlinux):
+ Linux Console Private CSI Sequences
+
+ The following sequences are neither ECMA-48 nor native VT102. They are
+ native to the Linux console driver. Colors are in SGR parameters: 0 =
+ black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan,
+ 7 = white.
+
+ ESC [ 1 ; n ] Set color n as the underline color
+ ESC [ 2 ; n ] Set color n as the dim color
+ ESC [ 8 ] Make the current color pair the default attributes.
+ ESC [ 9 ; n ] Set screen blank timeout to n minutes.
+ ESC [ 10 ; n ] Set bell frequency in Hz.
+ ESC [ 11 ; n ] Set bell duration in msec.
+ ESC [ 12 ; n ] Bring specified console to the front.
+ ESC [ 13 ] Unblank the screen.
+ ESC [ 14 ; n ] Set the VESA powerdown interval in minutes.
+
+ */
+ }
+ return n, nil
+}
+
+// WriteChars writes the bytes to given writer.
+func (term *WindowsTerminal) WriteChars(fd uintptr, w io.Writer, p []byte) (n int, err error) {
+ if len(p) == 0 {
+ return 0, nil
+ }
+ return w.Write(p)
+}
+
+const (
+ CAPSLOCK_ON = 0x0080 //The CAPS LOCK light is on.
+ ENHANCED_KEY = 0x0100 //The key is enhanced.
+ LEFT_ALT_PRESSED = 0x0002 //The left ALT key is pressed.
+ LEFT_CTRL_PRESSED = 0x0008 //The left CTRL key is pressed.
+ NUMLOCK_ON = 0x0020 //The NUM LOCK light is on.
+ RIGHT_ALT_PRESSED = 0x0001 //The right ALT key is pressed.
+ RIGHT_CTRL_PRESSED = 0x0004 //The right CTRL key is pressed.
+ SCROLLLOCK_ON = 0x0040 //The SCROLL LOCK light is on.
+ SHIFT_PRESSED = 0x0010 // The SHIFT key is pressed.
+)
+
+const (
+ KEY_CONTROL_PARAM_2 = ";2"
+ KEY_CONTROL_PARAM_3 = ";3"
+ KEY_CONTROL_PARAM_4 = ";4"
+ KEY_CONTROL_PARAM_5 = ";5"
+ KEY_CONTROL_PARAM_6 = ";6"
+ KEY_CONTROL_PARAM_7 = ";7"
+ KEY_CONTROL_PARAM_8 = ";8"
+ KEY_ESC_CSI = "\x1B["
+ KEY_ESC_N = "\x1BN"
+ KEY_ESC_O = "\x1BO"
+)
+
+var keyMapPrefix = map[WORD]string{
+ VK_UP: "\x1B[%sA",
+ VK_DOWN: "\x1B[%sB",
+ VK_RIGHT: "\x1B[%sC",
+ VK_LEFT: "\x1B[%sD",
+ VK_HOME: "\x1B[1%s~", // showkey shows ^[[1
+ VK_END: "\x1B[4%s~", // showkey shows ^[[4
+ VK_INSERT: "\x1B[2%s~",
+ VK_DELETE: "\x1B[3%s~",
+ VK_PRIOR: "\x1B[5%s~",
+ VK_NEXT: "\x1B[6%s~",
+ VK_F1: "",
+ VK_F2: "",
+ VK_F3: "\x1B[13%s~",
+ VK_F4: "\x1B[14%s~",
+ VK_F5: "\x1B[15%s~",
+ VK_F6: "\x1B[17%s~",
+ VK_F7: "\x1B[18%s~",
+ VK_F8: "\x1B[19%s~",
+ VK_F9: "\x1B[20%s~",
+ VK_F10: "\x1B[21%s~",
+ VK_F11: "\x1B[23%s~",
+ VK_F12: "\x1B[24%s~",
+}
+
+var arrowKeyMapPrefix = map[WORD]string{
+ VK_UP: "%s%sA",
+ VK_DOWN: "%s%sB",
+ VK_RIGHT: "%s%sC",
+ VK_LEFT: "%s%sD",
+}
+
+func getControlStateParameter(shift, alt, control, meta bool) string {
+ if shift && alt && control {
+ return KEY_CONTROL_PARAM_8
+ }
+ if alt && control {
+ return KEY_CONTROL_PARAM_7
+ }
+ if shift && control {
+ return KEY_CONTROL_PARAM_6
+ }
+ if control {
+ return KEY_CONTROL_PARAM_5
+ }
+ if shift && alt {
+ return KEY_CONTROL_PARAM_4
+ }
+ if alt {
+ return KEY_CONTROL_PARAM_3
+ }
+ if shift {
+ return KEY_CONTROL_PARAM_2
+ }
+ return ""
+}
+
+func getControlKeys(controlState DWORD) (shift, alt, control bool) {
+ shift = 0 != (controlState & SHIFT_PRESSED)
+ alt = 0 != (controlState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
+ control = 0 != (controlState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
+ return shift, alt, control
+}
+
+func charSequenceForKeys(key WORD, controlState DWORD, escapeSequence []byte) string {
+ i, ok := arrowKeyMapPrefix[key]
+ if ok {
+ shift, alt, control := getControlKeys(controlState)
+ modifier := getControlStateParameter(shift, alt, control, false)
+ return fmt.Sprintf(i, escapeSequence, modifier)
+ }
+
+ i, ok = keyMapPrefix[key]
+ if ok {
+ shift, alt, control := getControlKeys(controlState)
+ modifier := getControlStateParameter(shift, alt, control, false)
+ return fmt.Sprintf(i, modifier)
+ }
+
+ return ""
+}
+
+// mapKeystokeToTerminalString maps the given input event record to string
+func mapKeystokeToTerminalString(keyEvent *KEY_EVENT_RECORD, escapeSequence []byte) string {
+ _, alt, control := getControlKeys(keyEvent.ControlKeyState)
+ if keyEvent.UnicodeChar == 0 {
+ return charSequenceForKeys(keyEvent.VirtualKeyCode, keyEvent.ControlKeyState, escapeSequence)
+ }
+ if control {
+ // TODO(azlinux): Implement following control sequences
+ // <Ctrl>-D Signals the end of input from the keyboard; also exits current shell.
+ // <Ctrl>-H Deletes the first character to the left of the cursor. Also called the ERASE key.
+ // <Ctrl>-Q Restarts printing after it has been stopped with <Ctrl>-s.
+ // <Ctrl>-S Suspends printing on the screen (does not stop the program).
+ // <Ctrl>-U Deletes all characters on the current line. Also called the KILL key.
+ // <Ctrl>-E Quits current command and creates a core
+
+ }
+ // <Alt>+Key generates ESC N Key
+ if !control && alt {
+ return KEY_ESC_N + strings.ToLower(string(keyEvent.UnicodeChar))
+ }
+ return string(keyEvent.UnicodeChar)
+}
+
+// getAvailableInputEvents polls the console for availble events
+// The function does not return until at least one input record has been read.
+func getAvailableInputEvents(handle uintptr, inputEvents []INPUT_RECORD) (n int, err error) {
+ // TODO(azlinux): Why is there a for loop? Seems to me, that `n` cannot be negative. - tibor
+ for {
+ // Read number of console events available
+ n, err = readConsoleInputKey(handle, inputEvents)
+ if err != nil || n >= 0 {
+ return n, err
+ }
+ }
+}
+
+// getTranslatedKeyCodes converts the input events into the string of characters
+// The ansi escape sequence are used to map key strokes to the strings
+func getTranslatedKeyCodes(inputEvents []INPUT_RECORD, escapeSequence []byte) string {
+ var buf bytes.Buffer
+ for i := 0; i < len(inputEvents); i++ {
+ input := inputEvents[i]
+ if input.EventType == KEY_EVENT && input.KeyEvent.KeyDown != 0 {
+ keyString := mapKeystokeToTerminalString(&input.KeyEvent, escapeSequence)
+ buf.WriteString(keyString)
+ }
+ }
+ return buf.String()
+}
+
+// ReadChars reads the characters from the given reader
+func (term *WindowsTerminal) ReadChars(fd uintptr, r io.Reader, p []byte) (n int, err error) {
+ for term.inputSize == 0 {
+ nr, err := getAvailableInputEvents(fd, term.inputEvents)
+ if nr == 0 && nil != err {
+ return n, err
+ }
+ if nr > 0 {
+ keyCodes := getTranslatedKeyCodes(term.inputEvents[:nr], term.inputEscapeSequence)
+ term.inputSize = copy(term.inputBuffer, keyCodes)
+ }
+ }
+ n = copy(p, term.inputBuffer[:term.inputSize])
+ term.inputSize -= n
+ return n, nil
+}
+
+// HandleInputSequence interprets the input sequence command
+func (term *WindowsTerminal) HandleInputSequence(fd uintptr, command []byte) (n int, err error) {
+ return 0, nil
+}
+
+func marshal(c COORD) uintptr {
+ return uintptr(*((*DWORD)(unsafe.Pointer(&c))))
+}
+
+// IsConsole returns true if the given file descriptor is a terminal.
+// -- The code assumes that GetConsoleMode will return an error for file descriptors that are not a console.
+func IsConsole(fd uintptr) bool {
+ _, e := GetConsoleMode(fd)
+ return e == nil
+}
Index: runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/winconsole/term_emulator.go
===================================================================
--- /dev/null
+++ runc/Godeps/_workspace/src/github.com/docker/docker/pkg/term/winconsole/term_emulator.go
@@ -0,0 +1,234 @@
+package winconsole
+
+import (
+ "fmt"
+ "io"
+ "strconv"
+ "strings"
+)
+
+// http://manpages.ubuntu.com/manpages/intrepid/man4/console_codes.4.html
+const (
+ ANSI_ESCAPE_PRIMARY = 0x1B
+ ANSI_ESCAPE_SECONDARY = 0x5B
+ ANSI_COMMAND_FIRST = 0x40
+ ANSI_COMMAND_LAST = 0x7E
+ ANSI_PARAMETER_SEP = ";"
+ ANSI_CMD_G0 = '('
+ ANSI_CMD_G1 = ')'
+ ANSI_CMD_G2 = '*'
+ ANSI_CMD_G3 = '+'
+ ANSI_CMD_DECPNM = '>'
+ ANSI_CMD_DECPAM = '='
+ ANSI_CMD_OSC = ']'
+ ANSI_CMD_STR_TERM = '\\'
+ ANSI_BEL = 0x07
+ KEY_EVENT = 1
+)
+
+// Interface that implements terminal handling
+type terminalEmulator interface {
+ HandleOutputCommand(fd uintptr, command []byte) (n int, err error)
+ HandleInputSequence(fd uintptr, command []byte) (n int, err error)
+ WriteChars(fd uintptr, w io.Writer, p []byte) (n int, err error)
+ ReadChars(fd uintptr, w io.Reader, p []byte) (n int, err error)
+}
+
+type terminalWriter struct {
+ wrappedWriter io.Writer
+ emulator terminalEmulator
+ command []byte
+ inSequence bool
+ fd uintptr
+}
+
+type terminalReader struct {
+ wrappedReader io.ReadCloser
+ emulator terminalEmulator
+ command []byte
+ inSequence bool
+ fd uintptr
+}
+
+// http://manpages.ubuntu.com/manpages/intrepid/man4/console_codes.4.html
+func isAnsiCommandChar(b byte) bool {
+ switch {
+ case ANSI_COMMAND_FIRST <= b && b <= ANSI_COMMAND_LAST && b != ANSI_ESCAPE_SECONDARY:
+ return true
+ case b == ANSI_CMD_G1 || b == ANSI_CMD_OSC || b == ANSI_CMD_DECPAM || b == ANSI_CMD_DECPNM:
+ // non-CSI escape sequence terminator
+ return true
+ case b == ANSI_CMD_STR_TERM || b == ANSI_BEL:
+ // String escape sequence terminator
+ return true
+ }
+ return false
+}
+
+func isCharacterSelectionCmdChar(b byte) bool {
+ return (b == ANSI_CMD_G0 || b == ANSI_CMD_G1 || b == ANSI_CMD_G2 || b == ANSI_CMD_G3)
+}
+
+func isXtermOscSequence(command []byte, current byte) bool {
+ return (len(command) >= 2 && command[0] == ANSI_ESCAPE_PRIMARY && command[1] == ANSI_CMD_OSC && current != ANSI_BEL)
+}
+
+// Write writes len(p) bytes from p to the underlying data stream.
+// http://golang.org/pkg/io/#Writer
+func (tw *terminalWriter) Write(p []byte) (n int, err error) {
+ if len(p) == 0 {
+ return 0, nil
+ }
+ if tw.emulator == nil {
+ return tw.wrappedWriter.Write(p)
+ }
+ // Emulate terminal by extracting commands and executing them
+ totalWritten := 0
+ start := 0 // indicates start of the next chunk
+ end := len(p)
+ for current := 0; current < end; current++ {
+ if tw.inSequence {
+ // inside escape sequence
+ tw.command = append(tw.command, p[current])
+ if isAnsiCommandChar(p[current]) {
+ if !isXtermOscSequence(tw.command, p[current]) {
+ // found the last command character.
+ // Now we have a complete command.
+ nchar, err := tw.emulator.HandleOutputCommand(tw.fd, tw.command)
+ totalWritten += nchar
+ if err != nil {
+ return totalWritten, err
+ }
+
+ // clear the command
+ // don't include current character again
+ tw.command = tw.command[:0]
+ start = current + 1
+ tw.inSequence = false
+ }
+ }
+ } else {
+ if p[current] == ANSI_ESCAPE_PRIMARY {
+ // entering escape sequnce
+ tw.inSequence = true
+ // indicates end of "normal sequence", write whatever you have so far
+ if len(p[start:current]) > 0 {
+ nw, err := tw.emulator.WriteChars(tw.fd, tw.wrappedWriter, p[start:current])
+ totalWritten += nw
+ if err != nil {
+ return totalWritten, err
+ }
+ }
+ // include the current character as part of the next sequence
+ tw.command = append(tw.command, p[current])
+ }
+ }
+ }
+ // note that so far, start of the escape sequence triggers writing out of bytes to console.
+ // For the part _after_ the end of last escape sequence, it is not written out yet. So write it out
+ if !tw.inSequence {
+ // assumption is that we can't be inside sequence and therefore command should be empty
+ if len(p[start:]) > 0 {
+ nw, err := tw.emulator.WriteChars(tw.fd, tw.wrappedWriter, p[start:])
+ totalWritten += nw
+ if err != nil {
+ return totalWritten, err
+ }
+ }
+ }
+ return totalWritten, nil
+
+}
+
+// Read reads up to len(p) bytes into p.
+// http://golang.org/pkg/io/#Reader
+func (tr *terminalReader) Read(p []byte) (n int, err error) {
+ //Implementations of Read are discouraged from returning a zero byte count
+ // with a nil error, except when len(p) == 0.
+ if len(p) == 0 {
+ return 0, nil
+ }
+ if nil == tr.emulator {
+ return tr.readFromWrappedReader(p)
+ }
+ return tr.emulator.ReadChars(tr.fd, tr.wrappedReader, p)
+}
+
+// Close the underlying stream
+func (tr *terminalReader) Close() (err error) {
+ return tr.wrappedReader.Close()
+}
+
+func (tr *terminalReader) readFromWrappedReader(p []byte) (n int, err error) {
+ return tr.wrappedReader.Read(p)
+}
+
+type ansiCommand struct {
+ CommandBytes []byte
+ Command string
+ Parameters []string
+ IsSpecial bool
+}
+
+func parseAnsiCommand(command []byte) *ansiCommand {
+ if isCharacterSelectionCmdChar(command[1]) {
+ // Is Character Set Selection commands
+ return &ansiCommand{
+ CommandBytes: command,
+ Command: string(command),
+ IsSpecial: true,
+ }
+ }
+ // last char is command character
+ lastCharIndex := len(command) - 1
+
+ retValue := &ansiCommand{
+ CommandBytes: command,
+ Command: string(command[lastCharIndex]),
+ IsSpecial: false,
+ }
+ // more than a single escape
+ if lastCharIndex != 0 {
+ start := 1
+ // skip if double char escape sequence
+ if command[0] == ANSI_ESCAPE_PRIMARY && command[1] == ANSI_ESCAPE_SECONDARY {
+ start++
+ }
+ // convert this to GetNextParam method
+ retValue.Parameters = strings.Split(string(command[start:lastCharIndex]), ANSI_PARAMETER_SEP)
+ }
+ return retValue
+}
+
+func (c *ansiCommand) getParam(index int) string {
+ if len(c.Parameters) > index {
+ return c.Parameters[index]
+ }
+ return ""
+}
+
+func (ac *ansiCommand) String() string {
+ return fmt.Sprintf("0x%v \"%v\" (\"%v\")",
+ bytesToHex(ac.CommandBytes),
+ ac.Command,
+ strings.Join(ac.Parameters, "\",\""))
+}
+
+func bytesToHex(b []byte) string {
+ hex := make([]string, len(b))
+ for i, ch := range b {
+ hex[i] = fmt.Sprintf("%X", ch)
+ }
+ return strings.Join(hex, "")
+}
+
+func parseInt16OrDefault(s string, defaultValue int16) (n int16, err error) {
+ if s == "" {
+ return defaultValue, nil
+ }
+ parsedValue, err := strconv.ParseInt(s, 10, 16)
+ if err != nil {
+ return defaultValue, err
+ }
+ return int16(parsedValue), nil
+}
|