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 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> Linux Gazette Table of Contents LG #81</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000" >
<center>
<!-- A HREF="http://www.linuxgazette.com/">
<H1><IMG SRC="../gx/newlogo.jpg" ALT="LINUX GAZETTE" border="0"></H1></A> -->
<A HREF="http://www.linuxgazette.com/">
<H1><IMG ALT="LINUX GAZETTE" SRC="../gx/lglogo.png"
WIDTH="600" HEIGHT="124" border="0"></H1></A>
<H2>August 2002, Issue 81
Published by <I>Linux Journal</I></H2>
<A HREF="../index.html">Front Page</A> |
<A HREF="../index.html">Back Issues</A> |
<A HREF="../lg_faq.html">FAQ</A> |
<A HREF="../mirrors.html">Mirrors</A> <!-- | --><BR>
<A HREF="../tag-kb.html">The Answer Gang knowledge base</A> (your Linux questions here!) <!-- | --><BR>
<A HREF="http://www.linuxgazette.com/search.html">Search (www.linuxgazette.com)</A>
<!-- *** BEGIN mirror site search link *** -->
<!-- <A HREF="http://www.linuxgazette.com/search.html">(SITE.COM
mirror)</A> -->
<!-- *** END mirror site search link *** -->
</CENTER>
<HR NOSHADE>
<!--=================================================================-->
<!-- H1><font color="#BB0000">Table of Contents:</font></H1 -->
<!-- *** BEGIN toc *** -->
<UL>
<LI> <a HREF="lg_mail.html">The MailBag</A>
<LI> <a HREF="lg_tips.html">More 2-Cent Tips</A>
<LI> <a HREF="lg_answer.html">The Answer Gang</A>
<LI> <a HREF="lg_bytes.html">News Bytes</A>
<LI> <a HREF="adam.html">The Weekend Mechanic</A> , <EM>by Thomas Adam</EM>
<LI> <a HREF="adam2.html">Introduction to Programming Ada</A> , <EM>by Thomas Adam</EM>
<LI> <a HREF="arndt.html">Office Linux: Ideas for a Desktop Distribution</A> , <EM>by Matthias Arndt</EM>
<LI> <a HREF="durodola.html">Playing DVDs on Linux</A> , <EM>by Tunji Durodola</EM>
<LI> <a HREF="kurup.html">Is Your Memory Not What It Used To Be?</A> , <EM>by Madhu M Kurup</EM>
<LI> <a HREF="padala.html">Exploring Perl Modules - Part 1: On-The-Fly Graphics with GD</A> , <EM>by Pradeep Padala</EM>
<LI> <a HREF="ramankutty.html">Programming in Ruby, part 1</A> , <EM>by Hiran Ramankutty</EM>
<LI> <a HREF="sandeep.html">Process Tracing Using Ptrace</A> , <EM>by Sandeep S</EM>
<LI> <a HREF="sevenich.html">Secure and Robust Computer Systems for Primary and Secondary Schools</A> , <EM>by Richard A Sevenich and Michael P Angelo</EM>
<LI> <a HREF="tougher.html">Creating Reusable Software Libraries</A> , <EM>by Rob Tougher</EM>
<LI> <a HREF="vikas.html">SysRq: The Process-nuke</A> , <EM>by Vikas G P</EM>
<LI> <a HREF="lg_backpage.html">The Back Page</A>
</UL>
<!-- *** END toc *** -->
<HR NOSHADE>
<!--=================================================================-->
<H3 ALIGN="center"><EM>Linux Gazette</EM> Staff and The Answer Gang</H3>
<BLOCKQUOTE>
<STRONG>Editor:</STRONG> Michael Orr<BR>
<STRONG>Technical Editor:</STRONG> Heather Stern<BR>
<STRONG>Senior Contributing Editor:</STRONG> Jim Dennis<BR>
<STRONG>Contributing Editors:</STRONG>
Ben Okopnik, Dan Wilder, Don Marti
</BLOCKQUOTE>
<HR NOSHADE>
<!--=================================================================-->
<A HREF="TWDT.txt.gz">TWDT 1 (gzipped text file)</A><BR>
<A HREF="TWDT.html">TWDT 2 (HTML file)</A><BR>
are files containing the entire issue: one in text format, one in HTML.
They are provided
strictly as a way to save the contents as one file for later printing in
the format of your choice;
there is no guarantee of working links in the HTML version.
<HR NOSHADE>
<!--=================================================================-->
<center>
<I>Linux Gazette</I><img alt="[tm]" src="../gx/tm.gif">,
<A HREF="http://www.linuxgazette.com/">http://www.linuxgazette.com/</A><BR>
This page maintained by the Editor of <I>Linux Gazette</I>,
<A HREF="mailto: gazette@ssc.com"> gazette@ssc.com</A>
<P>
<H5>Copyright © 1996-2002 Specialized Systems Consultants, Inc.</H5>
</center>
<HR NOSHADE>
<!--=================================================================-->
<center>
<H1><A NAME="wanted"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/mailbox.gif">
The Mailbag</A></H1> <BR>
<!-- BEGIN wanted -->
</center>
<P> <hr> <P>
<!-- =================================================================== -->
<center><H3><font color="maroon">HELP WANTED : Article Ideas</font></H3></center>
<P>
<P> Send tech-support questions, Tips, answers and article ideas to The Answer Gang
<<A HREF="mailto:linux-questions-only@ssc.com"
>linux-questions-only@ssc.com</A>>. Other mail (including
questions or comments about the <EM>Gazette</EM> itself) should go to
<<A HREF="mailto:gazette@ssc.com">gazette@ssc.com</A>>. All material
sent to either of these addresses will be considered for publication in the
next issue. <EM>Please send answers to the original querent too, so that s/he
can get the answer without waiting for the next issue.</EM>
<P> Unanswered questions might appear here. Questions with
answers--or answers only--appear in The Answer Gang, 2-Cent Tips, or here,
depending on their content. There is no guarantee that questions will
<em>ever</em> be answered, especially if not related to Linux.
<P> <STRONG>Before asking a question, please check the
<A HREF="../faq/index.html"><I>Linux Gazette</I> FAQ</A> (for questions about the
Gazette) or <A HREF="../tag/kb.html">The Answer Gang Knowledge Base</A> (for
questions about Linux) to see if it has been
answered there.</STRONG>
<P> <HR> <P>
<!--====================================================================-->
<!-- BEGIN HELP WANTED : Article Ideas -->
<UL>
<!-- index_text begins -->
<li><A HREF="#wanted/1"
><strong>Linux terminal services server can't connect to internet via network</strong></a>
<li><A HREF="#wanted/2"
><strong>Pls Help (Squid/2000)</strong></a>
<li><A HREF="#wanted/3"
><strong>suggestion for link...</strong></a>
<li><A HREF="#wanted/4"
><strong>Finding a Windows user's home directory from Linux</strong></a>
<li><A HREF="#wanted/5"
><strong>article idea - making the minidistro</strong></a>
<!-- index_text ends -->
</UL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/1"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Linux terminal services server can't connect to internet via network</FONT></H3>
Tue, 02 Jul 2002 12:22:11 -0500
<BR>pat ring (<a href="mailto:linux-questions-only@ssc.com?cc=pat_ring@hotmail.com&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%231">pat_ring from hotmail.com</a>)
<!-- sig -->
<!-- sig -->
<P>
Great eZine. I think the typos, editorial asides and comments, and rough
edits are endearing and "personalizing" experience for the linux
enthusiasts. Your nitpicking detractors obviously are ignorant of the fact
that LG is a labor of love in what seems to be in the spirit of the open
source environment. I know this is a terribly long-winded question, so I
apologize in advance.
</P>
<blockquote><font color="#000066">Thanks, Pat. As for long questions, it's okay. We like that you
actually made some effort ahead of time. In fact since we didn't reply
to your detailed request I have to assume we're stumped, so I'm letting
the readers take a crack at it.
-- Heather</font></blockquote>
<P>
I have a stumper that I can't seem to get answered. I suspect this is more
of a two-NIC network question than a LTSP or K12LTSP question.
</P>
<P>
I have been testing terminal services. I couldn't really get the actual
LTSP working properly (something wrong with X on the client that I couldn't
figure out,) so I downloaded and installed the K12LTSP version of Redhat7.2.
</P>
<P>
This is a great version that offers LTSP as an install option and it works
great right out of the box. My clients log right in and can utilize
terminal services perfectly. However, on my normal installations of Redhat,
I can assign a static IP to the linux PC and use my Win2K gateway to surf
the internet. But when I install the LTSP'ized version with two NICs, I can
ping the gateway, the gateway can ping the LTSP server, but I can't surf the
internet. I think I've tried just about everything to try and use the
gateway for internet access. If I can get the LTSP server on the internet
via the gateway, then I believe the LTSP clients will fall into place, as
well.
</P>
<P>
Some details.
</P>
<P>
My network "server" is actually a Win2k PC with internet connection sharing.
</P>
<P>
I use VNC to virtually connect to the gateway to open and close dial in
connections to the internet. I have to use win2k because I need an
"internet answering machine" to answer the phone when I am online and there
is no linux support in this area (living in the sticks, as I do, also makes
separate lines very much cost prohibitive for dial in access to the
internet.)
</P>
<P>
The terminal services PC has two NICs. ETH0 attached to the terminal
services clients via a 3com switch. ETH1 is attached via an additional
switch to my network.
</P>
<P>
I might have a problem with the way the subnets are setup:
</P>
<P><BLOCKQuote>
ETH0 is assigned by the K12LTSP default install to 192.168.0.254 and serves
the LTSP clients .100 to .253.
</BLOCKQuote></P>
<P>
ETH1 also gets its 192.168.0.x IP address either manually or through DHCP
from the network. It doesn't matter if I manually assign the IP or let DHCP
handle the IP asignment, but I have known for years that if I let DHCP
handle the assignment, I can't surf, so I just use 192.168.0.88. This may
be because the DHCP services via Windows Internet COnnection Sharing aren't
really full DHCP.
</P>
<P>
My win2k gateway PC is 192.168.0.1 and I always enter this address as the
DNS server.
</P>
<P>
I tried to manually change the LTSP subnet on ETH0 to 192.168.1.254, etc.,
but I'm not sure this is the problem. Does the fact that the two subnets
are using the same subnet scheme create the problem? I could see if the
clients couldn't surf, then that may be the case, but the LTSP gateway can't
surf.
</P>
<P>
After about 30 installs, different configurations, etc., I'm not sure where
to go further with this issue. Can I provide some conf files that might
give you an idea of where I need to go? Is this DNS or a route problem?
Can the same IP adress scheme be used because the subnets are on different
NICs, or is this the problem? Can you push me in the right direction of
where to get some help?
</P>
<P>
Thanks for your help.
</P>
<!-- end 1 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/2"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Pls Help (Squid/2000)</FONT></H3>
Tue, 16 Jul 2002 17:03:21 +0530
<BR>Vikas Kanodia (<a href="mailto:linux-questions-only@ssc.com?cc=vikas@rocsearch.com&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%232">vikas from rocsearch.com</a>)
<!-- sig -->
<!-- sig -->
<P>
Hello ,
</P>
<P>
I've installed Squid-2.5.PRE8 & Samba 2.2.5 on RedHat Linux 7.1.So i wanted
to authenticate windows 2000 users in Squid.So i've install the Winbind &
configure as per the documentation available on the net , link is attached
pls see(Authentication tab).
<A HREF="http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5"
>http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5</A>
<<A HREF="http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5>"
>http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5></A>;
</P>
<P>
After doing all the things successfully...when i run the squid it gives the
message like this...
</P>
<blockquote><pre>[root@gnspl-prx bin]# ./squid
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| squid.conf line 1746: http_access allow manager localhost localh
2002/07/15 10:46:23| aclParseAccessLine: ACL name 'localh' not found.
2002/07/15 10:46:23| aclParseAclLine: IGNORING: Proxy Auth ACL 'acl AuthorizedUsers
proxy_auth REQUIRED' because no authentication schemes are fully configured.
2002/07/15 10:46:23| aclParseAclLine: IGNORING invalid ACL: acl AuthorizedUsers
proxy_auth REQUIRED
2002/07/15 10:46:23| squid.conf line 1751: http_access allow all AuthorizedUsers
2002/07/15 10:46:23| aclParseAccessLine: ACL name 'AuthorizedUsers' not found.
2002/07/15 10:46:23| Squid is already running! Process ID 9957
[root@gnspl-prx bin]#
</pre></blockquote>
<P>
Pls guide me...
</P>
<P>
Thanks.
</P>
<P>
Regards,
<BR>Vikas Kanodia
</P>
<blockquote><font color="#000066">This is a bit more complicated than the stuff Thomas' "Weekend Mechanic"
column covered in issue 78
(<A HREF="../issue78/adam.html"
>http://www.linuxgazette.com/issue78/adam.html</A>) -- anybody care to help
him out?
</font></blockquote>
<blockquote><font color="#000066">Some articles on living the life of a Windows server when you're really
a Linux box would be cool, too.
-- Heather</font></blockquote>
<!-- end 2 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/3"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">suggestion for link...</FONT></H3>
28 Jul 2002 23:10:53 -0400
<BR>D. Goel (<a href="mailto:linux-questions-only@ssc.com?cc=deego@glue.umd.edu&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%233">deego from glue.umd.edu</a>)
<P>
hi
</P>
<P>
i went to www.linuxgazette.com and tried to find a 'subscribe to paper
version' link to send to a coworker, but could not find one.
</P>
<P>
if you could please let me know of such a site, and include a link to
it on the main page..
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
</P>
<P>
DG
</P>
<blockquote><font color="#000066">Maybe we should put a link on the mirrors page about paper copies to the
FAQ entry for which formats <EM>LG</EM> isn't available in, since it describes
how to make quality printouts.
-- Heather</font></blockquote>
<blockquote><font color="#001F3F">Attention publishers, there continues to be high demand for a print version
of <EM>LG</EM> .
</font></blockquote>
<blockquote><font color="#001F3F"><EM>LG</EM> is not available in printed format. Since it's freely redistributable,
anybody has the right to offer this service. Since nobody has done this in the
six years <EM>LG</EM> has been in existence, even though there have been numerous
requests, one has to consider why. It costs money to print and deliver a paper
version, and the subscription rate would be higher than most people would be
willing to pay. Those outside the publisher's own country or region can forget
it; the mailing cost alone would be prohibitably high. Plus there's the
labor-intensive world of "subscription fulfillment": taking down names and
addresses, processing payments, updating addresses, etc. It can't all be
automated, unless you can somehow wave a wand and get everybody to fill out the
forms perfectly correctly every time.
</font></blockquote>
<blockquote><font color="#001F3F">Commercial magazines can justify all these costs by building a business around
selling advertisement space, but <EM>LG</EM> does not accept advertisements.
<EM>Consumer Reports</EM> don't accept advertising either, but again they have built a whole
business around it. One can't see the incentive for building such a business
around <EM>Linux Gazette</EM> , especially since Linux print magazines are already
available. (Unashamed plug for <EM>Linux Journal</EM> .)
-- Mike</font></blockquote>
<!-- end 3 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/4"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Finding a Windows user's home directory from Linux</FONT></H3>
Wed, 10 Jul 2002 11:13:39 -0600
<BR>Dee Abson (<a href="mailto:linux-questions-only@ssc.com?cc=dee.abson@sait.ab.ca&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%234">dee.abson from sait.ab.ca</a>)
<!-- sig -->
<!-- sig -->
<P>
Greetings,
</P>
<P>
I've decided to try and integrate a RedHat 7.3 computer into our Windows NT
domain based network, going for that brass ring of single sign-on and
integrating the Windows necessities - access to Windows print queues and
Windows file servers.
</P>
<P>
I have successfully implemented winbind (and samba, natch) under RedHat 7.3
and am now able to log on using a Windows domain based user name and
password. Through a little more research and such, I have Linux configured
so the user directory is setup automatically when the Windows user logs in
for the first time, printconf makes it easy to connect to an SMB-based print
queue and LinNeighborhood helps locate and mount SMB file shares. The only
missing piece of the puzzle, as far as I'm concerned at the moment, is
mapping the Windows user's home directory (which is a share on an SMB
server) to a subfolder under their Linux home directory. I'm certain that I
can accomplish the automatic mapping using the PAM module pam_mount
(available at <A HREF="http://pam-mount.conectevil.com"
>http://pam-mount.conectevil.com</A> if anyone's interested in a
look), it's retrieving the user's Windows home directory that eludes me.
</P>
<P>
Thus my question is this: How can I retrieve the Windows user's home
directory, that elusive little string that will complete my puzzle, from my
<A HREF="http://www.redhat.com/">Red Hat</A> system?
</P>
<P>
Many thanks,
<BR>Dee Abson, MCSE
</P>
<blockquote><font color="#000066">Okay, this question has two parts. As an MCSE he may already know where
MSwin keeps this valuable information stored; what he needs to know is
how to make Linux properly ask for it, or dig it up across the shares.
</font></blockquote>
<blockquote><font color="#000066">It wouldn't be as easy as running 'grep' against some plaintext file, or
maybe in a pipeline combined with 'strings'... would it? If it would,
is that a security problem?
</font></blockquote>
<blockquote><font color="#000066">p.s. Don't attach HTML along with the plaintext. It's so messy and sent
3 times the text for the exact same message.
-- Heather</font></blockquote>
<!-- end 4 -->
<!-- . . . . . . . . . . . . . . . . . . . -->
<HR WIDTH="40%" ALIGN="center">
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">article idea - making the minidistro</FONT></H3>
Mon, 8 Jul 2002 14:25:24 -0400
<BR>Tony Tonchev (<a href="mailto:linux-questions-only@ssc.com?cc=tony@stclaire.com&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%235">tony from stclaire.com</a>)
<!-- sig -->
<!-- sig -->
<P>
Hi,
</P>
<P>
This article idea may sound silly. I don't even know how to describe the
topic, but here it goes...
</P>
<P>
For some time now, I've been thinking of developing a minimal/modular
Linux distribution designed to allow small businesses to use Linux for
their server needs rather then the M$ solutions. This idea is inspired
partially by PizzaBox file server that Kyzo
(<A HREF="http://www.kyzo.com/free_stuff.html"
>http://www.kyzo.com/free_stuff.html</A>) made available a few years ago,
but their product is crippled and not Open Source. The same is partially
true for <A HREF="http://www.guardiandigital.com"
>http://www.guardiandigital.com</A> and their excellent product.
</P>
<P>
Anyway, my problem is that I don't know where to start. I've looked at
"Linux From Scratch" and "BYO Linux", but the most helpful information
came from "Building Tiny Linux Systems with Busybox" Parts 1 through 3,
published in ELJ. The three articles did help me understand some
fundamentals and allowed me to actually plan my next step more
intelligently.
</P>
<P>
Imagine having a modular Linux-based server that consists of a core and
modules. The core will contain the basic services (kernel, security,
networking, dhcp, etc. Web-based administration of all services should
be available as well as equivalent console-based administration. Typical
Modules will be a Web Server module, Workgroup File Server module, Mail
Server module, Firewall module, FTP module, etc. All modules should be
independent of each other and include their respective web and
console-based administration components.
</P>
<P>
In other words if I want just a file server, then I install the core and
file server module only. If I want a file and mail server then I install
the core, file and mail modules and that's it.
</P>
<P>
Here is yet another requirement: The core and all modules must have the
smallest possible memory footprint reasonably possible. I like uClibc,
BusyBox and TinyLogin because they all fit on a floppy. Why can't the
core and each installable module fit on one or two installation
floppies? That will be easy to download and install unlike a 600meg ISO.
</P>
<P>
As you can probably tell, I know where I want to go, but don't know how
to get there. Maybe my whole idea is flawed due to my lack of knowledge.
An article or articles on how to build that unique Linux
mini-distribution will be great.
</P>
<P>
Whew...
</P>
<P>
Thanks for the time
</P>
<P>
Tony Tonchev
</P>
<blockquote><font color="#000066">Hmm, let me see if I have this right. You want to be able to do all
these cool things, where maybe the real core fits on one floppy, and
maybe each "module" as you put it (not to be confused with kernel
modules) fits on a floppy of its own. Load up enough of them and you
have the dream server, which fit in your lunchbox or purse.
</font></blockquote>
<blockquote><font color="#000066">I note that a 196 MB cd-rom fits in the same space as one floppy (except
that it's slimmer). But you're right - watching someone take us through
this process of development would be a great article.
</font></blockquote>
<blockquote><font color="#000066">You may want to keep an eye on current development in the LNX-BBC
project. Nope, it has nothing to do with Britain's prime television station.
It's what happens when you use cloop compression to cram a fairly usable
Linux setup on a 50 MB "bootable business card" . Think LNX = squished
LiNuX. Since you're interested in rolling your own, I recommend reading
about the new GAR setup and, quite literally, checking it out.
(<A HREF="http://www.lnx-bbc.org"
>http://www.lnx-bbc.org</A>)
</font></blockquote>
<blockquote><font color="#000066">There are piles of specialized "mini distros" out there. This request
clearly aims towards the general use setup. A making-of article for any of
the minis might be fun to see, though.
-- Heather</font></blockquote>
<!-- end 5 -->
<a name="mailbag"></a>
<P> <hr> <P>
<!-- =================================================================== -->
<center><H3><font color="maroon">GENERAL MAIL</font></H3></center>
<P> <HR> <P>
<!--====================================================================-->
<!-- BEGIN GENERAL MAIL -->
<UL>
<!-- index_text begins -->
<li><A HREF="#mailbag/1"
><strong>IMAP</strong></a>
<li><A HREF="#mailbag/2"
><strong>LG #80: add to `Red Hat and USB devices'</strong></a>
<li><A HREF="#mailbag/4"
><strong>Using debug to write fresh MBR</strong></a>
<li><A HREF="#mailbag/5"
><strong>Mirrors</strong></a>
<li><A HREF="#mailbag/6"
><strong>Re: [LG 76] mailbag #1 cybercoffee shop</strong></a>
<li><A HREF="#mailbag/7"
><strong>Sweet...</strong></a>
<li><A HREF="#mailbag/8"
><strong>Ideas, huh?</strong></a>
<!-- index_text ends -->
</UL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/1"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">IMAP</FONT></H3>
Mon, 1 Jul 2002 08:37:14 -0400
<BR>Scott Sharkey (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%231%20IMAP">ssharkey from linuxunlimited.com</a>)
<P>
Hi Heather,
</P>
<P>
Just read your TAG about IMAP. You're right that Courier-IMAP is the
best.... run ith with Postfix instead of sendmail and you'll be even
happier. Then mix in Sqwebmail (from Courier's author) and you'll
be REALLY spoiled.
</P>
<P>
Just for grins, I mixed in OpenLDAP, and now have a server with
no Unix accounts, full IMAP/Pop/WebMail capability, and very
easy to maintain.
</P>
<P>
I use sylpheed as a mail client so far -- gotta try Evolution
sometime. The OpenLDAP handles the address book too.
</P>
<P>
-Scott
</P>
<!-- end 1 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/2"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">LG #80: add to `Red Hat and USB devices'</FONT></H3>
Mon, 01 Jul 2002 14:39:17 +0100
<BR>Daniel Baumann (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%232%20Red%20Hat%20and%20USB">danielbaumann from linuxmail.org</a>)
<P>
hi lg team,
</P>
<P>
i have a little add to the article `<A HREF="http://www.redhat.com/">Red Hat</A> and USB devices' in you current issue.
</P>
<P>
the missed kernel config files from the different redhat default kernels are located
in <TT>/usr/src/linux-*/configs.</TT>
</P>
<P>
greetings,
daniel
</P>
<blockquote><font color="#000066">Normally I don't leave sig blocks in, but since we occasionally get
requests asking us about free ISPs who cater to linux users... this
isn't specifically an endorsement, but you're all welcome to go look.
-- Heather</font></blockquote>
<P>
Get your free email from www.linuxmail.org
</P>
<!-- end 2 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/4"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Using debug to write fresh MBR</FONT></H3>
Wed, 3 Jul 2002 18:53:23 -0400
<BR>Ben Okopnik (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%234%20MBR%20rewrite">the <em>LG</em> Answer Gang</a>)
<P>
A recent follow-up to my MBR-rewriting article: a guy who had an E:
drive (yup, Wind*ws) that he wanted to blow off contacted me - seems
that Partition Magic wouldn't touch it as it was. He either didn't want
to or didn't know how to open up the machine and swap cables, so I
tweaked that debug program for him:
</P>
<blockquote><pre>Original
-----------
mov dx,9000
mov es,dx
xor bx,bx
mov cx,0001
mov dx,0080
mov ax,0301
int 13
int 20
-----------
</pre></blockquote>
<P>
Change the numbers in "mov dx,0080" for the appropriate drive:
</P>
<blockquote><pre>hda C: 0080
hdb D: 0081
hdc E: 0082
</pre></blockquote>
<P>
Worked like a charm, according to the very happy fella.
</P>
<!-- end 4 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/5"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Mirrors</FONT></H3>
Sat, 06 Jul 2002 00:45:22 +0000
<BR>Daniel Young (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%235%20mirrors">alandanielyoung from hotmail.com</a>)
<P>
A question.
Do you pay your Mirrors?
</P>
<blockquote><font color="#000066">No.
</font></blockquote>
<blockquote><font color="#000066">They don't pay us, either.
</font></blockquote>
<blockquote><font color="#000066">-- Dan Wilder
</font></blockquote>
<blockquote><font color="#001F3F">No. The mirrors are run by people who want to host a mirror.
</font></blockquote>
<blockquote><font color="#001F3F">You didn't ask, but none of the LG staff is paid either, we're all volunteers.
I'm the only one who's "paid", but paid in the sense that SSC donates some
of my work time to LG. (I normally do web application and sysadmin stuff for
<I>Linux Journal</I>.)
</font></blockquote>
<blockquote><font color="#001F3F">-- Mike Orr, Editor, Linux Gazette
</font></blockquote>
<!-- end 5 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/6"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Re: [LG 76] mailbag #1 cybercoffee shop</FONT></H3>
Wed, 10 Jul 2002 13:43:00 -0700
<BR>sandra (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%236%20cybercoffee%20shop">sfg from peak.org</a>)
<P>
I just want to make a small mention of our own little cybercafe... we're
not gurus but we're definitely geeks here.
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
</P>
<P>
Sandra Guzdek (waving hi to Heather Stern)
<br>Sip N Surf Cybercafe
<br>Eugene, OR
</P>
<blockquote><font color="#000066">Hi Sandra! (Sandra is the webmaster at one of my client sites.)
Thanks to Sandra I also found a really cool search engine specific to hunting
up internet coffeshops and kiosks - <A HREF="http://cybercaptive.com"
>http://cybercaptive.com</A> - which may be
a little spotty since it relies on visitor reports, but at least it's
international in scope. I was kind of amused when I looked up San Jose and
had to pick through the entries checking that I was finding places in California.
-- Heather</font></blockquote>
<!-- end 6 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/7"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Sweet...</FONT></H3>
Wed, 17 Jul 2002 19:59:29 -0500
<BR>Tim Chase (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%237%20sweet">gumnos from hotmail.com</a>)
<P>
As a long time self-taught user of Linux/Unix/Ultrix (and several other
flavours), I've become addicted to such handy tools as vi, grep, sed, awk,
ctags, and the bazillion other little utilities that can be so artisticly
chained together to produce the desired results. I've stumbled across your
LG archives, and all I can say is "WOAH!" I'm going to have to find myself
a text-to-speech translator so I can read/listen-to all of this good stuff
whilst at work, because there's just so much in here. Thanks for such a
fabulous (and fun!) resource...
</P>
<P>
-tim chase
</P>
<blockquote><font color="#000066">On behald of everbody here, THANKS! BTW, I've heard festival
(<A HREF="http://www.cstr.ed.ac.uk/projects/festival"
>http://www.cstr.ed.ac.uk/projects/festival</A>) is pretty
nice. Lots of things at Freshmeat that are supposed to use speech
really use either it or ViaVoice under the hood.
-- Heather</font></blockquote>
<!-- end 7 -->
<!-- . . . . . . . . . . . . . . . . . . . -->
<HR WIDTH="40%" ALIGN="center">
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Ideas, huh?</FONT></H3>
Fri, 19 Jul 2002 22:12:14 -0700
<BR>The Gaijin (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%238%20homebrew%20hardware">blades from inreach.com</a>)
<P>
Home-brew hardware plans! Genertic GPL motherboard designs, SCSI
cards, video, audio, PCI modems, NICs...everything Microsoft is trying
to corner the market on. Some people feel Linux has only ten good years
left if the current trend continues.
</P>
<blockquote><font color="#1F1F1F">Some people believe that the Moon is made of green cheese and that
big-bellied Santa Claus (with a sack of presents, no less) comes down a
foot-wide chimney. "Other people are/think/do" is a very poor reason for
doing something; I prefer to believe that people are _not_ sheep.
-- Ben</font></blockquote>
<P>
Since the anti-trust suit,
Microsoft's political contribution budget has gone from $100,000 per
year to over $6.1 million, and now they're trying to get manufacturers
to implement Microsoft-specific anti-piracy security measures directly
at the hardware level (called "Paladium").
</P>
<blockquote><font color="#1F1F1F">And those who do will end up in the same toilet as the winmodem/
winprinter manufacturers: the domain of the ignorant. I think that
lesson has been well ingrained. There's a small market out there that
sells to the gullible, but the whole world certainly isn't about to
switch <EM>en masse</EM>.
-- Ben</font></blockquote>
<P>
The only true solution I can see is to go back to the days of
bread-boarding our own hardware in Dad's garage...public domain circuit
designs from electronic hobbyist magazines and soldering irons. We've
"de-marketized" software. Why not the hardware, too? If we can create
the greatest operating system on the planet, imagine what Linux users
can do with computers themselves. It would be nice to have something no
organization or agency can legally touch or ruin for a buck. A
collection of Linux-friendly hardware diagrams in the public domain that
anyone can produce for the cost of parts alone. Our own hardware would
completely end our dependency on third-party drivers and vulnerability
to corporate rail-roading. I think creating our own hardware database
would be the best move we could ever make.
</P>
<P>
Regards
</P>
<blockquote><font color="#1F1F1F">I believe that you're seriously underestimating the difficulty and the
complexity of what you propose. Even if Joe Average did have the
necessary soldering, etc. skills (and I assure you that soldering
multi-layer PCboards _is_ a skill, one that takes time and patience to
acquire), where would he get the boards themselves? The average
mainboard today is at least a six- or a seven-layer type; there's no way
for the average experimenter to make one of those. Besides all that,
there's the troubleshooting of the finished board - I can assure you
that this will be required in most cases. How many people are capable of
it? How many of them will burn a trace just as they're about to wrap up
the project (i.e., after they've sunk hours into it?) How many have an
oscilloscope, which is what's necessary for troubleshooting high-speed
digital electronics?
</font></blockquote>
<blockquote><font color="#1F1F1F">I suggest that mainboard manufacture is the province of highly
skilled, highly knowledgeable people - not something that can be
retailed to Joe Average. I suggest that a much better tactic would be to
create a Linux certification authority, someone who can brand hardware
"100% Linux-compatible" in bright red ink; a goal that manufacturers
could strive for and easily achieve, given how much hardware support
already exists in Linux.
-- Ben</font></blockquote>
<blockquote><font color="#000066">There is a thing called "open-hardware". AFAIR they got open pci, agp,
bridges and stuff. For a short time they even had a open-processor
(arm clone) but that was pulled when arm pissed them off. So, the
designs are there, but who is going to build the stuff? Writing 0.18um
structures in your kitchen isn't that easy
<IMG SRC="../gx/dennis/smily.gif" ALT=";-)"
height="24" width="20" align="middle">
</font></blockquote>
<blockquote><font color="#000066">I think that the problem lies not with us linux users, we KNOW that M$
is up to something "bad". But what about those windows dau's that
simple stick to win "because it`s all so easy". Do you think they will
go through much trouble to make their own computer? No, if the thing
is cheap and it's easy (like in sharing your whole hdd with other
kazaa users
<IMG SRC="../gx/dennis/smily.gif" ALT=";-)"
height="24" width="20" align="middle"> they even let the government spy on them and allow ms
to know what dvd they watch and how ofter.
</font></blockquote>
<blockquote><font color="#000066">When such M$ hardware with the fritz chip arise these people will buy
them (in large numbers) so that it will be hard to get hardware that
does not feature these chips. But I think there will be a small market
(for us linux users and some intelligent win users) and where there is
a market there will be a seller.
</font></blockquote>
<blockquote><font color="#000066">Lets hope for the best
</font></blockquote>
<blockquote><font color="#000066">-- Robos
</font></blockquote>
<blockquote><font color="#000066">While I'm a big fan of the make it yourself philosphy, remember that
the widespread presence of all the good toys ... cars, and computers
themselves come to mind ... came not from the individual skilled
crafstmen, but from the assembly line. I find it far easier to maintain
an old 386 for ten years past its expected lifespan, than to figure out
how I'd compose a replacement out of loose copper wire and transistors.
Given that I'm among those whom Ben describes as able to wield a
soldering iron and knowing what an oscilloscope is (I don't own one, but
I know where to borrow a few) I just don't think garage made P7-oids
are going to happen real soon.
</font></blockquote>
<blockquote><font color="#000066">The buzzword you're looking for is "economy of scale". We haven't
"de-marketized" software ... we've shown there's a growing market for a
much greater variety of software.
</font></blockquote>
<blockquote><font color="#000066">Speaking of "so easy" ... the ease is mostly an illusion, fostered by
all those strong-arm OEM deals that resulted in nearly all systems being
preloaded with MSwin. Now that Linux, and perhaps rarely, occasional
others, are also being pre-loaded you'll see that particular bubble pop.
It's mostly flat already, since reinstalling MSwin after it crashes too
many times is so painful.
</font></blockquote>
<blockquote><font color="#000066">In countries where someone cannot simply wander into a department store,
buy a few new couch pillows, tortilla chips and salsa, and a box of the
latest rev of MSwin on special, buying into an expensive foreign
standards probably won't happen either. Indeed, here's looking to a long
and profitable time for companies that don't buy into the "palladiium"
chip game. Can you say "sink the Clipper chip?" Knew you could.
-- Heather</font></blockquote>
<blockquote><font color="#1F1F1F">A better solution might be to join the struggle to give some of the power
back to the people through the establishment of public campaign financing.
It should help to fight many more problems than just M$ taking over.
</font></blockquote>
<blockquote><font color="#1F1F1F">Some URL's to check for more info about this are:
</font></blockquote>
<blockquote><font color="#1F1F1F"><A HREF="http://www.angelfire.com/al/10avs/links.html#campfin"
>http://www.angelfire.com/al/10avs/links.html#campfin</A>
</font></blockquote>
<blockquote><font color="#1F1F1F"><A HREF="http://www.sonic.net/~doretk/Issues/96-04%20APRIL/alliance.html"
>http://www.sonic.net/~doretk/Issues/96-04%20APRIL/alliance.html</A>
</font></blockquote>
<blockquote><font color="#1F1F1F"><A HREF="http://www.thealliancefordemocracy.org"
>http://www.thealliancefordemocracy.org</A>
</font></blockquote>
<blockquote><font color="#1F1F1F">-- John Karns
</font></blockquote>
<!-- end 8 -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright ©</a> 2002
<BR>Published in issue 81 of <I>Linux Gazette</I> August 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<center>
<H1><A NAME="tips"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/twocent.jpg">
More 2¢ Tips!</A></H1> <BR>
<!-- BEGIN tips -->
Send Linux Tips and Tricks to <A HREF="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</A></center>
</center>
<UL>
<!-- index_text begins -->
<li><A HREF="#tips/1"
><strong>Spam comments</strong></a>
<li><A HREF="#tips/2"
><strong>Playing CD Music Digital Output</strong></a>
<li><A HREF="#tips/3"
><strong>Getchar and loops...</strong></a>
<li><A HREF="#tips/4"
><strong>epoch</strong></a>
<li><A HREF="#tips/5"
><strong>crypt undefined</strong></a>
<li><A HREF="#tips/6"
><strong>diald</strong></a>
<li><A HREF="#tips/7"
><strong>Killing GUI applications under KDE</strong></a>
<li><A HREF="#tips/8"
><strong>GRUB - Window XP can not load</strong></a>
<li><A HREF="#tips/9"
><strong>Kylix</strong></a>
<li><A HREF="#tips/10"
><strong>use an .rpm without installing it</strong></a>
<li><I>Linux Journal's</I> Weekly News Notes
<a href="#tips/lj">Tech Tips</a>
<ul>
<LI>Watching multiple log files at once
<LI>Switching to Maildir format mailboxes
<LI>Running screen-oriented programs directly
<LI>Your running processes
<li><A HREF="http://noframes.linuxjournal.com/subscribe/lja-sub.html"
>subscribe</A> to LJWNN
</ul>
<!-- index_text ends -->
</UL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/1"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Spam comments</FONT></H3>
4 Jul 2002 15:52:02 -0400
<BR>Karl Vogel (<a href="mailto:linux-questions-only@ssc.com?cc=vogelke@dnaco.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%231">vogelke from dnaco.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_answer.html#tag/greeting"
><em>LG</em> issue 80 TAG blurb</a>.</blockquote>
<P><STRONG><FONT COLOR="#000066"><EM>
In LG 80, Heather was rumored to have said:
</EM></FONT></STRONG></P>
<P><STRONG><FONT COLOR="#000066"><EM>
Almost the only spam that escapes Dan's traps anymore are those dratted
conman scams telling me about how their late uncle <TT>/</TT> business partner /
revered general or whatever left them a quadzillion dollars <TT>/</TT> francs or
whatever and they can't get at any of it unless you as a friend /
distant relative <TT>/</TT> confidant <TT>/</TT> conveniently uninvolved sucker open your
bank account to help them launder it.
</EM></FONT></STRONG></P>
<P>
Do you use "ifile"? That nails just about all the spam I get, including
those stupid laundering schemes. The best part is that it gets smarter
with time; the more spam you feed it, the better it weeds out crap.
</P>
<P><DL><DT>
Source:
<DD><A HREF="http://www.ai.mit.edu/~jrennie/ifile"
>http://www.ai.mit.edu/~jrennie/ifile</A>
</DL></P>
<P><DL><DT>
Mailing list:
<DD><A HREF="http://groups.yahoo.com/group/ifile-discuss"
>http://groups.yahoo.com/group/ifile-discuss</A>
</DL></P>
<P><DL><DT>
Some tips plus a nice procmail setup and ifile database:
<DD><A HREF="http://www2.picante.com:81/~gtaylor/spam"
>http://www2.picante.com:81/~gtaylor/spam</A>
</DL></P>
<P>
My .procmailrc is below.
</P>
<P>
-- Karl Vogel
</P>
<p align="center">See attached <tt><a href="misc/tips/vogel.procmailrc.txt">vogel.procmailrc.txt</a></tt></p>
<!-- end 1 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/2"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Playing CD Music Digital Output</FONT></H3>
Tue, 2 Jul 2002 11:17:04 -0400 (VET)
<BR>Ernesto Hernandez-Novich (<a href="mailto:linux-questions-only@ssc.com?cc=emhn@telcel.net.ve&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%232">emhn from telcel.net.ve</a>)
<blockquote>This is in reply to the <a href="../issue79/lg_mail.html#wanted/2"
><em>LG</em> issue 79, help wanted #2</a>.</blockquote>
<P>
Hi,
</P>
<P>
Regarding Bill Parks question on the June issue, as to how to play
CD audio <EM>without</EM> the analog cable usually connecting CD-ROMs to
audio cards, a similar situation happens if you have one of the latest
iBooks. There is no way to tweak the sound driver to do what he wants,
but XMMS can be of help. He should try using the "CD Audio Player"
Input Plugin (select it via Preferences -> Audio I/O Plugins) and
configure it accordingly, say have <TT>/dev/hdc</TT> (the "real" CD-ROM device,
not <TT>/dev/cdrom</TT> which is usually a symlink) and <TT>/cdrom.</TT> Then, put the
audio CD, and open a "Playlist" in XMMS but instead of selecting a File,
select the <TT>/cdrom</TT> directory; he'll see the audio tracks there and be
able to play and listen to them.
</P>
<P>
That's right, the system will be doing CDDA extraction from the CD
into XMMS, which then plays it through OSS/ESD/ARTS. Ugly, but works.
</P>
<blockquote><code><font color="#000033"><br>Ernesto Hernndez-Novich
<br>GPG Key Fingerprint = 438C 49A2 A8C7 E7D7 1500 C507 96D6 A3D6 2F4C 85E3
</font></code></blockquote>
<!-- end 2 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/3"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Getchar and loops...</FONT></H3>
Mon, 8 Jul 2002 08:34:35 -0500 (CDT)
<BR>Jay R. Ashworth, Pradeep (<a href="mailto:linux-questions-only@ssc.com?cc=zaikxtox@yahoo.com&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%233">the <em>LG</em> Answer Gang</a>)
<BR>Question by Zaikxtox (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%233">zaikxtox@yahoo.com</a>)
<P>
Hello. I'm trying to write a very simple C program
that needs to attend the user input without blocking a
loop. I have porgrammed many time on pascal, and there
the code will be something like:
</P>
<blockquote><pre>begin
while not keypressed
writeln('hello! i'm still alive');
end.
</pre></blockquote>
<P>
well... when i use C code i try the getchar function,
but it waits until a key is pressed blocking the
program.
</P>
<P>
How can i know if there is a key into the buffer
without blocking the execution of my programs?
</P>
<P>
Thanks in advance
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
Zaikxtox
</P>
<BLOCKQUOTE>
[jra]
Well, you can, but it's not exactly trivial, and how you do it depends
on which environment you're coding: raw-C for the glass-tty,
curses/termcap, X, <A HREF="http://www.kde.org/">KDE</A>, Gnome, etc.
</BLOCKQUOTE>
<BLOCKQUOTE>
This is more generic C stuff than Linux stuff; I'd recommend you look
into books like The Unix Programming Environment, by (I think)
Kernighan and Pike, and the Stevens books.
</BLOCKQUOTE>
<BLOCKQUOTE>
[pradeep]
As the other poster mentioned, it depends on where you want this
behaviour. Assuming that you want to do this on a console, ncurses is a
great library to use. It gives you the right abstraction.
</BLOCKQUOTE>
<BLOCKQUOTE><DL><DT>
Read my howto at
<DD><A HREF="http://tldp.org/HOWTO/NCURSES-Programming-HOWTO"
>http://tldp.org/HOWTO/NCURSES-Programming-HOWTO</A>
</DL></BLOCKQUOTE>
<BLOCKQUOTE>
Particularly the function <TT> halfdelay()</TT> should help you for non-blocking key
input.
</BLOCKQUOTE>
<!-- end 3 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/4"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">epoch</FONT></H3>
Sun, 30 Jun 2002 02:22:29 -0700
<BR>Heather Stern (<a href="mailto:linux-questions-only@ssc.com?cc=star@starshine.org&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%234"><em>Linux Gazette</em> Technical Editor</a>)
<!-- sig -->
<P>
Recently one of the gang mentioned renaming an rpm file to a much
higher version number before running alien, so that the <A HREF="http://www.debian.org/">Debian</A> package
system would not want to overwrite the result.
</P>
<P>
The key to doing that "the right way" is a value that the Debian
maintaineers call the epoch.
</P>
<P>
Of course people are used to seeing package versions like 1.2 or even
1.4.3p1.
</P>
<P>
In the Debian world that might be 1.4.3p1-2 meaning that this is the
second time the Debian maintainer had to build the same version.
Probably he or she has patches in it.
</P>
<P>
But to handle programs whose version numbers don't go constantly up
like time goes forward ... a certain typesetting package comes to
mind ...
</P>
<blockquote><font color="#000066">Must have been some other package. According to its FAQ, TeX's version
number asymptotically approaches pi, growing digits along the way.
-- Heather</font></blockquote>
<P>
... they invented an epoch. epochs start at the invisible "1"
and go up to 99.
</P>
<P>
So a version:
</P>
<blockquote><code><font color="#000033"><br> 99:1.4.3p1-local
</font></code></blockquote>
<P>
Would be 98 epochs ahead of a mere:
</P>
<blockquote><code><font color="#000033"><br> 1.4.3p1-12
</font></code></blockquote>
<P>
and the same number of epochs ahead of:
</P>
<blockquote><code><font color="#000033"><br> 2.1.12-1
</font></code></blockquote>
<P>
If you want your package and the Debian one to live together in
harmony, then rename yours to something before the version number that
does not overlap:
</P>
<blockquote><code><font color="#000033"><br> mtools4flash-3.9.7-1fp
<br> mtools-3.9.7-2
</font></code></blockquote>
<P>
Of course that's safest if the files inside their file list don't
overlap either!
</P>
<blockquote><font color="#1F1F1F">That was the problem, of course; the filesets were exactly the same.
-- Ben</font></blockquote>
<P>
Using either of these methods is safer than setting a hold on the
package, which is sometimes recommended, but which I've seen fail before.
</P>
<!-- end 4 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/5"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">crypt undefined
</FONT></H3>
Tue, 2 Jul 2002 16:48:03 +0200
<BR>Chris Niekel (<a href="mailto:linux-questions-only@ssc.com?cc=chris@niekel.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%235">chris from niekel.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_tips.html#tips/8"
><em>LG</em> issue 80, 2c Tips #8</a>.</blockquote>
<P><STRONG>
g++ -lcrypt server.c
Error: 'crypt' undefined
</STRONG></P>
<P>
The order of the arguments matter. You should try:
</P>
<blockquote><code><font color="#000033"><br>g++ server.c -lcrypt
</font></code></blockquote>
<P>
The linker links from left to right and is a bit dumb.
After compiling server.c, the crypt call is undefined. Then libcrypt.a
is tried, and crypt is defined in there. So it will be resolved.
</P>
<P>
In your case, libcrypt.a doesn't match any undefined symbols (YET!), so
it is not linked into the executable. Then server.o is linked, and that
has an unresolved symbol (crypt). The linker isn't smart enough to go
back to libcrypt.a.
</P>
<P>
The answerer of the questions talks about the name mangling. If you mix
C and C++ code, you have to tell the compiler what is C. That is usually
done by doing:
</P>
<blockquote><code><font color="#000033"><br>extern "C" void foo(int);
</font></code></blockquote>
<P>
This tells the compiler that function foo takes an int, returns nothing
and is a C function. But all standard libraries already do that for you,
so it's very safe to call <TT> crypt()</TT> from C++ code.
</P>
<P>
Greetings,
</P>
<P>
Chris Niekel
</P>
<!-- end 5 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/6"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">diald
</FONT></H3>
Mon, 15 Jul 2002 14:07:38 -0400
<BR>LF11 (<a href="mailto:linux-questions-only@ssc.com?cc=lf11@naisp.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%236">lf11 from naisp.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_tips.html#tips/10"
><em>LG</em> issue 80, 2c Tips #10</a>.</blockquote>
<P><STRONG>
I've mainly been connecting to the internet using diald, but I've noticed
that I'm only getting about 3.5 KBps , whereas on W98 I get about 5KBps. A
little experimentation shows that dialling with kppp gives about 5KBps as
well.
</STRONG></P>
<P><STRONG>
kppp seems to use an initialisation string of ATM1L1, but changing MODEM_INIT
to "ATM1L1" in <TT>/etc/diald/connect</TT>, didn't improve the performance.
</STRONG></P>
<P><STRONG>
MODEM_INIT started out as "ATZ&C1&D2%C0". I changed "%C0" to "%C3" to ensure
that compression was enabled, but this made no difference. I can't find an
option in diald to log exactly what's sent to the modem and I can't see any
conflicting options in the configuration for pppd.
</STRONG></P>
<P><STRONG>
Any suggestions for how to track down why kppp gets better performance than
diald would be appreciated.
</STRONG></P>
<P><STRONG>
The modem is an MRI 56K internal modem.
</STRONG></P>
<P>
Check the port speeds. It's likely that diald is using a port speed of
28.8KBps or 56KBps. Try to have something well above the actual speed of the
modem, as the data coming from the modem may be substantially higher in
volume than the actual modem's capability (due to hardware compression).
</P>
<P>
The only exception to this is with a USR 56k Faxmodem I have when used with
WvDial; it must be at 56k, and I don't know why. If the computer port speed
is set higher than that, what comes across the line from the modem seems to
be escaped characters of some sort, along the lines of
</P>
<blockquote><code><font color="#000033"><br>CONNECT 49333/ARQ
<br>f [18] f [18] `[1e]~[1e]~[1e][06][1e]x[1e][18]x
</font></code></blockquote>
<P>
And pppd says "LCP timeout sending Config-Requests" in syslog. Just thought
I'd let you know about this problem in case you have it.
</P>
<P>
HTH,
-cj
</P>
<BLOCKQUOTE>
[Neil]
Beware, it doesn't read <TT>/etc/diald/diald.conf.</TT> According to the man page
"diald reads options first from <TT>/etc/diald/diald.defs</TT>, then from
<TT>/etc/diald/diald.options</TT>".
</BLOCKQUOTE>
<BLOCKQUOTE>
Putting speed 115200 in diald.options gave me a
throughput 4.9KBps downloading Mozilla 1.1 alpha.
</BLOCKQUOTE>
<!-- end 6 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/7"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Killing GUI applications under KDE</FONT></H3>
04 Jul 2002 08:17:43 +0530
<BR>Ashwin N (<a href="mailto:linux-questions-only@ssc.com?cc=ashwin_n@gmx.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%237">ashwin_n from gmx.net</a>)
<!-- sig -->
<!-- sig -->
<P>
Here's a quick way of killing a GUI application that has hung or is not
quitting (or you just want to kill for fun
<IMG SRC="../gx/dennis/smily.gif" ALT=":-)"
height="24" width="20" align="middle">. Press Ctrl-Alt-Esc and
your mouse pointer turns into skull-and-bones. Now, click on the
offending application to kill it. This works only under <A HREF="http://www.kde.org/">KDE</A>.
</P>
<P>
Of course, "xkill" command does the same thing, but this is much easier
and faster to use.
</P>
<P>
Ashwin
</P>
<BLOCKQUOTE>
[Ben]
Good tip, Ashwin! Under IceWM, I have "xkill" tied to "Alt-Ctrl-K" for
the same functionality:
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQuote>
(from "~/.icewm/keys")
</BLOCKQuote></BLOCKQUOTE>
<blockquote><code><font color="#000033"><br>key "Alt+Ctrl+k" /usr/bin/X11/xkill
</font></code></blockquote>
<!-- end 7 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/8"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">GRUB - Window XP can not load</FONT></H3>
Fri, 28 Jun 2002 16:43:08 +0100
<BR>Neil Youngman (<a href="mailto:linux-questions-only@ssc.com?cc=orion982@yahoo.com&cc=n.youngman@ntlworld.com&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%238">n.youngman from ntlworld.com</a>)
<BR>Question by Soufian Widjaja (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%238">orion982@yahoo.com</a>)
<P><STRONG>
I find some info online that we can overwrite
the boot loader and then install boot loader
for Window by
run fdisk <TT>/</TT> MBR on Windows
If this is the way, how can I do that?
What to do with my Linux once we overwrite
the MBR?
</STRONG></P>
<P>
I think what's needed is to experiment with the GRUB command line mode. When
the menu comes up press 'c' to go to command line mode and try a few
variations on the command sequence you've got in <TT>/boot/grub/menu.last</TT>
When you come up with a command sequence that works, then edit your GRUB
config to match.
</P>
<P>
2 things to try are:
</P>
<P><BLOCKQuote>
1 After the rootnoverify command add the command makeactive.
2 Try varying the partition numbers in the rootnoverify command.
</BLOCKQuote></P>
<P><DL><DT>
There's lots of handy info in Linux Journal #85, see
<DD><A HREF="http://www.linuxjournal.com/article.php?sid=4622"
>http://www.linuxjournal.com/article.php?sid=4622</A>
</DL></P>
<P>
Hope That Helps
</P>
<!-- end 8 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/9"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Kylix
</FONT></H3>
Wed, 3 Jul 2002 20:04:57 GMT
<BR>Chirag Wazir (<a href="mailto:linux-questions-only@ssc.com?cc=oam@mail.cosett.com.bo&cc=wazir@vsnl.com&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%239">wazir from vsnl.com</a>)
<BR>Question by Octavio Aguilar (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%239">oam@mail.cosett.com.bo</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_mail.html#wanted/1"
><em>LG</em> issue 80, Help Wanted #1</a>.</blockquote>
<P><STRONG><FONT COLOR="#000066"><EM>
Does anybody know how to run a program that's compiled in Kylix,
but without having the Kylix environment around at runtime?
</EM></FONT></STRONG></P>
<P>
If you want to run a compiled Kylix program outside the IDE you need to run
</P>
<blockquote><code><font color="#000033"><br> source /usr/local/kylix2/bin/kylixpath
</font></code></blockquote>
<P>
first, or add it to your <TT>/etc/profile</TT>
</P>
<P>
I had the same problem initially - so I presume that's what the question is
about - my Spanish is non-existent.
</P>
<P>
The alternative interpretation could be about making a distribution package
to run on machines where Kyilx isn't installed - I haven't tried that yet.
</P>
<P>
Chirag Wazir
</P>
<!-- end 9 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/10"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">use an .rpm without installing it
</FONT></H3>
Sat, 6 Jul 2002 13:40:26 -0500 (COT)
<BR>RE Otta (<a href="mailto:linux-questions-only@ssc.com?cc=ashwin_n@gmx.net&cc=obob@qwest.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%2310">obob from qwest.net</a>)
<BR>Previous Tip by Ashwin M (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%2310">ashwin_n@gmx.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_answer.html#tips/18"
><em>LG</em> issue 80, 2c Tip #18</a>.</blockquote>
<P>
It is simpler to use Midnight Commander. Click on the rpm file like you
would a directory and transverse the rpm as you would a branch of the
directory tree. Locate the file or files and copy them to an actual
directory with the copy button. Simple and effective!
</P>
<BLOCKQUOTE>
[John Karns]
I've found that some mc versions changed the rpm handling behavior. I had
grown quite accustomed to viewing rpm contents and copying parts via mc,
then after installing <A HREF="http://www.suse.com/">SuSE</A> 7.1 on my laptop, was no longer able to view
more than a partial list of the files in the rpm; specifically the rpm
headers (description, etc.). I was able to correct the problem finding
the mc scripts used for rpm handling, and changing one to agree with a
previous mc version script.
</BLOCKQUOTE>
<BLOCKQUOTE>
One other point is that for very large rpm files (over 2 or 3 MB), the
process can be very slow. When dealing with rpm files containing large
tar balls of source code, I usually just "install" the rpm, which copies
the desired file to <TT>/usr/src/packages/SOURCES.</TT>
</BLOCKQUOTE>
<!-- end 10 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/lj"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy"><em>Linux Journal</em> Weekly News Notes tech tips</FONT></H3>
<h4 align="center"><br>Watching multiple log files at once
</h4>
<P>
Recent versions of the GNU tail command let you tail multiple files
with the same command. Combined with the -f option, you can watch
multiple log files. For example:
</P>
<blockquote><code><font color="#000033"><br> tail -f /var/log/httpd/access_log /var/log/httpd/error_log
</font></code></blockquote>
<P>
will monitor the <A HREF="http://www.apache.org/">Apache</A> access and error logs.
</P>
<HR width="10%" align="center">
<h4 align="center"><br>Switching to Maildir format mailboxes
</h4>
<P>
If you're moving from old-style mailboxes to Maildir directories for
your mail, you can force Mutt to create Maildir directories by default
with:
</P>
<blockquote><code><font color="#000033"><br> :set mbox_type=Maildir
</font></code></blockquote>
<P>
in your .muttrc file.
</P>
<P>
To get Procmail to deliver to directories as Maildir and not MH
folders, put a <TT>/</TT> after the directory name in your recipes, like this:
</P>
<blockquote><code><font color="#000033"><br># Dump mail from Microsoft viruses into a trash Maildir
<br>:0 Bf
<br>* Content-Type: application/octet-stream;
<br>trash/
</font></code></blockquote>
<HR width="10%" align="center">
<h4 align="center"><br>Running screen-oriented programs directly
</h4>
<P>
To run a screen-based program such as top remotely with one ssh
command, use the -t (terminal) option to ssh, like this:
</P>
<blockquote><code><font color="#000033"><br> ssh -t myserver top
</font></code></blockquote>
<HR width="10%" align="center">
<h4 align="center"><br>Your running processes
</h4>
<P>
For an easy-to-understand, compact view of what's running on your
system now, try the pstree command. A handy option is -u, which shows
the name of the user running each process. Option -p shows the process
ID, so if you want to memorize only one option combination, try:
</P>
<blockquote><code><font color="#000033"><br> pstree -pu
</font></code></blockquote>
<P>
(No pun intended.)
</P>
<P>
pstree is a good way to make sure that privilege separation is working
in your upgraded ssh install--you did upgrade sshd, didn't you?
</P>
<!-- end 12 -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright ©</a> 2002
<BR>Published in issue 81 of <I>Linux Gazette</I> August 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<A HREF="http://www.linuxgazette.com/"
><H1 align="center"><IMG ALT="LINUX GAZETTE" SRC="../gx/../gx/lglogo.jpg"
WIDTH="600" HEIGHT="124" border="0"></H1></A>
<P>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<center>
<H1><A NAME="answer">
<img src="../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Gang</font>
<img src="../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and...
(<a href="tag/bios.html">meet the Gang</a>) ...
the Editors of Linux Gazette...
and You!
<br>Send questions (or interesting answers) to
The Answer Gang
for possible publication
(but read the <a href="../tag/ask-the-gang.html">guidelines</a> first)
</H4>
</center>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<p><hr><p>
<H3>Contents:</H3>
<dl>
<dt><a href="#tag/greeting"
><strong>¶: Greetings From Heather Stern</strong></A></dl>
<DL>
<!-- index_text begins -->
<dt><A HREF="tag/1.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
></a>Can't See Boot Messages Even Though RedHat 7.2 Boots OK --or--
<dd><A HREF="tag/1.html"
><strong>Shedding Light On A Monitor's Troubles</strong></a>
<br>We're still in the dark, here.
<dt><A HREF="tag/2.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
><strong>ide-scsi emulation for IDE IOMEGA ZIP 250MB</strong></a>
<dt><A HREF="tag/3.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
><strong>Sound</strong></a>
<dt><A HREF="tag/4.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
><strong>Version incompatibility</strong></a>
<!-- index_text ends -->
</DL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<A NAME="tag/greeting"><HR WIDTH="75%" ALIGN="center"></A>
<H3 align="left"><img src="../gx/dennis/hbubble.gif"
height="50" width="60" alt="(¶) " border="0"
>Greetings from Heather Stern</H3>
<!-- begin hgreeting -->
<blockQuote>
It's been a slow month here at the Gazette, with some days actually being so light that
some gang members piped up with "did I fall off the list?" Not so slow that we didn't
get tips and threads, though. And not quite so slow that I'm publishing all the threads
we got or anything like that.
</blockQuote>
<blockQuote>
Readers are being very helpful to each other and I'm glad that the Help Wanteds are
popular. Andy Fore tells us that with so much fuss over the Alcatel Speedtouch and
its gory details, it now has a HOWTO of its very own (although not by him). Here it
is:
</blockQuote>
<blockQuote><BLOCKQuote>
<A HREF="http://linux-usb.sourceforge.net/SpeedTouch/howto.html"
>http://linux-usb.sourceforge.net/SpeedTouch/howto.html</A>
</BLOCKQuote></blockQuote>
<blockQuote>
I'm glad to see that with enough people's work on tiny bits here and there, we all
grow richer for it.
</blockQuote>
<blockQuote>
The Peeve Of The Month this time around is some fellow who, not getting more than
raw guesses from The Answer Gang, and figuring it out himself, instead of chiming in
with it decided to tell us off how stupid and flatfooted we all are, not to mention
how dare <EM>we</EM> ask <EM>him</EM> for the answer. I'll save you all the grumpy replies. Let's
just say that we didn't promise you our rose garden wouldn't have thorns, bugs, or
that we'd have an instant gauze bandage (brand-name or otherwise) handy if you get
bit. We try our best, when we've got a few moments free. That's all we can really do.
</blockQuote>
<blockQuote>
Which brings me to the topic of my babbling this month. I certainly say it often
enough face to face...
</blockQuote>
<h4 align="center"><br> When Did Your Important Data Become Important To You?
</h4>
<blockQuote>
With the sub-thought... and perhaps you should decide what really is important,
instead of discovering it in emergency. Take a good look at your own day for a week
or two, and notice the things and people that you need the most.
</blockQuote>
<blockQuote>
Unfortunately the financial world continues to be slow too. While Linux increasingly
creeps onto people's desktops and has pretty much taken root in their LAN closers -
especially places still small enough to use closets instead of glass houses and cardkey
setups - there continues this persistent and patently false feeling that those free
software zealots have no interest in spending money.
</blockQuote>
<blockQuote>
Not true in the slightest. If it was there wouldn't be all these shows on our topic,
like this month's LinuxWorldExpo in San Francisco (<A HREF="http://www.linuxworldexpo.com"
>http://www.linuxworldexpo.com</A>).
We just want to get our money's worth when we do.
</blockQuote>
<blockQuote>
Take this example. Just last week the news that <em>Linux Weekly News</em>
(<a href="http://www.lwn.net/">LWN.net</a>) was almost out of money - again -
resulted in another heartening rush of help for them from readers eager to keep getting
their dose of Linux events... enough for them to consider that a web based subscription
model might not fall <EM>plop</EM> on its rear, after all.
</blockQuote>
<blockQuote>
Free projects are good, but many of the finer ones have their commercial support avenues
too, and not always with the obviosu product name placed in their URLs, either.
Berkeley DB has Sleepycat (<A HREF="http://www.sleepycat.com"
>http://www.sleepycat.com</A>), and so on. Without noting anybody in
particular - I'm sure you all have different things you really use your computers for out
there - I'd like to encourage everyone to continue to put their money where their mouth
is. Pick up a distro at an installfest, and decide it doesn't drive you as batty as some
other distro or OS you tried before? Buy their next version. Like an incredibly cool
free software project that never asks a dime and says "we're doing this 'cuz it works,
not 'cuz we need the bucks" ? Send something in thought of a thank you to one of the
organizations that defend making it easy to pass these things around. The tops on
my list are the <A HREF="http://www.debian.org/">Debian</A> project (<A HREF="http://www.debian.org"
>http://www.debian.org</A>), the Free Software Foundation
(<A HREF="http://www.fsf.org"
>http://www.fsf.org</A>), and the EFF (<A HREF="http://www.eff.org"
>http://www.eff.org</A>) but you probably already
guessed that, and I'm sure there are others.
</blockQuote>
<blockQuote>
Don't be afraid to thow kudos in package authors' directions either -
that's at least some pay in "The Coin of The Realm"
(<A HREF="http://www.linuxgazette.org/issue64/lg_answer64.html#tag/greeting"
>http://www.linuxgazette.org/issue64/lg_answer64.html#tag/greeting</A>). If your
life with a package isn't quite perfect but you like it anyway, then pitch in with
some elbow grease, being willing to fuss with ltrace, strace or waste a bit of disk
space on some more verbose logging so your bug reports can be more useful, and even
more importantly, be willing to try the new code when they think they've got some
sort of fix for you.
</blockQuote>
<blockQuote>
Err, don't forget to turn off all the traces and debug stacks when you're done, or
you'll find yourself buying terabyte storage to go with it.
</blockQuote>
<blockQuote>
If you <EM>have</EM> terabyte storage and nothing better to do with it, or at least don't
mind, consider mirroring some projects that your site uses and enjoys the benefits
from. You get a local download, crosslinks, and that's one less chance the project
might disappear on you just because some poor fellow loses his job or completes his
college curriculum and has to move... or that some poor company who was primary-hosting
it will go the way of the dodo and the dotbomb.
</blockQuote>
<blockQuote>
And what people usually mean when they say that fun little phrase:
</blockQuote>
<blockQuote><ol>
<li> don't forget to make backups!
<br>
<li> They aren't bloody well helpful if they don't <EM>work</EM>, so check the
restore procedures once in a while. Go ahead. Grab a spare machine and
try it. Figure out if it really only takes you an hour and a half or
all afternoon to bring the mail server or accounting department back up if
that last power surge fries the UPS and a computer with it.
<br>
<br>(You laugh now, but I have seen a UPS blow out and take the machine with it. I can
still smell the burning plastic and hear that horrible squeal. Thank goodness we
cut off the real power before a <EM>real</EM> fire started. Ugh!)
<br>
<li> Make sure that you've rescued the human-generated work that goes into a
system, not just the grubby details that make it able to boot up. People
are limited in what they can regenerate, and people stressed from losing a
lot of work, even more so.
</ul></blockQuote>
<blockQuote>
Did I mention that we just passed Sysadmins Appreciation Day? It's the
fourth Friday in July. (<A HREF="http://SysAdminDay.boxke.be"
>http://SysAdminDay.boxke.be</A>) From the website:
"Let's face it, System Administrators get no respect 364 days a year..."
</blockQuote>
<blockQuote>
It's a tough world out there, folks. We've got to stand together these days.
If we can't all be heroes, we can at least put our own sense of what heroism is
to good use.
</blockQuote>
<blockQuote>
Have a great August, folks. Now, enjoy the threads
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
</blockQuote>
<!--endcut ========================================================= -->
<!-- end hgreeting -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href=""
>Copyright ©</a> 2002
<BR>Published in issue 81 of <I>Linux Gazette</I> August 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<P>
<H4 ALIGN="center">"Linux Gazette...<I>making Linux just a little more fun!</I>"</H4>
<HR>
<center>
<table cellpadding=7><tr><td>
<IMG SRC="../gx/bytes.gif" border=1 ALT="News Bytes">
</td><td>
<H3>Contents:</H3>
<ul>
<li><a HREF="#leg">Legislation and More Legislation</a>
<li><a HREF="#links">Linux Links</a>
<li><a HREF="#conferences">Conferences and Events</a>
<li><a HREF="#general">News in General</a>
<li><a HREF="#distro">Distro News</A>
<li><a HREF="#commercial">Software and Product News</a>
</ul>
</td></tr></table>
<STRONG>Selected and formatted by <A HREF="mailto:michael.conry@softhome.net">Michael Conry</A> and Mike Orr</STRONG>
</center>
<P> Submitters, send your News Bytes items in
<FONT SIZE="+2"><STRONG>PLAIN TEXT</STRONG></FONT>
format. Other formats may be rejected without reading. You have been
warned! A one- or two-paragraph summary plus URL gets you a better
announcement than an entire press release. Submit items to
<A HREF="mailto:gazette@ssc.com">gazette@ssc.com</A>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<font color="green">
August 2002 <I>Linux Journal</I> -- 100th issue!
</font>
</H3>
<IMG ALT="[issue 100 cover image]" SRC="misc/bytes/lj-cover100.png" WIDTH=200 HEIGHT=268
ALIGN="left" HSPACE="20">
The August issue of <A HREF="http://www.linuxjournal.com/"><I>Linux
Journal</I></A> is on newsstands now.
This issue focuses on LJ's 100th issue. Click
<A HREF="http://www.linuxjournal.com/modules.php?op=modload&name=NS-lj-issues/issue100&file=index">here</A>
to view the table of contents, or
<A HREF="http://www.linuxjournal.com/subscribe/">here</A>
to subscribe.
<P>
<FONT COLOR="green">All articles through December 2001 are available for
public reading at
<A HREF="http://www.linuxjournal.com/magazine.php">http://www.linuxjournal.com/magazine.php</A></FONT>.
Recent articles are available on-line for subscribers only at
<A HREF="http://interactive.linuxjournal.com">http://interactive.linuxjournal.com/</A>.
<BR CLEAR="all">
<!-- =================================================================== -->
<a name="leg"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Legislation and More Legislation</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">JPEG
</FONT>
</H3>
<P>
It emerged during the past month, to the dismay of everyone interested in
open file formats and free software, that the JPEG image compression scheme
may be subject to patent royalties. As
<a href="http://www.theregister.co.uk/content/4/26272.html">
reported</a>
by The Register,
<a href="http://www.forgent.com/">
Forgent Networks</a> have recently come into possession of a
<a href="http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/srchnum.htm&r=1&f=G&l=50&s1='4,698,672'.WKU.&OS=PN/4,698,672&RS=PN/4,698,672">
patent</a> which they claim covers the transmission of JPEG images, and
have even managed to claim royalties from two companies. If this patent
proves to be enforceable, the ISO have said that they will
<a href="http://www.theregister.co.uk/content/4/26339.html">
withdraw JPEG as a standard</a> (the licencing terms being enforced by
Forgent are not compatible with ISO regulations for standards).
Hopefully the patent will not stand up. To make sure of this, the JPEG
committee is
<a href="http://www.jpeg.org/newsrel1.html">
seeking examples of prior art</a> which would render the patent null
and void.
If the worst comes to the worst, it appears that the patent will
expire in 2004 in any case.
<P>
The
<a href="http://swpat.ffii.org/group/index.en.html">
Software Patent Working Group of the FFII</a>,
has pointed out that there are also
<a href="http://swpat.ffii.org/patente/wirkungen/jpeg/index.en.html">
European Patents in existence</a>
which could be used to put a lean on JPEG compression.
A small step can be taken against EU software patents by signing
the <a href="http://www.noepatents.org/index_html?LANG=en">
Petition for a Software Patent Free Europe</a>.
<P>
A webpage bringing together many links on this story is the new
<a href="http://burnalljpegs.org/">
Burn All .JPEGs!</a> website.
Forgent's website also has a
<a href="http://www.forgent.com/company/press_room/in_the_news.shtml">
list</a> of recent appearances of the company in the news, which has a
couple of links to stories regarding the JPEG patent.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Perens and DMCA
</FONT>
</H3>
<P>
<a href="http://perens.com/">
Bruce Perens</a>
generated some publicity this month by
<a href="http://www.infoworld.com/articles/hn/xml/02/07/23/020723hnperens.xml">
threatening</a>
to violate the DMCA
<a href="http://conferences.oreillynet.com/cs/os2002/view/e_sess/3111">
live on stage</a> at the
<a href="http://conferences.oreillynet.com/os2002/">
O'Reilly Open Source Convention</a>.
<a href="http://yro.slashdot.org/comments.pl?sid=36633&cid=3946881">
The plan</a>
was to demonstrate how to remove the region-code control built into a DVD
player. However
<a href="http://www.siliconvalley.com/mld/siliconvalley/business/columnists/dan_gillmor/ejournal/3735855.htm">
as reported by Dan Gilmore</a> and
<a href="http://yro.slashdot.org/article.pl?sid=02/07/26/1739207&mode=nested&tid=153">
by Slashdot</a>,
Bruce backed down from openly breaking the law
following a request from his employers,
<a href="http://www.hp.com/">HP</a>.
<P>
There are several good links regarding this story on the
<a href="http://www.oreillynet.com/oscon2002/">
O'Reilly Open Source Convention Conference Coverage page</a>.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">More DRM (sigh)
</FONT>
</H3>
<P>
A bill proposed by US Senator Biden would make certain kinds of Digital
Rights Management circumvention a
<A HREF="http://thomas.loc.gov/cgi-bin/bdquery/z?d107:s.02395:">felony</A>
(capital crime).
<A HREF="http://zdnet.com.com/2100-1107-946890.html">ZDNet coverage</A> states
that the bill was originally intended to combat large-scale piracy (e.g., fake
Windows holograms), but was quietly rewritten to include DRM. (Courtesy
Slashdot)
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Open source: EU, US, Peru and Pakistan
</FONT>
</H3>
<P>
It was reported in various locations
(<a href="http://www.theregister.co.uk/content/4/26102.html">in The Register</a>,
<a href="http://slashdot.org/article.pl?sid=02/07/09/1739246&mode=nested&tid=99">
on Slashdot</a> and
<a href="http://news.zdnet.co.uk/story/0,,t269-s2118707,00.html">
in ZDNet</a>), that a recent EU report has called for
wider open-source adoption, in order to have greater exchange of software
between different administrative branches, and also between countries.
The
<a href="http://slashdot.org/article.pl?sid=02/07/09/1739246&mode=nested&tid=99">
Slashdot story</a> has links to the original EU report in various formats.
<P>
On a not unrelated theme,
Sam Williams at O'Reilly.net
<a href="http://linux.oreillynet.com/pub/a/linux/2002/07/16/linux_in_govt.html">
has taken a look</a>
at the impact of open source software in government--both inside and
outside the U.S.
<P>
Wired <A HREF="http://www.wired.com/news/business/0,1367,54141,00.html">reports</A>
that the US Ambassador to Peru has come out against Peruvian Congressman
Villanueva's bill advocating usage of open-source software in
gonvernment computers. Also, Bill Gates personally delivered
Peru's president Alejandro Tolero a donation estimated at $550,000
for the national school system. Not surprisingly, the money is
to go to the same schools Villanueva's bill targets.
Villanueva said he believes Microsoft isn't worried so much about
losing the small Peruvian market as the cascading effect that might
happen if other Latin American countries follow suit. Similar bills
are pending in Argentina, Mexico and Brazil, and Spain's Extremadura
region has
<A HREF=http://www.wired.com/news/business/0,1367,51994,00.html"">
already adoped Linux</A> as the official operating system of
its public schools and offices.
<P>
<A HREF="http://www.linuxjournal.com/article.php?sid=6204">Pakistan</A> is
getting into the Open Source game too. 50,000 Pentium IIs running GNU/Linux
are being installed in schools and colleges all over Pakistan, at a cost of
less than US$100 each. "Proprietary software for these PCs would cost a
small fortune. Surely more than what the computers cost!"
<a name="links"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Linux Links</font></H3></center>
<P>
The Register have an
<a href="http://www.theregister.co.uk/content/6/26275.html">
excellent report</a> (originally from NewsForge) by Grant Gross on a
public workshop on digital rights management. It would appear that "fair
use" advocates got less than a warm reception from Hollywood and Dept. of
Commerce representatives.
<P>
Marcelo Tosatti, maintainer of the stable kernel branch
<a href="http://news.zdnet.co.uk/story/0,,t269-s2118919,00.html">
in an interview</a> with ZDNet.
<P>
From <a href="http://www.lwn.net/">LWN</a>, come links to reports
<a href="http://news.com.com/2100-1023-944715.html">
in CNET</a> and
<a href="http://techupdate.zdnet.com/techupdate/stories/main/0,14179,2874933,00.html">
in ZDNet</a> of
the Netherlands' NAH6 plans to release a Secure
Notebook incorporating a program that encrypts files transparently.
The user runs applications on Windows, which is installed in a VMWare
virtual machine. VMWare is run on Debian GNU/Linux, which keeps files
encrypted in case the laptop is stolen or mislaid.
<P>
A few links from
<a href="http://www.linuxjournal.com/"><em>Linux Journal</em></a>
which might be of interest:
<ul>
<li>
An account of
<a href="http://www.linuxjournal.com/article.php?sid=5837">
setting up an old 386</a> on a home network.
</li>
<li>
A Dutch court says
<a href="http://www.linuxjournal.com/article.php?sid=6235">
opt-out is a good enough policy for spam</a>.
(meaning you get the messages unless you specifically request to be removed
from the list), and that if the level of spam gets objectionable, you can
always get a new e-mail address.
</li>
<li>
Doc Searls
<a href="http://www.linuxjournal.com/article.php?sid=6218">
writes</a>
about CARP and suggests that RIAA et al's motive isn't to extract money
from Internet radio stations but rather to shut them down through
royalty rates no station can afford, to protect their CD market.
</li>
<li>
Linux Journal's
<a href="http://www.linuxjournal.com/modules.php?op=modload&name=NS-lj-issues/issue100&file=index">
100th issue</a>.
</li>
<li>
<a href="http://www.linuxjournal.com/article.php?sid=6000">
Linux timeline</a>.
By
<a href="http://www.lwn.net">LWN</a> and
<a href="http://www.linuxjournal.com">LJ</a> staff.
</li>
</ul>
<P>
Some interesting links from
<a href="http://www.theregister.co.uk">The Register</a>
over the past month:
<ul>
<li>
A
<a href="http://www.theregister.co.uk/content/4/25993.html">
$200k prize has been offered</a>
for getting Linux to run legally on Xbox. The first program
<a href="http://www.theregister.co.uk/content/4/26078.html">
isn't much to look at though</a>.
</li>
<li>
European antitrust investigation
<a href="http://www.theregister.co.uk/content/4/25988.html">
considers Palladium</a>, while Microsoft tells us it's
<a href="http://www.theregister.co.uk/content/4/26231.html">
not so bad as it looks</a>, but
<a href="http://www.theregister.co.uk/content/54/26085.html">
not everyone is convinced</a>.
</li>
<li>
2600
<a href="http://www.theregister.co.uk/content/4/26038.html">
withdraws Supreme Court appeal</a> in DeCSS case.
</li>
<li>
<a href="http://www.theregister.co.uk/content/4/26289.html">
Forbes reports on Linux</a>.
</li>
<li>
UK government
<a href="http://www.theregister.co.uk/content/4/26335.html">
cautiously accepts</a>
Open Source.
</li>
<li>
<a href="http://www.theregister.co.uk/content/6/26357.html">
Cracking legal</a> for copyright enforcement?
</li>
<li>
<a href="http://www.theregister.co.uk/content/4/26382.html">
Danger</a>
of the UCITA.
</li>
<li>
NVidia edges towards open source, and opens parts of its compiler
<a href="http://www.theregister.co.uk/content/4/26351.html">
technology to the public</a>.
</li>
</ul>
<P>
DesktopLinux.com are
<a href="http://www.desktoplinux.com/news/NS6907557337.html">
publishing the winning essays</a> from their wIndependence Day contest.
<P>
<a href="http://www.privacyinternational.org">
Privacy International</a> have
<a href="http://www.privacyinternational.org/issues/idcard/uk/">
an FAQ and other information</a>
on proposals to introduce ID cards to
the UK. Probably of quite wide interest.
<P>
A couple of links from
<a href="http://slashdot.org/">
Slashdot</a> which might interest you:
<ul>
<LI>
<A HREF="http://www.msnbc.com/news/785970.asp">USB 2.0</A> is being
backported to Linux kernel 2.4.19. This means the stable Linux kernel
will have access to the upcoming generation of USB devices running 40
times faster than currently. The speedup makes USB CR-RW drives and
network cards practical, and gives performance comparable to FireWire
(but cheaper). This is only the first step: the specific device drivers
still need to be written. Linux users can rejoice that the delay in
getting USB 2.0 support is much less than was the case with USB 1.0, and
that the rate of progress is quite competitive with that of proprietary OSes.
(Another interesting point is that the article was published on MSNBC,
which is half owned by Microsoft but continues to publish pro-Linux articles.)
<LI>
Summary of articles about Secure Computing's SELinux and its
<A HREF="http://slashdot.org/articles/02/07/27/0224224.shtml?tid=155">
patented content</A>.
<li>
A
<a href="http://linuxdailynews.net/">
new portal:
<em>LinuxDailyNews</em></a> has
<a href="http://slashdot.org/articles/02/07/02/1158217.shtml?tid6">
been launched</a>, founded by several existing
Linux portal sites.
</li>
<li>
<a href="http://slashdot.org/articles/02/07/25/0237238.shtml?tid2">
Linux Beer Hike Goes to Ireland</a>.
</li>
</ul>
How Marty Roesch
<a href="http://newsforge.com/article.pl?sid=02/06/29/2127239&mode=thread&tid=3">
made the journey</a> from obsessive gamer to successful open source
developer and entrepreneur.
<P>
<a href="http://www.advogato.org/article/512.html">
The binary nature of freedom</a>, at Advogato (with
<a href="http://newsvac.newsforge.com/article.pl?sid=02/07/05/134242&mode=thread&tid=19">
talkbacks at NewsForge</a>).
<P>
NewsForge have
<a href="http://newsforge.com/article.pl?sid=02/07/12/0137212&mode=thread&tid=23">
a report</a> on the various instant messaging options available to Linux
users.
<P>
Howard Wen at O'Reilly
<a href="http://linux.oreillynet.com/pub/a/linux/2002/03/21/linuxps2.html">
takes a look</a>
at Sony's upcoming Linux distribution kit
for the PlayStation 2.
<P>
Some interesting links from
<a href="http://www.linuxtoday.com/">Linux Today</a>
<ul>
<li>
A detailed
<a href="http://www.nsa.gov/selinux/doc/freenix01/freenix01.html">
white paper</a> from the NSA, on Security-Enhanced Linux.
</li>
<li>
<a href="http://www-106.ibm.com/developerworks/linux/library/l-clutil/?t=gr,lnxw02=CLUtil">
Developing a Linux command-line utility</a> (at IBM developerWorks).
</li>
<li>
CrossNodes have
<a href="http://networking.earthweb.com/netsecur/article/0,,12084_1429131,00.html">
an introduction</a>
to auditing your LAN using nmap.
</li>
</ul>
<P> NewsForge article on
<a href="http://newsforge.com/article.pl?sid=02/07/19/1957242&mode=thread&tid=11">
the game theory of open code</a>.
<P>
Timo Hannay of Nature
<a href="http://www.oreillynet.com/pub/a/network/2002/07/17/timo.html">
compares</a> [O'Reilly]
the scientific method
to the mechanics of open source development.
<a name="conferences"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Upcoming conferences and events</font></H3></center>
<P> Listings courtesy <EM>Linux Journal</EM>. See <EM>LJ</EM>'s
<A HREF="http://www.linuxjournal.com/events.php">Events</A> page for the
latest goings-on.
<!-- *** BEGIN events table [this line needed by Linux Gazette events.py *** -->
<table cellpadding=5 border=0 width=100%>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>USENIX Securty Symposium (USENIX)</b><BR>
<td valign=top>August 5-9, 2002<BR>San Francisco, CA<BR>
<a href="http://www.usenix.org/events/sec02/" target="_blank">
http://www.usenix.org/events/sec02/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>LinuxWorld Conference & Expo (IDG)</b><BR>
<td valign=top>August 12-15, 2002<BR>San Francisco, CA<BR>
<a href="http://www.linuxworldexpo.com" target="_blank">
http://www.linuxworldexpo.com</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>LinuxWorld Conference & Expo Australia (IDG)</b><BR>
<td valign=top>August 14 - 16, 2002<BR>Australia<BR>
<a href="http://www.idgexpoasia.com/" target="_blank">
http://www.idgexpoasia.com/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>Communications Design Conference (CMP)</b><BR>
<td valign=top>September 23-26, 2002<BR>San Jose, California<BR>
<a href="http://www.commdesignconference.com/" target="_blank">
http://www.commdesignconference.com/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>IBM eServer pSeries (RS/6000) and Linux Technical University</b><BR>
<td valign=top>October 14-18, 2002<BR>Dallas, TX<BR>
<a href="http://www-3.ibm.com/services/learning/conf/us/pseries/" target="_blank">
http://www-3.ibm.com/services/learning/conf/us/pseries/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>Software Development Conference & Expo, East (CMP)</b><BR>
<td valign=top>November 18-22, 2002<BR>Boston, MA<BR>
<a href="http://www.sdexpo.com/" target="_blank">
http://www.sdexpo.com/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
</table>
<!-- *** END events table [this line needed by Linux Gazette events.py *** -->
<a name="general"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">News in General</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green"><EM>Linux Journal</EM> articles available for documentation
</FONT>
</H3>
<P>
<P> <EM>Linux Journal</EM>
<A HREF="http://www.linuxjournal.com/article.php?sid=6240">has changed its
author contract</A> to clarify that any author may include his/her articles as
freely-redistributable documentation in a free software project or free
documentation project after the article has been published. Authors have
always had this right since the founding of <EM>LJ</EM>, but some did not
realize they had it. Motivations for doing so are to make the information
available to all users of a program, in a convenient location, and so that the
project can use the article as primary documentation if desired, updating it as
the program evolves.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Linux Weekly News
</FONT>
</H3>
<P>
It looked like the end of the road for
<a href="http://www.lwn.net/">
Linux Weekly News</a>
earlier this month, when they
<a href="http://lwn.net/Articles/5052/">
announced</a>
that the August 1st edition would be the last ever. The basic cause for
this decision was lack of money, and the absence of any plan which could
generate money.
Following the announcement, many disappointed readers put their money on
the table and contributed to LWN's donation scheme. This quickly raised
$12000, leading to a
<a href="http://lwn.net/Articles/5838/">rethink of LWN's future</a>.
A final decision on the magazine's fate has not been made.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Mandrake at Walmart
</FONT>
</H3>
<P>
Following last month's
<a href="http://newsforge.com/article.pl?sid=02/06/14/1316203&mode=thread&tid=23">
launch</a> [NewsForge]
by
<a href="http://www.walmart.com/">
Wal-Mart</a> of PC's with
<a href="http://www.lindows.com">
Lindows</a>
pre-installed, comes a
<a href="http://www.mandrakesoft.com/company/press/pr?n=/pr/products/2315&lg=en">
new announcement of</a>
the availability of
<a href="http://www.linux-mandrake.com/">Mandrake</a>-equipped versions.
The Wal-Mart catalogue contains full details and prices of both the
<a href="http://www.walmart.com/catalog/product_listing.gsp?cat=96356&dept=3944&path=0%3A3944%3A3951%3A41937%3A86796%3A96356">
Lindows</a> and
<a href="http://www.walmart.com/catalog/product_listing.gsp?cat=102252&dept=3944&path=0%3A3944%3A3951%3A41937%3A86796%3A102252">
Mandrake</a> PC product lines.
<P>
NewsForge have
<a href="http://newsforge.com/article.pl?sid=02/07/15/0147230&mode=thread&tid=23">
reported on this story</a>, as
<a href="http://www.theregister.co.uk/content/4/26192.html">has The
Register</a>.
Hopefully the Mandrake version of this product will prove more satisfactory
than the earlier Lindows offering, which received
<a href="http://newsforge.com/article.pl?sid=02/07/02/1247234&mode=thread&tid=23">
a very lukewarm review</a>
from NewsForge.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Ogg and Real
</FONT>
</H3>
<P>
Congratulations to the folk behind the
<a href="http://www.xiph.org/ogg/vorbis/">
Ogg Vorbis</a>
project, who have
<a href="http://www.ogg.org/ogg/vorbis/index.html">
released a version 1.0</a>.
As linked
<a href="http://lwn.net/Articles/5057/">from LWN</a>,
there are currently various news items related to the 1.0 release on
<a href="http://www.vorbis.com/news.psp">
Ogg Vorbis News</a>.
This story was also reported
<a href="http://www.theregister.co.uk/content/4/26176.html">
by The Register</a> and
<a href="http://news.com.com/2100-1023-945228.html">
by CNET</a>,
<P>
<a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a> and
<a href="http://www.xiph.org/">Xiph.org</a> have also been in the news this
month due to the links being forged between the open source format and the
new
<a href="http://www.realnetworks.com/info/helix/index.html">
Helix</a>
software of
<a href="http://www.realnetworks.com/">RealNetworks</a>. This development
should see some parts of RealNetworks' software
<a href="http://linuxtoday.com/news_story.php3?ltsn=2002-07-24-016-26-NW-DT-SW">
being released</a>
under "a community and open source licence". Inclusion of the Ogg Vorbis
codec into RealNetworks products should follow.
<P>
Bruce Perens has written an
<a href="http://newsforge.com/article.pl?sid=02/07/23/0032247&mode=thread&tid=11">
in-depth account</a>
of the issues surrounding the RealNetworks-Xiph link-up, and has criticised
many features of the deal, such as the fact that Real's codecs will remain
proprietary, and the use of community licencing (rather than opensource)
for parts of their software.
Rob Lanphier of RealNetworks has
<a href="http://slashdot.org/comments.pl?cid=3933287&sid=36511&tid=126">
replied to Bruce</a> on Slashdot, and asked for good will to be shown to
the company's open source contribution.
The Register has also
<a href="http://www.theregister.co.uk/content/4/26314.html">
reported on</a>
Real's open source experiment,
<a href="http://news.com.com/2100-1023-945406.html">
as has CNET</a>.
The
<a href="http://www.helixcommunity.org/">
Helix Community website</a> should report future developments in the open
source development of the RealNetworks Helix project, and also contains
copies of the
<a href="http://www.helixcommunity.org/content/licenses.html">
licences</a> the software will be released under (comments are invited).
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">GNU Scientific Library (GSL) 1.2 is Released
</FONT>
</H3>
<P>
Version 1.2 of the GNU Scientific Library is now available.
The GNU Scientific Library is a collection of routines for numerical
computing in C.
This release is backwards compatible with previous 1.x releases.
The project home page is at
<a href="http://www.gnu.org/software/gsl/">
http://www.gnu.org/software/gsl/</a>.
Information for developers is at
<a href="http://sources.redhat.com/gsl/">
http://sources.redhat.com/gsl/</a>.
<a name="distro"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Distro News</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Debian
</FONT>
</H3>
<P>
Big news in the Debian world this month,
Debian GNU/Linux 3.0 (Woody) has
<a href="http://www.debian.org/News/2002/20020719">
been released</a>!
Debian GNU/Linux now supports a total of eleven processor architectures,
includes KDE and GNOME desktop environments, features cryptographic
software, is compatible with the FHS v2.2 and supports software developed
for the LSB. This was also
<a href="http://www.theregister.co.uk/content/4/26323.html">
reported by The Register</a>. As
<a href="http://www.debian.org/News/weekly/2002/28/">
reported by Debian Weekly News</a>,
the new testing distribution
<a href="http://lists.debian.org/debian-devel-announce-0207/msg00011.html">
will be called "sarge"</a>.
<P>
<hr noshade width="20%">
<P>
A new revision of Potato, 2.2r7, was also
<a href="http://www.debian.org/News/2002/20020713">
released</a>. Main changes were security updates, and a couple of
corrections.
<P>
<hr noshade width="20%">
<P>
<a href="http://www.debian.org/News/weekly/2002/28/">
Debian Weekly News reported</a> that the patent claims being made against
the jpeg image compression scheme could require the movement of
libjpeg62 and everything compiled against it into non-free.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Gentoo
</FONT>
</H3>
<a href="http:/www.tinyminds.org">tinyminds.org</a>
have published an
<a href="http://www.tinyminds.org/modules.php?op=modload&name=News&file=article&sid=429&mode=thread&order=0&thold=0">
interview</a> with Daniel Robbins of
<a href="http://www.gentoo.org/">
Gentoo Linux</a>.
There are a
<a href="http://newsvac.newsforge.com/newsvac/02/07/27/152253.shtml?tid=23">
few talkbacks</a> on NewsForge.
<P>
<hr width="20%" noshade>
<P>
LinuxPlanet have a
<a href="http://www.linuxplanet.com/linuxplanet/reviews/4302/1/">
recent review</a>
of Gentoo Linux 1.2.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">RedFlag
</FONT>
</H3>
<P>
<a href="http://www.redflag-linux.com">
Redflag Software Technologies Co., Ltd</a>
and
<a href="http://www.opera.com">
Opera Software</a>
have made a strategic announcement, and are looking forward to working
together on embedded browser solutions for the Chinese market.
RedFlag will seek to join as an Opera reseller, with joint development
and market efforts to tailor Opera for the Chinese embedded market.
<P> With Opera included, RedFlag will be able to offer original equipment
manufacturers (OEMs) and hardware manufacturers Web-enabled solutions
customised to fit with Red Flag's current product line.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">SuSE
</FONT>
</H3>
<P>
<a href="http://www.suse.de/en">SuSE Linux</a> has
announced the availability of the
<a href="http://www.suse.de/en/products/suse_business/email_server/">
SuSE Linux eMail Server 3.1</a>
with expanded system functionalities. SuSE's
e-mail solution which assists in managing appointments, tasks, and
resources, is aimed specifically at small and medium-scale enterprises as
well as workgroups and public administrations.
<P>
<hr noshade width="20%">
<P>
<a href="http://www.suse.de/en/">
SuSE Linux</a>
has also announced its participation in
<a href="http://www.tsanet.org">
TSANet</a> - the "Technical
Support Alliance Network". TSANet is a global support platform
that hosts more than 150 hardware and software providers. Within
the scope of TSANet, various manufacturers cooperate in providing
solutions for problems their enterprise customers encounter in
connection with their applications.
<P> For detailed information on the support offer of SuSE, please
check
<a href="http://support.suse.de/en/">
http://support.suse.de/en/</a>
<a name="commercial"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Software and Product News</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Opera
</FONT>
</H3>
<P>
<a href="http://www.opera.com">
Opera Software</a>
has announced the
release of Opera 6.02 for Linux. The new version includes important fixes
to the document and user interface, with special emphasis on the display of
Asian characters, making this a useful upgrade for Linux users all over
the world.
Opera 6 opened up Asian markets to Opera, because of its added ability
to display non- Western characters, and the Linux version has proved to be
especially popular in this region.
<P>
Opera 6.02 for Linux is available for free in a ad-supported version at
<a href="http://www.opera.com">
www.opera.com</a>.
Users can purchase a banner-free version for USD 39. Discounts apply.
<P>
<hr width="20%" noshade>
<P>
<a href="http://www.opera.com">
Opera Software ASA</a>
has also announced that
<a href="http://www.suse.de/en">
SuSE</a>
will distribute the popular Opera for Linux Web browser in their Linux
distribution. The deal is Opera's first major Linux distribution agreement.
Opera is available in SuSE Linux 8.0.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Random Factory
</FONT>
</H3>
<P>
<a href="http://www.randomfactory.com/">
The Random Factory</a>, have a range of scientific software for Linux,
covering subjects such as astronomy, chemistry, and biotechnology. Also
available are Linux workstations, preloaded with a choice of Random Factory
products.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Magic Software
</FONT>
</H3>
<P>
<a href="http://www.magicsoftware.com/edeveloper">
Magic Software Enterprises</a>, a provider of
application development technology and business solutions announced today
the introduction of
<a href="http://www.magicsoftware.com/edeveloper">
Magic eDeveloper</a>
into the Chinese market.
Magic Software
<a href="http://www.magicsoftware.com/bin/en.jsp?enPage=InnerPage&enDisplay=view&enDispWhat=object&enDispWho=tech%5El4%5EsLinux&enZone=tech&enVersion=0&enretain=branch&">
support Linux</a>
on some of their product lines.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Other software
</FONT>
</H3>
<P>
<a href="http://www.varicad.com">
VariCAD</a>
has announced the release of a new VariCAD 8.2.0.2 Update for both Windows
and Linux operating systems. This mechanical 3D/2D CAD package offers tools
for 3D modelling, 2D drafting, libraries of mechanical components,
calculations, BOM's, and many others. It is priced $399.
Free trial versions for Windows 98/NT/200/XP and Linux (RedHat, Mandrake,
SuSE) are available for downloading at
<a href="http://www.varicad.com">
http://www.varicad.com</a>
<P>
Linux Game Publishing is looking for beta testers for Mindrover 1.07b. You
can register your interest at <a
href=http://betas.linuxgamepublishing.com/>betas website</a>. Successful
applicants will be notified by e-mail.
<!-- *** BEGIN copyright *** -->
<P> <hr> <P>
<H5 ALIGN=center>
Copyright © 2002, Michael Conry and
the Editors of <A HREF="mailto:gazette@ssc.com"><I>Linux Gazette</I></A>.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<i>making Linux just a little more <font COLOR="red">lovable!</font></i>"
<img ALT="" SRC="../gx/adam/heart.png" WIDTH="30" HEIGHT="25">
</h4>
<p> <hr> <p> <!--===================================================================-->
<p ALIGN=CENTER><img ALT="[picture of mechanic]" SRC="../gx/adam/mechanic.png" ALT="Weekend Mechanic Logo" ALIGN=BOTTOM WIDTH=399 HEIGHT=135 BORDER=0></p>
<h1 ALIGN=CENTER><font COLOR="maroon">The Weekend Mechanic</font></h1>
<h4 ALIGN=CENTER>By <a HREF="mailto:thomas_adam16@yahoo.com">Thomas
Adam</a></h4>
<p> <hr> <p> <!--===================================================================-->
<!-- END header -->
<!-- =======================================================================-->
<!-- --------------- -->
<!-- BEGIN: contents -->
<!-- --------------- -->
<UL>
<LI><A HREF="#preamble">Welcome to the July edition</A></LI>
<LI><A HREF="#quotas">A Brief Introduction: Quotas</A></LI>
<LI><A HREF="#dansg">A Brief Introduction: DansGuardian</A></LI>
<LI><A HREF="#touchrec">Touchrec: Recursively touches files in a
directory</A></LI>
<LI><A HREF="#gnufind">GNU Find: Evaluating its effectiveness</A></LI>
<LI><A HREF="#intjf">Interview: John M. Fisk</A></LI>
<LI><A HREF="#closet">Closing Time</A></LI>
</UL>
<!-- --------------- -->
<!-- END: contents -->
<!-- --------------- -->
<HR>
<! -- ======================================================================= -->
<! -- --------------- -->
<! -- BEGIN: preamble -->
<! -- --------------- -->
<H2><A NAME="preamble">Welcome to the July edition</A></H2>
<P>Well Howdy. Glad you could all make it. How are you all??? Still keeping
up the pace with the rest of the LG thus far? I hope so, 'cos I can't see
that this article is going to be any different :-)</P>
<P>News for this month?? Well, I have installed myself in my house now.
When I get the chance, I'll get some pictures together for you all to have
a sneak preview into the isolated, but pretty corner of Somerset that I
now reside in when I am not at University, that is.</P>
<P>I also have a new job!! I work in a small factory, which produces eight
different types of luxury dessert for a chain-store called <I>Waitrose</I>.
For those of you who don't know who this company is, <I>Waitrose</I> is
part of the <I>John Lewis Partnership, plc</I>. They specialise in nice,
high quality food. For the really curious among you, here is a list of the
desserts I make:</P>
<UL>
<LI>Chocolate Mousse</LI>
<LI>Zabaglioni (Amorretti biscuit-base mousse)</LI>
<LI>Lemon Dessert</LI>
<LI>Rhubarb Syllabub</LI>
<LI>Blackberry Syllabub</LI>
<LI>Creme Brulee</LI>
<LI>Creme Brulee with Chocolate and Grand Marnier</LI>
<LI>Creme Brulee with Raspberry Compote</LI>
</UL>
<P>I start at 6:00am :-) That's the only the drawback. However it does
mean that I finish around 2-4 in the afternoon.</P>
<P>That's about as exciting as my life gets really, I think it is time to
move on to some proper material.<B> Linux.....</B></P>
<!-- ============= -->
<!-- END: preamble -->
<!-- ============= -->
<HR>
<!-- ======================================================================== -->
<!-- ============= -->
<!-- BEGIN: Quotas -->
<!-- ============= -->
<H2><A NAME="quotas"></A>A Brief Introduction: Quotas</H2>
<!-- ====================== -->
<!-- BEGIN: Content Listing -->
<!-- ====================== -->
<UL>
<LI><A HREF="#Q-wiq">What is Quota?</A></LI>
<LI><A HREF="#Q-inst">Installation</A></LI>
<LI><A HREF="#Q-sq">Setting Quotas</A></LI>
<LI><A HREF="#Q-an">An Example</A></LI>
</UL>
<!-- ==================== -->
<!-- END: Content Listing -->
<!-- ==================== -->
<HR>
<!-- ============================ -->
<!-- BEGIN: Quotas: What is Quota -->
<!-- ============================ -->
<H2><A NAME="Q-wiq">What is Quota?</A></H2>
<P>Way, way back in <A HREF="../issue13/slew.html">
issue 13</A> Jim Dennis wrote a small article about how to set up your
Linux machine so that it would tell you if you were going to run out of
disk space. (SLEW). I read this article, and decided that you can make sure that
your users do not run amok on disk space by enforcing a set <B>rules</B>
by either specifying the number of inodes or blocks that a particular
user cannot exceed.</P>
<P>Quota is handled on a per-user basis though, and is only active on one
file system at a time. Thus, if a user has access to more than one file
system, and you wish to enforce quotas on each of them, then you must do so
separately.</P>
<P>So in short, quota is a way of setting maximum disk space that a user
can consume, at any one time</P>
<HR WIDTH=25%>
<!-- ========================== -->
<!-- END: Quotas: What is Quota -->
<!-- ========================== -->
<!-- ========================== -->
<!-- =========================== -->
<!-- BEGIN: Quotas: Installation -->
<!-- =========================== -->
<H2><A NAME="Q-inst">Installation</A></H2>
<P>As of Kernel version >=2.0, Quota support has been bundled in with the
kernel, and as such, if you come from the dark ages, and have a kernel
version <2.0, then obtain the latest source (<A
HREF="http://www.kernel.org">www.kernel.org</A>) NOW!!</P>
<P>And as for the rest of the GNU/Linux planet, you should find that you
already have quota support enabled by default in the kernel anyway. If you
<I>think</I> you have not, then download the latest stable release and
re-compile. It can't hurt.....much :-). For instructions on how to do this,
please refer to the INSTALL file, under the source directory.</P>
<P>Incidentally, for those users running a nice shiny SuSE Box, Quota
automatically comes compiled into the kernel :-)</P>
<P>But the fun-and-games continue, since Quota is not directly runnable
from the kernel itself (i.e. it is not a self-contained module). You have
to either install an RPM for Source file.</P>
<P>The RPM file (should you be using a distribution that uses this system
of package handling) in question is:</P>
<B>quota-1.70-263.rpm</B>
<P>And the tarball file is called:</P>
<B>all.tar.gz</B>
<P>Both of which are available from the following FTP repository:</P>
<A HREF="ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/">
ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/</A>
<P><U>To install the RPM file:</U></P>
<P>Issue the command:</P>
<B>su - -c'rpm -i /path/to/quota-1.70-263.rpm'</B>
<P><U>To install the source file</U></P>
<PRE>
1. <B>su -</B>
2. <B>cd /path/to/tarball/</B>
3. <B>tar xzvfm ./all.tar.gz</B>
4. <B>./configure</B></PRE><I>[ Allow for configure script to run ]</I>
<PRE>
5. <B>make && make install</B>
6. <B>logout</B></PRE><I>[ To exit out of root's "su;ed" account
]</I>
<P>That's all there is to it :-) Now the <I><B>real</B></I> fun begins</P>
<!-- ======================== -->
<!-- END: Quota: Installation -->
<!-- ======================== -->
<HR WIDTH=25%>
<!-- ============================ -->
<!-- BEGIN: Quota: Setting Quotas -->
<!-- ============================ -->
<H2><A NAME="Q-sq">Setting Quotas</A></H2>
<P>The first step in configuring this, is to have a logical idea in your
head as to how you are going to organise this. Quota gives you the option
of either specifying a single user, or a group (which has been assigned to
specific users), or both. If you are on a large network, then perhaps a
mixture of the two is preferable. Think about it :-)</P>
<P>Group version is usually good, if you assign <B>all</B> users to that
specific group. Makes life easier, <EM>n'est pas?</EM></P>
<P>But the first actual step is to make some system-wide changes. For
this, log in as user <B>root</B>. Please though, do not simply
"su" in, as this simply changed your effective UID, and does
nothing about export variables, etc.</P>
<P>We must first modify "/etc/fstab" so that the kernel knows
that the filesystem mount point will make use of the quota support. A
typical "/etc/fstab" file looks like the following:</P>
<PRE>
/dev/hda1 /boot ext2 defaults 1 2
/dev/hda2 swap swap defaults 0 2
/dev/hda3 / ext2 defaults 1 1
/dev/cdrom /cdrom auto ro,noauto,user,exec 0 0
/dev/fd0 /floppy auto noauto,user 0 0
proc /proc proc defaults 0 0
usbdevfs /proc/bus/usb usbdevfs defaults 0 0
devpts /dev/pts devpts defaults 0 0
#NFS clients....
#Updated: Thomas Adam, Tuesday 03:45am??? -- Can't remember.
server:/etc /mnt/etc nfs rw,user,rsize=1024,wsize=1024,hard,intr 0 0
server:/home /mnt/home nfs rw,user,rsize=1024,wsize=1024,hard,intr 0 0
server:/usr/doc/lg/lg/lwm /mnt/lwm nfs rw,user,hard,intr 0 0
#server:/usr /mnt/usr nfs rw,user,hard,intr 0 0
server:/cdrom /cdrom nfs ro,user,rsize=1024,wsize=1024,hard,intr 0 0
server:/dev /mnt/dev nfs ro,user,rsize=1024,wsize=1024,hard,intr 0 0
</PRE>
<P>What we are concerned with, is not the last part of the file <I>[ ** although
<B>quota</B> can be used with <B><I>nfs</I></B> exported file types -- see
"man rquota" ** ]</I>, but with
which mount point is to be issued with quota support. This will depend
upon where your user's $HOME directories are located. Unless you have got a
separate partition or drive for this, then typically the mount points you
will want to use is either "/" or "/usr" (if
<B>/home</B> is a symlink to "/usr/local/home/" -- and
"/usr" is on a separate drive or partition.)</P>
<P>Now I come back to my original question that I first posed at the
beginning of this section. How are the users going to be managed? If you
have decided to do it just on a user by user basis, then add
<B>usrquota</B> to your fstab file. If you are going to do it by group then
add <B>grpquota</B>. If you are going to use a mixture of the two, then add
them both.</P>
<P>Thus, we are now concerned with adding to the fourth field the
following:</P>
<PRE>
/dev/hda3 / ext2 defaults,<B>usrquota,grpquota</B> 1 1
</PRE>
<P>Change as appropriate for your version of fstab. If you are unsure as to
which quota to use, I recommend that you include both in the fstab file,
since it means that should you need to swap, you'll already have it set up.
Now save the file.</P>
<P>OK. The next thing we have to do is to make sure that for whichever
option you chose (i.e. namely <B>usrquota</B> or <B>grpquota</B>), that you
create the necessary file(s) on the root of the partition that you changed
in the fstab file. To do this, enter the following commands (still as user
<B>root</B>)</P>
<PRE>
touch /top/of/partition/quota.user && chmod 600
/top/of/partition/quota.user
touch /top/of/partition/quota.group && chmod 600
/top/of/partition/quota.group
</PRE>
<P>Lastly, you have to ensure that when your system boots up, that quotas
are enabled along with it. For those of you who installed <B>Quota</B> from
an RPM/.DEB, etc should find that they already have a script named
"quota" or something similar in "/etc/init.d/". If you
installed from source however, this might not be the case, which means that
you will have to add the following script into your main init-script AFTER
the mounting of all files in "/etc/fstab" has taken place.</P>
<PRE>
<A HREF="misc/adam/quota.sh.txt">(text version)</A>
#Check quotas
[ -x /usr/sbin/quotacheck ] && {
echo "Checking Quotas (please wait)...
/usr/sbin/quotacheck -avug
echo "Done."
} || {
echo "Checking Quotas FAILED"
}
[ -x /usr/sbin/quotaon ] && {
echo "Initialising Quotas..."
/usr/sbin/quotaon -avug
echo " Done."
} || {
echo "Turning Quotas On: FAILED
}
</PRE>
<P>What the above does, is runs a test on the named file, for the
"-x" flag which means that it is checking to ensure that the file
is executable, before it processes the rest of the script. It checks to see
what quotas are defined (if any), and then goes on to enable them.</P>
<P>Once you have done that, issue:</P>
<PRE>
<B>init 6</B>
</PRE>
<P>And wait for your computer to reboot. <BR><BR><FONT COLOR="red">Caveat Emptor:
If you did have to recompile your kernel, ensure that if you are using LILO
as your boot-loader that you run: <BR><BR>
<B>lilo</B><BR><BR>
BEFORE you reboot so that it knows about your new kernel-image
:-)</FONT></P>
<!-- ========================== -->
<!-- END: Quota: setting quotas -->
<!-- ========================== -->
<HR WIDTH=25%>
<!-- ============================ -->
<!-- BEGIN: Quota: An Example -->
<!-- ============================ -->
<H2><A NAME="Q-an">An Example</A></H2>
<P>Right. We should now have your machine acknowledging the fact that we
are going to use Quota. What we haven't done yet, is the most important
bit, and that is, who or which groups will be using the quota rule.</P>
<P>What I have decided to do, is to use an example if a user, and show you
how you go about setting up a quota limit for him. We shall call the user
<B>lg</B>.
<P>Assuming <B>lg</B> is already on your system, what we must do is,
depending on which format you are using, edit the appropriate file. For the
purposes of this example, I shall do this on a per-user basis (i.e. I shall
be using the <B>usrquota</B> format, although everything I shall explain
here, is exactly the same for the <B>grpquota</B> option, if you have
decided to do that.</P>
<P>The command that we shall be using is called "edquota" What we
must do is edit a quota for user <B>lg</B> by issuing the command:</P>
<PRE>edquota -u lg</PRE>
<P>What this does, is launches an editor, and opens a new quota. If you
haven't set the environment variable EDITOR="/usr/bin/jed" or some
equivalent editor, then this command will not work. To set up this
variable, add this to your "~/.bash_profile"</P>
<PRE>
EDITOR="/usr/bin/jed"
export EDITOR
</PRE>
<P>Change the program as you see fit, i.e. Vi, jed, joe, emacs, etc. Then
to make the changes active, source the file, by typing:</P>
<PRE>source ~/.bash_profile</PRE>
<P>What you should find, is that for user <B>lg</B> you get something
similar to the following:</P>
<PRE>
Quotas for user lg:
/dev/hdb2: blocks in use 0, limits (soft = 0, hard = 0)
inodes in use: 356, limits (soft = 0, hard = 0)
</PRE>
<P>Now your thinking: "err...." :-) Don't worry. It is much more
simpler than it looks.</P>
<P><B>Blocks</B> indicate the total number of blocks that a user has used
on a partition (measured in Kilobytes, KB).</P>
<P><B>Inodes</B> indicate the total number of files that a user has on the
partition. N.B. These values you cannot change.</P>
<P>What we are concerned with, is the bit in brackets, right at the end of
each line. This is the key to setting the entire quota. You'll notice that
there are two options, one for <B>soft</B> and one for <B>hard</B>.
<P><B>Soft limits</B> indicate the maximum amount of space (in Kilobytes)
that <B>lg</B> is allowed to have. It acts as a boundary which when set
along with a <B>grace period</B> informs to user <B>lg</B> that he is
exceeding his limit.</P>
<P>A <B>grace</B> limit is a period of time before the <B>soft</B> limit is
enforced. This can be set from (sec)onds, (min)utes, hour, day, week,
month. This is set by issuing the command:</P>
<PRE>edquota -t</PRE>
<P>You'll see that you should get the following:</P>
<PRE>
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/dev/hdb2: block grace period: 0 days, file grace period: 0 days
</PRE>
<P>Change both values for <B>block</B> and <B>file</B> to whatever you see
fit. I recommend 14 days (2 weeks) for both. But then, I am generous
:-)</P>
<P>A <B>hard</B> limit indicates the maximum amount of space that a user
<I>cannot</I> exceed. This only works when a grace period has been set.</P>
<P>That's all there is to it. Now, you are probably wondering how the hell
you are supposed to assign the same quota to every user on your system.
Well, having just followed the example for <B>lg</B>, what you can do, is
to use user <B>lg</B> as a template, and issue the command:</P>
<PRE>awk -F: '$3 >= 500 {print $1}' /etc/passwd'</PRE>
<P>What this does, is prints a list to the screen of all users who start
with a UID greater than 499 (i.e 500 onwards). If this set of users on the
screen looks OK, then we can use the above, in conjunction with the
<B>edquota</B>, as shown below:</P>
<PRE>edquota -p lg $(awk -F: '$3 > 499 {print $1}' /etc/passwd')</PRE>
<P>This uses the quota we have already enabled for <B>lg</B> as a template
to assign it to the string of users that the awk script produces for
us.</P>
<P>That's all there is to it :-). I have found quota to be an excellent
tool in keeping users at bay. I use it for my non-root account, as it stops
me from going wild in my home directory, and thus forces me to clean it out
once in a while.</P>
<!-- ========================== -->
<!-- END: Quota: An Example -->
<!-- ========================== -->
<HR>
<!-- ======================== -->
<!-- ============================ -->
<!-- BEGIN: Dansguardian -->
<!-- ============================ -->
<H2><A NAME="dansg">A Brief Introduction: DansGuardian</A></H2>
<UL>
<LI><A HREF="#DG-wis">What is DansGuardian?</A></LI>
<LI><A HREF="#DG-ins">Installation</A></LI>
<LI><A HREF="#DG-conf">Configuration</A></LI>
</UL>
<HR WIDTH=25%>
<H2><A NAME="DG-wis">What is DansGuardian?</A></H2>
<P>For those of you who followed my last miniature introduction to the world
of linux proxying for <B>Squid</B> and <B>SquidGuard</B>,
<A HREF="http://www.linuxgazette.com/issue78/adam.html">will remember</A> that
I showed you how you could filter certain webpages that matched a certain
regex. What <B>Dansguardian</B> does. is take the concept of filtering and
stretches it so that you can filter webpages, based on <B>content!!</B>. Also
though, Dansguardian allows you to filter out mime-types and block file
extensions, thus meaning that should your users have the unfortunate punishment
of using an M$-Windows machine, you can block files such as <B>.exe, .com,
.dll, .zip .... etc</B></P>
<!-- ======================================== -->
<HR WIDTH=25%>
<H2><A NAME="DG-ins">Installation</A></H2>
<P>Dansguardian can be obtained from the following:</P>
<A HREF="http://www.dansguardian.org">http://www.dansguardian.org</A>
<P>You can either download an RPM or tar.gz file from his site. If you're a
budding Debian GNU/Linux user, then you can always use the <B>alien</B>
package to convert the RPM file to a DEB file :-). To actually install the
files, follow the <A HREF="#Q-inst">instructions</A> as in the Quota
section.</P>
<P>It is also worth noting, that Dansguardian requires the use of the
<B>nb++</B> library. There is a link to a download site, on the main site
of dansguardian. This library is used to look at the content of webpages,
and is thus essential to the operation of Dansguardian.</P>
<P>On install, dansguardian, main program is installed as
"/usr/sbin/dansguardian". What you must do, is either in
"/etc/init.d/rc.local" OR "/etc/init.d/boot.local"
(depending on which distribution you are using), add:<P>
<PRE>
/usr/sbin/dansguardian
</PRE>
<P>So that Dansguardian is loaded up on init.</P>
<!-- ======================== -->
<HR WIDTH=25%>
<!-- ======================== -->
<!-- BEGIN: DG: Configuration -->
<!-- ======================== -->
<H2><A NAME="DG-conf">Configuration</A></H2>
<P>There really is not <I>too</I> much to configure when it comes to
Dansguardian. What takes all the work, is the various regex expressions
that you may want to build for really accurate content filtering.</P>
<P>It should be pointed out that DansGuardian can be used in conjunction
with <A
HREF="http://www.linuxgazette.com/issue78/adam.html#squidg">SquidGuard</A>
so that you don't have to replace any existing filters that you may already
have in place :-) Good, eh?</P>
<P>So, the first thing we should do, is check where the package has put the
configuration files. Well, it should be no surprise that they have been out
in "/etc/dansguadian", and it is the files contained in this
directory that we shall concentrate on. We shall begin by looking at the
configuration file <B>/etc/dansguardian/dansguardian.conf</B>.</P>
<P>This is all the settings that Dansguardian will require. Typically, the
only options that I have had to change are listed below:</P>
<PRE>
#DansGuardian config file
[Reporting]
reportinglevel = 1 # 0 = just say 'Access Denied'
# 1 = report why but not what denied phrase
# 2 = report fully
[Network Settings]
filterport = 8080 # the port that DansGuardian listens to
proxyip = 127.0.0.1 # loop back address to access squid locally
proxyport = 3128 # the port DansGuardian connects to squid on
accessdeniedaddress = "http://grangedairy.laptop/cgi-bin/dansguardian.pl"
[Logging] # 0 = none 1 = just denied 2 = all text based 3 = all requests
loglevel = 2
[Content Filtering]
bannedphraselist = "/etc/dansguardian/bannedphraselist"
bannedextensionlist = "/etc/dansguardian/bannedextensionlist"
bannedmimetypelist = "/etc/dansguardian/bannedmimetypelist"
exceptionsitelist = "/etc/dansguardian/exceptionsitelist"
exceptioniplist = "/etc/dansguardian/exceptioniplist"
[Phrase Scanning] # 0 = normal 1 = intelligent
scanningmode = 1
# normal does a phrase check on the raw HTML
# intelligent does a normal check as well as removing HTML tags and
# multiple blank spaces, tabs, etc - then does 2nd check
[ ** Many other options elided ** ]
</PRE>
<P>The only things I changed here, was the <B>filterport</B>, the
<B>proxyport</B> and the <B>accessdeniedaddress</B> tags, to reflect the
configurations I used in <B>"/etc/squid.conf"</B>. Having
changed your options accordingly, you can save the file, and ignore it
:-)</P>
<P>OK, moving on. In the same directory, you should notice files with the
following filenames:</P>
<UL>
<LI>bannedphraselist</LI>
<LI>bannedextensionlist</LI>
<LI>bannedmimetypelist</LI>
<LI>exceptionsitelist</LI>
<LI>exceptioniplist</LI>
</UL>
<P>I shall take each file in turn, and explain what each one does. Where
appropriate, I shall list small portions of the file.</P>
<B>bannedphraselist</B>
<P>This file contains explicit words and as such, I shall not list its
contents here. Suffice to say, this is the file that holds keywords which
are blocked if found anywhere in the HTML page.</P>
<P>As you will see, each word is enclosed within < > signs, as
in:</P>
<PRE>< sex ></PRE>
<P>These angled brackets are important, since without them, the word would
not be blocked.</P>
<P>You will also notice, throughout the file that some words have a space
either side of the angle brackets, and some only have one space, either end
of the bracket. This is important, since it says to dansguardian how to
block the word.<P>
<PRE>< sex ></PRE>
<P>Indicates that the word sex (and only the word sex) should be blocked
when it is found, nothing more.</P>
<PRE><sex></PRE>
<P>Indicates that the word sex should be blocked, regardless of where it is
found in a sentence or phrase. I.e. if it is found in
<B>hellosexyhowareyou?</B> then it will be blocked.</P>
<PRE>< sex></PRE>
<P>Means that anything is blocked, to the left of the word.</P>
<PRE><sex ></PRE>
<P>Is the converse of the above.</P>
<P>As you look down the file, you'll see a number of different words which
are being blocked. :-) You will also notice that there a number of comments
of example words or hyphenated phrases which are not blocked, because you
have already blocked part of that word. For example:</P>
<PRE><middlesex></PRE>
<P>Need not be blocked, since the phrase:</P>
<PRE><sex></PRE>
<P>is already blocking any other word that contains the word <B>sex</B>.
That is an important fact to remember of you are going to be adding to the
list at a later date.</P>
<B>bannedextensionlist</B>
<P>Simply contains a list of file extensions that will be blocked by
dansguardian, thus:</P>
<PRE>
#Banned extension list
.gz
.tar
.zip
.mp3
.mpeg
.mpg
.avi
.exe
.sys
.ini
.bat
.doc
.xls
.scr
</PRE>
<P>This is pretty much self explanatory!!</P>
<B>bannedmimetypelist</B>
<PRE>
# banned MIME types
audio/mpeg
audio/x-mpeg
audio/x-pn-realaudio
video/mpeg
video/x-mpeg2
video/acorn-replay
video/quicktime
video/x-msvideo
video/msvideo
application/gzip
application/x-gzip
application/zip
application/compress
application/x-compress
application/java-vm
</PRE>
<P>MIME types are used to identify different multi-media portions of
applications, and as such is particularly useful when sending e-mail,
however MIME has its uses in HTML too :-)</P>
<P>Again, I would add some other options here.</P>
<B>exceptionsitelist</B>
<P>Lists those sites which, are allowed to be viewed, even though it would
ordinarily be blocked by the rules defined in any of the other files,
thus:</P>
<PRE>
#Sites in exception list
#Don't bother with the www. or
#the http://
jadeb.com
</PRE>
<P>You can obviously add more sites as you are going along :-)</P>
<B>exceptioniplist</B>
<PRE>
#IP addresses to ignore and just
#pass straight through.
#
#These would be servers which
#need unfiltered access for
#updates. Also administrator
#workstations which need to
#download programs and check
#out blocked sites should be
#put here.
#
#Only put IP addresses here,
#not host names
192.168.0.1
192.168.0.2
192.168.42.2
#these are examples above
#delete them and put your own
#in if you want
</PRE>
<P>The comments in this, pretty much say all :-). Obviously I would say be
careful as to which machines you allow override access to :-)</P>
<P>And that rather short explanation explains how dansguardian works. You
may well find, as I did, that it is very frustrating at first, since it
really does block what you tell it to, but once you yourself have shoved a
whole load of domain names into the <B>exceptionsitelist</B>, things should
not be too bad at all! :-)</P>
<!-- ===================== -->
<!-- END: DG: ALL SECTIONS -->
<!-- ===================== -->
<HR>
<!-- ========================== -->
<!-- ===================== -->
<!-- BEGIN: Touchrec -->
<!-- ===================== -->
<H2><A NAME="touchrec">Touchrec: Recursively touches files in a
directory</A></H2>
<P>In <A HREF="http://www.linuxgazette.com/issue66/tag/2.html"
TARGET="_blank">issue66</A>, there appeared a thread about how to
recursively touch files in a given directory. Since the GNU
version of touch does not support an option (yet), a few
suggestions were offered using GNU find.</P>
<P>Indeed I was intrigued by this idea. I have often been in a situation
where having a recursive feature to touch all files and/or directories was
a necessity. Such an example is where I had forgotten to add the
"m" flag to the tarball I was un-tarring, and as a result had a
while load of future modification dates on my files (See <A
HREF="../issue79/lg_tips.html#tips/3">
issue79</A>). Deleting the entire directory would have been a pain, since
it took <I>ages</I> to untar. Thus, I decided to write the following
shell-script :-)</P>
<A HREF="misc/adam/touchrec.tar.gz">(tar.gz file)</A>
<P ALIGN="center">-----------------</P>
<PRE>
#!/bin/bash
##########################################################
#touchrec -- Recursively "touches" files in a directory #
#Ackn: Written for TAG (Linux Gazette) :-) #
#Version: Version 1.0 (first draft) #
#Author: Created by Thomas Adam #
#Date: Saturday 15 June 2002, 16:58pm BST #
#Contact: thomas_adam16@yahoo.com #
##########################################################
#Declare Variables
bname=$(basename $0) #Basename of program (path stripped)
curr_dir=$(pwd) #Current dir
dironly=0 #-d off
filesonly=0 #-f off
quiet=0 #-q off
toplevel= #-l off
redir=$(tty) #verbosity redirection tag
version="$bname: Created by Thomas Adam, Saturday 15 June 2002, 16:58pm BST,
Version 1.0"
#Start Procedures
#Help Procedure
help_user()
{
echo "
$bname usage: [-s directory path] [-q] [-d] [-f] [-t] [-h] [-v]
where:
-s (optional starting directory, default is 'pwd')
-q (quiet mode -- suppresses verbosity)
-d (only touch directories)
-f (only touch files)
-t (touches the top-level directory, i.e. '.')
-h (prints this message)
-v (version of program)
Issue command \"man \\1 touchrec\" for full documentation
"
exit 0
}
run_default ()
{
for lists in $(find ${curr_dir} ${toplevel} -depth 2> /dev/null); do
#If it's a directory....
[ -d $lists ] && {
#All directories -- yes
[ $dironly = 0 ] && {
#Just the files? -- continue to the next instance of a loop, if so
[ $filesonly = 1 ] && {
continue
}
echo "touching dir $lists/" >$redir && touch -c $lists
continue
} || [ $dironly = 1 ] && {
#then we are only checking for directories
echo "touching dir $lists/" >$redir && touch -c $lists
}
#This time check for files...
} || [ $dironly = 0 ] && {
[ -f $lists ] && {
[ $filesonly = 1 ] && {
#Only checking for files....
echo "touching files $lists" >$redir && touch -c $lists
continue
} || [ $filesonly = 0 ] && {
#As a result of no flags passed at run-time, this executes :-)
echo "touching files $lists" >$redir && touch -c $lists
}
}
}
done
}
#Main
#Check for presence of command-line switches
if [ "$#" = 0 ]; then
echo "No command-line args given"
curr_dir=$(pwd)
else
while getopts ":hqlfvdts: " opts; do
case $opts in
d )
#Only Check for Directories
dironly=1
;;
q )
#Quiet -- suppresses verbosity to console
quiet=1
redir="/dev/null"
;;
f )
#Only check for files, no directories
filesonly=1
;;
t )
#Only process the top-level directory "."
toplevel="-maxdepth 1"
#echo $toplevel #for debugging purposes
;;
s )
#Get path as specified
#If $optarg is blank, print help_user()
[ $OPTARG = "" ] && {
echo "No Parameter Given"
help_user
} || curr_dir=${OPTARG}
;;
h )
#Print help message
help_user
;;
v )
#Prints the version
echo $version
exit 0
;;
-* | * )
#Any other options -- ignore
help_user
;;
esac
done
fi
#Process optional commands...
shift $(($OPTIND - 1))
#Start main procedure -- once all options processed.
run_default
</PRE>
<P ALIGN="center">-----------------</P>
<P>For those of you who are completely new to BASH programming, please
refer back to Ben Okopnik's excellent tutorial earlier on in the LG series
(<A HREF="http://www.linuxgazette.com/issue52/okopnik2.html"
TARGET="_blank">issue52</A> onwards). For those experienced programmers,
you'll notice that I have used the "[ ..... ] && {} ||"
construct, rather than the more traditional "if..then..else..fi"
method, since the former gives more control with exit status :-), and
I prefer coding like this anyway. Perl also requires this syntax too :-)</P>
<P>The script in itself is quite simple. Basically what happens is that I
initialise all of my variables first. Now, BASH does not require this, but
I find it much easier to know what's going on if I do.</P>
<P>I set up various variables, most of which are just switch identifiers so
that I can tell whether or not any command-line switches (and which ones)
have been issued. I set up another variable <B>bname</B> which returns the
name of the program, with the PATH stripped, which I used in my
<I>help_user()</I> function.</P>
<P>The other variable I defined is the <B>redir</B> variable. This is
initially set to whichever tty you invoke the script from, so that if you
did not specify the "-q" option, you will get messages to your
screen. I think I have been quite clever since, whenever a file/directory
is found, I issue a command thus:</P>
<PRE>echo "touching $lists/" >$redir</PRE>
<P>which, as I say is set to whatever tty you invoked it from.
(/dev/tty1)???. But, if you specified the "-q" flag $redir equals
"/dev/null" so that no messages appear</P>
<P>With regards to command-line switching, I have made good use of the
<B>getopts</B> command. Refer to <B>man 1 touchrec</B> for more information
on that.</P>
<P>I was so taken by this, that I even wrote a manual page :-).
Simply download the tar.gz file, untar it, and run
"install.sh"</P>
<P>For more information about how to use this script, please refer to
"man touchrec". Hope you get good use out of it :-)</P>
<HR>
<!-- ============= -->
<!-- END: Touchrec -->
<!-- ============= -->
<H2><A NAME="gnufind">GNU Find: Evaluating its effectiveness</A></H2>
<P>How many of you have been guilty of using <B>mc</B> (midnight
commander), hitting the key sequence
"<ALT><SHIFT><?>" before, and then filling out
that nice dialog box to find the file that you require?? Don't lie, we've
all done it <B>(Hi Ben :-))</B>. And why? All that dialog box is, is a front
end to the command <B>find(1)</B> anyway. This article will help try and
wean you off pretty command-line dialog boxes. While there is nothing wrong
with using <B>mc's</B> searching feature, it does not give you the full
benefit to do complex searches. GNU <B>find</B> is a very
powerful tool indeed.</P>
<H2>Finding one particular file</H2>
<P>The most common use of find, is knowing where a certain file is. Now,
usually, if it is a binary file, you would most likely either use the
commands <B>which</B> and <B>where</B> to find it :-), but what if you were
looking for that file called <B>etherh.c</B>? You'd issue the command:</P>
<PRE>
cd /
find / -name etherh.c -print 2>/dev/null
</PRE>
<P>Now don't panic :-) The syntax of the find command is thus:</P>
<PRE>find {/path/} [name_of_file/expression] [options...]</PRE>
<P>So, what the command does, is beginning at "/" (the root
directory of the partition), search for the file called <B>etherh.c</B>,
when it finds it, <B>-print</B> it to stdout (and in this case the
<I>2>/dev/null</I> redirects any errors to oblivion. -- used here
because I am not user <B>root</B> I obviously have permission problems
looking at certain files from "/" that I don't care to know
about!)</I>.</P>
<P>The <B>-name</B> flag above has more than just one use as shown here. It
is in fact a flag which allows you to pass shell metacharacters to the
filename that you are trying to look for, and we will discuss that in the
next section.</P>
<P>If you have your kernel sources installed, you should find that the
file, is at:</P>
<PRE>/usr/src/linux/drivers/acorn/net/etherh.c</PRE>
<H2>Finding filenames using shell metacharacters</H2>
<P>It is all very well, knowing the exact name of the file that you trying
to search for. That makes life easier. But what if you didn't know the
exact name of the file, what then?</P>
<P>Well, in that situation, you would obviously have to use wildcards, or
more specifically shell metacharacters. These are characters such as:</P>
<PRE>
*
?
[]
{} -- [ although these have their uses as we shall see later on ]
</PRE>
<P>Quite simply then, we can try something like the following:</P>
<PRE>
find /usr/bin -name 'xa*' -print
</PRE>
<P>Which should return:</P>
<PRE>
/usr/bin/xargs
</PRE>
<P>The sharp eyed among you will have noticed that I
<H2>Find involving actions</H2>
<P>You can also tell find to run a program on the file(s) that it finds
too. This is an extremely useful feature, and you will be surprised at just
how often you will have cause to use it.</P>
<P>Suppose you have a bunch of files, say in $HOME, and I wanted to look
for a regular expression in each of them, i.e. "#!/bin/bash". I can do the
following:</P>
<PRE>
find $HOME -name '*' -print -depth -exec egrep -n '#!/bin/bash' {} \;
</PRE>
<P>The syntax of the last part, may seem strange, but what is happening is
that the flag <PRE>-exec</PRE> accepts first the command, and then any
addition options (in this case, a regular expression), followed by two
brackets {} which when run, will be expanded to the current filename which
is returned by the find parameter (be it a regular expression or specific
filename -- in this case all files (*). The backslash (\;) terminates the
command.</P>
<P>Therefore, in short, the syntax is:
<PRE>
find -path -name {pattern/regex} -exec {name_of_program} [options] {} \;
</PRE>
<P>You can then apply this principle to use any command that you can see a
use for :-)</P>
<H2>Finding particular types</H2>
<P>Once again, find makes our life even easier, by allowing us to look for
specific file types. Now, while you might well think that you could use a
combination of <PRE>ls, test, find</PRE> to do the same thing, <B>don't
re-invent the wheel</B> :-). Here are some examples:</P>
<PRE>find / -name '*' -print -depth -type d</PRE>
<P>-- which prints only directories</P>
<PRE>find / -name '*' -print -depth -type f</PRE>
<P>-- which finds only files</P>
<PRE>find / -name '*' -print -depth -type l</PRE>
<P>-- finds symbolic links only</P>
<P>If you only want to search say, on the top-level directory, and not
traverse any lower, then you can use the:</P>
<PRE>-maxdepth {number}</PRE>
<P>switch. For example, if you only wanted to search for directories which
is in your $(pwd) -- (current working directory) you can do:</P>
<PRE>
find / -name '*' -type d -maxdepth 1 -print
</PRE>
<P>Which on my computer (laptop) returns the following:</P>
<PRE>
/
/lost+found
/boot
/proc
/var
/tmp
/etc
/sbin
/bin
/lib
/root
/usr
/cdrom
/floppy
/home
/mnt
/opt
/dev
/chess
/pavement
</PRE>
<P>The number indicates the number of subdirectories that you wish to
descend during your search.</P>
<P>But the fun doesn't stop just with this mini-article. <B>find</B> has a
whole host of other options many of which I cannot ever see the need
for, but that's only because I have a limited use for it.....</P>
<P>Definitely check out the command:</P>
<B>man find</B>
<HR>
<!-- ========================== -->
<A NAME="intjf"><H2>Interview: John M. Fisk</H2></A>
<I>[ Yep! It is the same John Fisk that started off this magazine, and
thie Weekend Mechanic series. I was <B>really</B> pleased when John sent me an
e-mail out of the blue saying he had read my article :-) So, I post a
transcript of our conversation here -- Thomas Adam ]</I>
<BR><BR>
<I><FONT COLOR="blue"><B>[John]</B></FONT></I>: <PRE><B>Dear Thomas,
I want to say thanks for keeping up the "Weekend Mechanic" column in the
LG. I have to admit that I've had little time for pleasure reading (and
much less for writing) these past several years. On a whim, I started
reading the latest LG (after seeing an announcement for it on the lwn.net
site) and noticed the WM column was still there. I'm absolutely delighted
that you're keeping it going and wish you the very best.
Trust your end-of-semester exams go well. Have a great summer 'linuxing.
cheers,
John
p.s., kudos for providing "install from source" instructions for squid. I
suppose that a growing number of users are simply dependent on rpm or deb
binaries (and there are good reasons for using these) but I still tend to
"roll my own" from source and make a package out of it when I'm not feeling
so lazy :-)
</B></PRE>
<I>[Thomas]</I>
<PRE>Hello. I must say that I feel *very* honoured to have
received an e-mail from you -- especially as you
founded the Linux Gazette :-) You have no idea just
how much I valued your efforts way back in 1996. Had
you any idea that the LG would be as popular as it is
now?
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
Absolutely not. I started getting interested in Unix/Linux during the
summer of 1994. I had just switched from being a general surgery resident
at a very busy tertiary care hospital to working as a research assistant in
the lab of one of the hepatobiliary surgeons. I managed to get a dial-up
account on the universities VAX machine (2400 baud :-) and started using
gopher. Somehow, I ran across information on Linux and decided to give it
a try since I was interested in doing a medical informatics fellowship.
It took countless days to download the installation floppy set from TAMU
(Texas A&M Univ.). I had a 2 MB limit on my shell account so I would ftp
an image to the account and then turn around and transfer it to my local
box via kermit. TAMU was the first distribution I ever tried. Almost
immediately, I decided to give Slackware a try -- it was the "new kid on
the block" and was supposed to be so much better than SLS. That was
August, 1994.
After playing with Linux for a year or so I decided that I wanted to learn
how to write HTML and so the Linux Gazette was born out of similar
"itches": learning Linux and learning HTML. I absolutely loved Linux, and
do so to this day, so it was easy to come up with content. I just wrote
about the things I loved and found exciting. I had no earthly notion that
it would be that popular. I had a good deal more time on my hands back
then and so I was able to do almost everything -- write columns, coordinate
inclusions by others, format the entire batch so that the HTML was at least
reasonably "legal", etc.
About a year later (issue 8) I was in over my head and was now back in
school full time working on a computer science degree (actually, I was a
non-degree seeking graduate student, but I took the entire computer science
curriculum and enough math courses for a math minor). Phil Hughes from the
Linux Journal got in touch with me. He was interested in an online
magazine of this type and offered to take over the administrative
work. So, I was terribly relieved to turn the reins over to him and
continue writing.
</B></PRE>
<I>[Thomas]</I>:
<PRE>
I started reviving your article several months ago.
Although I started submitting articles once a
month, they have been more intermittent of late, due
to University work getting in the way :-(
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
Brother, I know that feeling... :-)
</B></PRE>
<I>[Thomas]:</I>
<PRE>
Incidentally, I hope you didn't mind me, re-using your
article name, and images. I had tried to get in
contact with you, to ask your permission, but it seems
that you don't mind :-)
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
Not in the least. I'm absolutely delighted that you've done this and wish
you the very best.
</B></PRE>
<I>[Thomas]:</I>
<PRE>
If time permits, you should start reading the LG. It
would be nice, if you could send an e-mail to the
editor :-) Just to say, hi. I'm sure that'll cause
quite a stir.....especially with Jim Dennis :-)
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
I'll do that.
</B></PRE>
<I>[Thomas]:</I>
<PRE>
What are you doing these days??? Your last ever
article said that you'd finished your degree
(congratulations) and was going to work for a medical
centre?? Is this still the case?? How is your wife??
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
At the moment, I'm within a couple years of finally finishing up my medical
training! I went on to do a brief medical informatics fellowship under
Drs. Randolph Miller and William Stead at the Vanderbilt University Medical
Center and then decided to finish my formal medical training in
Pathology. I matched at Yale (here in New Haven, Connecticut) and have
completed 2 years of Anatomic Pathology training. This year, I was able to
take a year off to do some medical informatics research with Dr. Prakash
Nadkarni. We've just finished writing our first paper (in information
retrieval) and I'm working on two additional projects. I start back "on
the wards" as a Clinical Pathology (AKA, Laboratory Medicine) resident on
July 1.
Life has gotten a rather busy of late. My wife and I adopted a little girl
from China in August, 2000. She's a cutie pie, but definitely takes a good
deal of what little "free time" we had left :-). Any more, I try to keep
up with things in the Linux Community but I've had no time to write.
What distribution are you using?
</B></PRE>
<I>[Thomas]</I>:
<PRE>
I'm using SuSE 7.1, soon to switch back to using <B>Debian</B>
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
I'm still using Slackware :-). You mentioned that you've been using Linux
for around six years. That's long enough that you've probably given a
number of distributions a whirl. I have to say that I really like
Mandrake, and I've run Debian for short time. Eventually, however,
managing the *.deb's and *.rpm's becomes a headache and I start fighting
with the package manager. In time, I just get disgusted and go back to
Slackware. It's stable, Patrick V. does a nice job of keeping current
without pushing too far toward the bleeding edge. And I still compile
nearly everything from scratch.
</B></PRE>
<I>[Thomas]</I>:
<PRE>
Thanks again John :-)
Keep in touch,
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>:
<PRE><B>
You too. Best wishes,
John
--
John M. Fisk, M.D.
Postdoctoral Research Associate, The Yale Center for Medical Informatics
Yale University School of Medicine, 333 Cedar Street, PO Box 208009, New
Haven, CT 06520-8009
email: John.Fisk@yale.edu
phone: (203) 764-8132
</B></PRE>
<!-- ========================== -->
<!-- =================== -->
<!-- BEGIN: closing time -->
<!-- =================== -->
<HR>
<H2><A NAME="closet">Closing Time</A></H2>
<P></P>
<P>Oh well, until next month -- take care.</P>
<!-- ==================== -->
<!-- END: closet -->
<!-- ==================== -->
<HR>
<!-- ** Begin table comments, etc. Oh wakey wakey you idiot Thomas ** -->
<TABLE width="60%" align=center border=0>
<TBODY>
<TR>
<TH></TH>
<TH></TH>
<TH></TH>
<TR>
<TD width="10%"><IMG height=64 alt="" src="../gx/adam/mail.png"
width=64 align=left></TD>
<TD align=middle width="80%"><FONT color=red size=5>Send Your
Comments</FONT></TD>
<TD width="10%"><IMG height=64 alt="" src="../gx/adam/mail.png"
width=64 align=left></TD></TR></TBODY></TABLE>
<P align=center><FONT size=3>Any comments, suggestions, ideas, etc can be mailed
to me by clicking the e-mail address link below:</FONT></P>
<P align=center><FONT size=3><A
href="mailto:thomas_adam16@yahoo.com">mailto:thomas_adam16@yahoo.com</A></FONT></P>
<HR>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Thomas Adam</H4>
<EM>My name is Thomas Adam. I am 18, and am currently studying for A-Levels
(=university entrance exam). I live
on a small farm, in the county of Dorset in England. I am a massive Linux
enthusiast, and help with linux proxy issues while I am at school. I have been
using Linux now for about six years. When not using Linux, I play the piano,
and enjoy walking and cycling.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Thomas Adam.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Introduction to Programming Ada</font></H1>
<H4>By <a href="mailto:thomas_adam16@yahoo.com">Thomas Adam</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<H2>Introduction</H2>
<P>I'm quite old-fashioned when it comes to computers. I am one of these
people whom prefers working at a command-line driven interface rather than
a GUI. So it should not come as a shock to you that many of the
programming languages I have experimented in are also based on <I>textual
</I> input / output. <B>Ada</B>, along with <B>Perl, Bash, Sed, Awk,
C</B>, etc is no such exception.</P>
<P>Over the years, there have been quite a few programming languages
mentioned in the <I>Linux Gazette</I>. Ben Okopnik has done two
<B><I>very</I></B> good tutorials on both <B>Perl</B> and <B>Bash</B>,
and other people have contributed to describing other languages, such as:
<B>Smalltalk, C++, Python</B>. Over the next couple of months, I shall
be writing a series of articles to do with programming in Ada.</P>
<H2>What is Ada?</H2>
<P>Glad you asked :-) Originally <B>Ada</B> was a US governmental (DoD)
developed programming language. The standard was originally known as
Ada83, but this is now obsolete, as it was recently "overhauled"
and re-born as <B>Ada95</B>. This is now the preferred standard and
implementation of the Ada programming language.</P>
<P>In 1983, Ada was standardised by ANSI. Thus, it went through all the
official motions and in that year, that first edition was released. Then
four years later in 1987, ISO released an equivalent standard. At this
time though, the idea of so called OOP (Object-Orientated Programming) was
a concept that had not really been considered.</P>
<P>Ada however, was not designed by a committee. The original design was
implemented by Jean Ichbiah, who won a language design competition. Then
in 1995, Tucker Taft led a small group of developers and Ada95 was born.
Unlike the previous version (Ada83), the implementation of Ada95 (or
Ada9X, as it is sometimes known) underwent a public "benchmark"
test; whereby testers of the language gave their feedback, and suggestions
to make the syntactical and lexicographical layout more efficient.</P>
<P>The name <B>Ada</B> is attributed to a woman called <B>Ada Loveless</B>
(1815-1852) who is considered to be the world's first programmer. Ada
is used in all sorts of situations, and since it is a <B>concurrent</B>
programming language, it is most commonly used in <B>embedded systems</B>.
Ada has been used in some of the following:</P>
<UL>
<LI>Airplanes</LI>
<LI>Air Traffic Control systems</LI>
<LI>Financial Systems</LI>
<LI>Telecommunications Systems</LI>
<LI>Medical Devices</LI>
</UL>
<P>The list however is by no means exhaustive :-)</P>
<H2>Ada Compilers</H2>
<P>Unlike other scripting programming languages (Perl, Bash, Python, tcsh,
etc), Ada like C is compiled rather than interpreted. This means that
the person that is going to run the program does not need the
interpreter installed to use it. Ada programs are therefore standalone
from having any kind of Ada packages installed. <I>[Unless you have used
pragmas to interface with other languages, like C, in which case you might
have libraries, but more on that later -- TA]</I></P>
<P>The Ada compiler that I recommend to you is called <B>GNAT</B>, which
stands for: <B>GNU</B> <B>NYU</B> (New York University) <B>A</B>da
<B>T</B>ranslator. It is free (GNU license :-), and there is a wealth of
information on it. It is based on the <B>gcc</B> compiler, which has had
the Ada syntax bundled in with it.</P>
<P>It is available from the following website, which then has a link to
the GNAT compiler:</P>
<A HREF="http://www.gnuada.org/alt.html"
TARGET="_blank">www.gnuada.org/alt.html</A>
<P>A word of caution here. I recommend that you download a pre-compiled
binary version of GNAT, and use the package <B>alien</B> if need be to
convert to .DEB .RPM .TGZ, etc. The reason I say this, is because you will
need an Ada version of <B>gcc</B> (often called <B>gnatcc</B>) to bootstrap
the compiler. If this is the first time you are installing GNAT then the
compilation from source code will not be possible.</P>
<P>That said, you can then go ahead and install the package once you have
downloaded it. You'll find that with the RPM version of GNAT, that there
should be one single RPM: "GNAT-3.13p-7.rpm" which will contain
everything you need to start programming in this wonderful language
:-).</P>
<H2>Ada IDE's</H2>
<P>Before we start our first program in Ada, I thought it would be good to
make you aware of some of the IDE's (<B>I</B>ntegrated <B>D</B>evelopment
<B>E</B>nvironment). These are programs which help you to program in the
specified language by offering features such as: </P>
<UL>
<LI>Syntax Highlightling</LI>
<LI>Compiler Support</LI>
<LI>Keyword Definitions</LI>
<LI>Pre-defined Templates</LI>
</UL>
<P>The two that I would recommend to you are:-</P>
<P><B>TIA</B> (TIny Ada) -- a console based IDE written in Ada and is built
around the use of GNAT</P>
<P><B>GRASP</B> -- an X11 IDE which supports among other languages,
Ada!</P>
<P>For all you EMACS fans, there is an extension called <B>Glade</B> which
is installed as part of the main GNAT distribution. This is an EMACS
extension which supports the GNAT compiler, syntax highlighting, etc. More
information on that can be found at <A
HREF="http://www.gnuada.org">gnuada</A> website</P>
<P>You do not have to use and IDE at all to be able to use GNAT.
I actually don't bother, and instead use <B>jed</B> if I am at the
console (although this does not yet support Ada syntax highlighting) and
<A
HREF="http://www.linuxgazette.com/issue79/adam.html#prognedit"
TARGET="_blank"><B>Nedit</B></A> if I am in X11. This <I>does</I> support
Ada syntax highlighting :-)</P>
<H2>The Features of Ada</H2>
<P>Ada95 has been greately enhanced over its predecesor Ada83. The biggest
improvement has been <B>object orientation</B>, which many people will
find useful. Some of the features that Ada has are:</P>
<UL>
<LI>Packages (Modules), related types, objects can all be defined</LI>
<LI>Packages and data types can be made generic</LI>
<LI>Data representation gives a means to support systems
programming</LI>
<LI>Object-orientated programming is supported</LI>
<LI>Errors can be caught and delt with explicitly</LI>
<LI>Tasks (multiple paralell threads) can be created and used. This
ability is inherent to Ada95 and is uncommon is most other
langugaes</LI>
<LI>Interfaces to other languages (such as: C, Fortran, COLBOL) can be
included in the language</LI>
<LI>Ada supports hard <B>types</B> of data, both for textual and
mathematical Input/Output. As a result, Ada is well suited to writing
and maintaining complex systems</LI>
</UL>
<P>In addition to the above, there are also:</P>
<UL>
<LI>Packages</LI>
<LI>Functions</LI>
<LI>Procedures</LI>
<LI>Task Units</LI>
<LI>Records</LI>
<LI>Arrays</LI>
</UL>
<P>And many more....</P>
<H2>Hello World!</H2>
<P>Now it's time to write our first ada program. In time-honoured
tradition, we are going to start by writing a <I>Hello World</I>
example. Open up a text editor, and type in the following:</P>
<TABLE BORDER="1">
<TBODY>
<TR COLSPAN="12">
<TD>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">use</FONT> text_io;
<FONT COLOR="red">procedure</FONT> hello_world <FONT COLOR="red">is </FONT>
<FONT COLOR="red">begin</FONT>
<FONT COLOR="red"> put</FONT>("Hello World!");
<FONT COLOR="red">end</FONT> hello_world;
</PRE>
</TD>
</TR>
</TBODY>
</TABLE>
<P>Easy, isn't it :-). Before we can run the program, we have to save it.
But it has to be with the correct suffix. GNU/Linux doesn't require any
suffix (file extension) as a rule, but it is <B>essential</B> when
programming in <B>Ada</B> and using the GNAT compiler. A list of valid
extensions are:</P>
<UL>
<LI>.ads - Ada package specification</LI>
<LI>.adb - Ada package body or program</LI>
</UL>
<P>When writing anything other than a package (which we won't be doing for
<I>some</I> time yet -- I can assure you) :-) you should append a
".adb" extension to your filename. This is so that the compiler
knows that the file it is compiling is a program and not a package
specification!</P>
<P>So, save your file as <B>hello_world.adb</B>
<P>Now we are ready to start to compile / build the program. This has to
be done so that we can run it. You cannot run an Ada program until it has
been compiled and built.</P>
<P>Change to the directory that you have just saved the file, and issue
the command:</P>
<PRE>
gnatmake hello_world.adb
</PRE>
<P>This will compile -> link -> build your Ada code into a compiled
program.</P>
<P>Now if you type in:</P>
<PRE>
./hello_world
</PRE>
<P>the response:</P>
<PRE><B>hello world!</B></PRE>
<P>is output to the screen, and the program exits.</P>
<P>You should also have noticed that as you issued the command, the following
output was produced:</P>
<PRE>
gnatgcc -c hello_world.adb
gnatbind -x hello_world.ali
gnatlink hello_world.ali
</PRE>
<P>You could, if you wish, type each of the above commands in turn to both
<B>compile, bind and link</B> your program (respectively). Luckily
<B>gnatmake</B> provides a nice automation for this :-). If you now look
in your directory, along with the main program, you'll find that GNAT has
created other files too, namely:</P>
<UL>
<LI>hello_world.ali</LI>
<LI>hello_world.o</LI>
</UL>
<P><B>.ali</B> files are GNAT link files that contain information about
debugging and linking for the main program</P>
<P><B>.o</B> files are object files which can be used in conjunction with
the program-debugger: <B>gdb</B>.</P>
<P> In short, unless you plan to debug your program, you can delete these files.</P>
<H2>Explanation: Hello World</H2>
<P>In perl, you can issue a command such as: <B>print("Hello");</B> and
that can be the <B><I>only</I></B> line in your program (excluding the
she-bang line), and it will run.</P>
<P>Ada however, has to be told exactly which packages it is to use before
it can perform even the simplest of commands like echoing statements to
the VDU. A <B>package</B> is a collection of functions and procedures that
perform specific tasks. If you do not declare explicitly these at the
start of the program, GNAT, when it comes to compile your program, will
bomb out immediately.</P>
<P>Therefore, if we wish to read and write I/O (Input/Output) to a screen
terminal, this has to be stated. All I/O functions are found within the
package <B>text_io</B>, and the first two lines within our hello_world
example are crucial....</P>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">use</FONT> text_io;
</PRE>
<P>The <FONT COLOR="red">with</FONT> statement in Ada indicates that we
will be requiring the use of the named package, in this case
<B>text_io</B>. If more than one package is required then this can be
added, by separating each package name by a comma (,). When we have
finished, we must append a semi-colon (;) to the end of the line, similiar
to that of Perl. The <FONT COLOR="red">with</FONT> statement is a
mandatory command that must <B>ALWAYS</B> be present at the start of your
program in order for it to work.</P>
<P>The package <B>text_io</B>, as I have already stated allows I/O
functions / procedures. This involves printing messages to the screen,
allowing user input to be entered, etc. It is a package that is used in
virtually every program you will ever write in Ada.</P>
<P>The <FONT COLOR="red">use</FONT> statement MUST be used only after the <FONT
COLOR="red">with</FONT> statement has been made. It allows for unqualified
references to be made to procedures and functions from other packages.
Without the use of this statement, each procedure or function call must
have the name of the package that it belongs to, followed by a period
(full stop) preceeding it. For example, below is what the
<B>hello_world</B> program would look like <B>without</B> the <FONT
COLOR="red">use</FONT> statement.</P>
<TABLE BORDER="1">
<TBODY>
<TR COLSPAN="12">
<TD>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">procedure</FONT> hello_world <FONT COLOR="red">is </FONT>
<FONT COLOR="red">begin</FONT>
<FONT COLOR="red"> text_io.put</FONT>("Hello World!");
<FONT COLOR="red">end</FONT> hello_world;
</PRE>
</TD>
</TR>
</TBODY>
</TABLE>
<P>You can see how this has increased the amount of information that we
have to type in, without the use of the <FONT COLOR="red">use</FONT>
statement. When more than one package is used that might have the same
procedure or function names, the compiler can usually tell to which
package you are referring, based on the parameters passed to it.</P>
<P>The third line:</P>
<PRE>
<FONT COLOR="red">procedure</FONT> hello_world <FONT COLOR="red">is </FONT>
</PRE>
<P>declares that we are writing a new procedure with the name
<B>hello_world</B>. The statement word <FONT COLOR="red">is</FONT> tells
us that we are about to start the declarative section of the procedure,
more on that later.</P>
<P>The keyword <BR><BR>
<FONT COLOR="red">begin</FONT><BR><BR> then tells us that we are going to
start the executable part of the procedure -- i.e. where all the
statements will appear and be executed, which in this case is:</P>
<PRE>
<FONT COLOR="red">put</FONT>("Hello World!")</FONT>
</PRE>
<P>Which calls the procedure <FONT COLOR="red">put</FONT> from the package
<B>text_io</B> to print the message <B>Hello World!</B> on the screen.</P>
<P>The last line:</P>
<PRE>
<FONT COLOR="red">end</FONT> hello_world;
</PRE>
<P>simply just ends the named procedure.</P>
<P>In short, the basic structure for an Ada program looks like the
following:</P>
<TABLE BORDER="1">
<TBODY>
<TR COLSPAN="12">
<TD>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">use</FONT> text_io;
<FONT COLOR="red">procedure</FONT> program_name <FONT COLOR="red">is </FONT>
[ declaritive part here ]
<FONT COLOR="red">begin</FONT>
[ executable section here ]
<FONT COLOR="red">end</FONT> program_name;
</PRE>
</TD>
</TR>
</TBODY>
</TABLE>
<P>Also within the package <B>text_io</B> are commands such as:</P>
<PRE><FONT COLOR="red">
put
put_line
get
get_line
new_line
</FONT></PRE>
<P>Plus many others...</P>
<P>
<FONT COLOR="red">put</FONT> does what we have already seen.<BR>
<FONT COLOR="red">put_line</FONT> does the same as <FONT
COLOR="red">put</FONT>, except starts on a new line.<BR>
<FONT COLOR="red">new_line</FONT> is a command issued on its own, which
starts a new line. If you use it, make sure that you put a semicolon at the
end of it, like:<BR><BR>
<FONT COLOR="red">new_line;</FONT><BR><BR>
In fact, that statement about the
semicolon (;) goes for each command that you make in Ada.
</P>
<P>Next month, we will be looking at:</P>
<UL>
<LI>text_io (inputting data via the <FONT COLOR="red">get</FONT>
statement)</LI>
<LI>data types</LI>
<LI>simple arithmetic expressions</LI>
<LI>enumeration types</LI>
</UL>
<H2>Exercises</H2>
<P>Well, that is all for this month. I'm sorry if it seems like I'm not
explaining enough things all in one go, but trying to explain anything
more at this point, is I think overload. So, I am going to leave you with
a few exercises for you to try.....</P>
<P>1. Print your name on the screen</P>
<P>2. Print your address on the screen, using only <FONT
COLOR="red">put</FONT> and <FONT COLOR="red">new_line</FONT></P>
<P>3. Repeat exercise 2, this time with <FONT COLOR="red">put_line</FONT>
<P>If you submit them to me, I will print them in my next installment of
this article!</P>
<P>As with all of my articles, if you have any questions, suggestions,
rants or raves (hopefully not complaints :-) drop me a line!!</P>
<HR WIDTH=25%>
<PRE>
with text_io, ada.integer_text_io;
use text_io, ada.integer_text_io;
procedure happy_programming is
loop_number : integer :=0;
begin
while loop_number /= 10 loop
loop_number := loop_number + 1;
put("Happy Programming in Ada");
new_line;
end loop;
end happy_programming;
</PRE>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Thomas Adam</H4>
<EM>My name is Thomas Adam. I am 18, and am currently studying for A-Levels
(=university entrance exam). I live
on a small farm, in the county of Dorset in England. I am a massive Linux
enthusiast, and help with linux proxy issues while I am at school. I have been
using Linux now for about six years. When not using Linux, I play the piano,
and enjoy walking and cycling.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Thomas Adam.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Office Linux: Ideas for a Desktop Distribution</font></H1>
<H4>By <a href="mailto:marndt@asmsoftware.de">Matthias Arndt</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h3>Introduction</h3>
<p>
I remember one of the meetings of my LUG a few weeks ago. We argued about Linux and
its readiness for the desktop.
We all had the same opinion that Linux is ready for the desktop, at least where software
is concerned. We discussed other related things but this is the thing that made me think about distributions.
<p>
In this article I want to propose to create a special desktop distribution for end users
especially those who sit and work in an office all day long like secretaries.
<h3>Why another distribution of GNU/Linux?</h3>
<p>
To summarize my thoughts:
<ul>
<li>Most current Linux distributions like <a href="http://www.suse.com/">SuSE</a>,
<a href="http://www.debian.org/">Debian</a> or <a href="http://www.redhat.com/">Red Hat</a> come
with huge amounts of available software. This has many advantages but many new users are confused
with this. They ask: <em>I want to do .... . I installed lots of software from CD but which one
should I use?</em> So why not only install one package that fits well for the required work?
<li>A distribution for offices and end user use should be easy to install and easy to administrate.
The people shall work with the computer not fix bugs and tweak configurations.
<li>A distribution consisting of a few but proven components might be much easier to promote its use.
</ul>
<h3>Office Linux Manifest</h3>
<p>
<em>Office Linux</em> should not be one of the bloated 6 CDs full of programs distributions but
a simple distribution that fits on one CD and that brings all needed applications and tools to
create a productivity environment using GNU/Linux.
<p>
<em>Office Linux</em> should
<ul>
<li>run on standard PC hardware as found in offices
<li>be easy to use
<li>be easy to install
<li>consist only of selected applications and environments
<li>fit on one CD
<li>be easy to upgrade
<li>be designed for a workstation setup - not a single server application should be included
<li>bring along optional development packages to allow users to compile software
<li>have a nice and comfortable standard look'n'feel compatible to M$ Windows ™ so
that the intended end user audience feels at home
<li>come with all applications and tools needed for office work such as word processors, spreadsheets
file viewers and printing utilities
<li>be easy to network to Linux and M$ servers
<li>be easy to administrate from remote locations
<li>bring standard compliant Internet software such as <a href="http://www.mozilla.org/">Mozilla</a>
<li>allow network install for disk-less workstations
</ul>
<p>
<em>Office Linux</em> could consist only of free software but this is not a requirement.
<h3>The bare system</h3>
<p>
<em>Office Linux</em> should only come with a proven and stable version of the
<a href="http://www.kernel.org/">Linux kernel</a>. The kernel should be compiled to run on standard
hardware out of the box supporting typically office hardware as networking and printing.
Multimedia support would be nice but not required.
<p>
The standard set of <a href="http://www.gnu.org/">GNU tools</a> like Bash, sed, awk and find should
come with <em>Office Linux</em>. However <em>Office Linux</em> should not present the user or admin with
a huge list of tools to be installed. Installing a standard subset should be enough.
<p>
As <em>Office Linux</em> puts emphasize on secretaries and other office personnel it should not come
with much applications for the console. One or two proven editors should be enough.
<h3>Desktop environment</h3>
<p>
<em>Office Linux</em> should be easy to use. Therefor a proven stable and possibly fast desktop environment
is required. <a href="http://www.kde.org/">The K Desktop Environment</a> could fit to meet this. However it
is not the fastest possible solution.
<p>
<table width="100%">
<tr><td>Pro KDE</td><td>Contra KDE</td></tr>
<tr valign="top">
<td>
<!-- Pro KDE -->
<ul>
<li>easy to use
<li>known and well supported in the GNU/Linux community
<li>can be configured to feel like M$ Windows ™
<li>Desktop environment with file manager and panel
<li>easy to configure by the end user
<li>comes fully internationalized
</ul>
</td>
<td>
<!-- Contra KDE -->
<ul>
<li>needs a considerable time to launch
<li>huge memory footprint both in RAM and on hard-disk
</ul>
</td>
</tr>
</table>
<p>
Personally I do not like KDE that much but I recommend it for <em>Office Linux</em>.
<h3>Office productivity</h3>
<p>
This is a very important field and <em>Office Linux</em> should concentrate on this
field as its name suggests.
A reliable and commonly accepted office suite like Star Office or OpenOffice should
come with it.
<p>
Compatibility with M$ Office ™ is required to allow the intended user audience to import and reuse
their old files. This compatibility should be achieved through the office suite and not through
external tools. Not only to provide GUI but to make it more easy to use.
A worst case scenario may invoke a GUI shell for command line tools.
<p>
I do not recommend KOffice for <em>Office Linux</em> just because it will find more
resistance from the intended audience than suites that resemble M$ Office ™.
<p>
The distribution should provide reliable PDF readers and converters. Perhaps an installable PDF
printer for <em>Office Linux</em> would be a nice idea. Users could print PDFs from any application
then.
<p>
The printing subsystem should be able to communicate with existing network printers of any kind
including SAMBA printers and standard Unix printers.
The subsystem should be easy to install and use. It should be compatible with Unix convention in resembling
the BSD printing system. CUPS would be a fine solution and I suggest using it in <em>Office Linux</em>
<h3>Internet</h3>
<p>
A standard compliant Internet suite is another main part of <em>Office Linux</em>.
<p>
Although there a many fine programs out there <em>Office Linux</em> should only provide on of them
in a preconfigured and working way. A stable <a href="http://www.mozilla.org/">Mozilla</a> release
in a complete install with all needed plugins such as Macromedia Flash and a Java VM.
<p>
A security tweaked default configuration should be included.
<h3>Help System</h3>
<p>
To be easy to use <em>Office Linux</em> has to include a help system that is easy to use and navigate.
<p>
The help system should provide
<ul>
<li>a general tutorial for new users
<li>tutorial / help system for the desktop environment
<li>access to software documentation
<li>a wizard for application selection depending upon the task the user wants to accomplish
<li>general introductions to Unix concepts
<li>HOWTOs on Internet security
<li>wizards to install default configurations for main applications like the office suite or the
Internet software
</ul>
<p>
Markup in HTML is recommended for the Help System.
<h3>Conclusion</h3>
<p>
I think the creation of a distribution upon these ideas is entirely possible. It will require some work
and patience but it shouldn't be impossible.
<p>
A distribution providing only a few but proven components might be as easy to use as M$ Windows ™.
And then GNU/Linux might be ready for the desktop. It is a matter of time, hard work and patience but it
is possible.
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Matthias Arndt</H4>
<EM>I'm a Linux enthusiast from northern Germany.
I like plain old fifties rock'n'roll music, writing
stories and publishing in the Linux Gazette, of course.
Currently I'm studying computer science in conjunction with
economics.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Matthias Arndt.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Playing DVDs on Linux</font></H1>
<H4>By <a href="mailto:oladokun@consultant.com">Tunji Durodola</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" VLINK="#0000ff">
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Hello
dear readers.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">My
name is Tunji Durodola and I write from Nigeria, West Africa, the
largest collection of black peoples on the face of the planet.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
purpose of this article is to give an insight into how to get Linux
to play DVDs using one or more of the now readily available tools on
the web. You should have basic DVD playing in a matter of minutes;
are more detailed section will follow later. </FONT>
</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Preamble.</B></FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
key to watching DVDs lies in the ability of hardware or software to
decode and read encrypted movies. DVDs are encrypted with a special
algorithm called Content Scrambling System or CSS, to prevent illegal
copying of the material contained on the disc. The algorithm is not a
secret, but to get a copy of it to put in your device (hardware or
software), you have to pay a license fee <STRONG>plus</STRONG> sign a mean set of
agreements to prevent you from disclosing the algorithm to anyone.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Each
DVD has its own key, rather akin to each door having a separate key
to unlock it. The key itself in Windows is kept secret.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">All
commercial Windows DVD players have the algorithm contained in it,
but they have paid, and as such, charge for their software, or the
cost is embedded in the price of the DVD drive your purchase, so in
effect you are paying a fee for the “bundled” software
player.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
whole philosophy of Linux is <STRONG>freedom</STRONG>, which would be defeated if you
have to pay for a Linux DVD player. Some chaps tried to get the
algorithm from the owners, but were told they had to go through the
same process as the Windows people.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">For
those earthlings who haven't got a clue as to what DeCSS is, I'll
give a brief summary.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">A
young lad, a few years ago, desiring to watch <STRONG>his</STRONG>
legally purchased DVDs in Linux, thought to develop a player for
Linux, when none existed at the time, stumbled on a flaw in a now
defunct Windows’ player called Xing, which had the unfortunate
habit of leaving the key in the program itself. He then used his
knowledge of maths to reverse-engineer the code and generate the
algorithm.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
software he wrote to do that job was called DeCSS. He then teamed up
with a few friends collectively called Masters Of Reverse Engineering
(MORE) to develop a DVD ripper on Windows, and a small set of
Linux-based utilities to view the un-encrypted files.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">No
fee was charged, but was posted on the ‘net for anyone with a
similar desire to view their DVDs in Linux. The MPAA found out and
subsequently obtained a court order forbidding any US site from
hosting DeCSS. That of course sparked worldwide interest in
Linux-based DVD players. The case is still in court in the Land of
the Free. For more info please click <A HREF="http://www.eff.org/">here.</A></FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Today,
there are other software decryptors available for Linux which do not
use the original DeCSS code, but do the same job, and are not subject
to any litigation. We shall focus on these.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><B>The
Goods!</B></FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Just
to get you warm, I'll tell you what system I've got in my crib.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"> </P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Hardware</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>CPU:
Pentium III 750 (old, I know, I'm planning for an Athlon XP 1900+)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>RAM:
1GB PC 133 SDRAM (hey, ram was cheeeep when I bought)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>BOARD:
MSI BX Master, 4 IDE Slots (2 on an on-board Promise Controller)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Case:
ATX Extended Tower with 9 5.25 Slots</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Sound:
SoundBlaster Live! 5.1 Platinum (lovely card!)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>VGA:
NVidia TNT2, 32MB SDRAM</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>HDD:
2x WD400 7200 RPM, 40GB drives, 2MB Cache (I'm showing off here)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Speakers:
<B>Front:</B> 80W Kenwood speakers, driven by a Technics 80W Power Amp
connected directly to the card</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Rear:
</B>Some mid-budget 20W RMS computer speakers</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Center:
</B>As Above</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Sub:
</B>A no name 40W Sub in a wooden enclosure</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Monitor:
18" NEC TFT Flat Panel</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"> </P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Software</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>OS:</B>
SuSE Linux 8.0 Professional</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Sound:</B>
<B>ALSA 0.9.0rc2,</B> running emu10k1 SoundBlaster driver. This is
the only audio driver for Linux capable of using the Surround
capabilities of the SB Live 5.1. Even the Windows drivers and
software don't have half the features of this driver. Linux driver
can handle up to 8 such cards on 1 system, whereas Windows can't
handle two (don't bother, I've tried it). Hats off to the ALSA team!</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Video:</B>
</FONT></FONT>
</P>
<P STYLE="margin-left: 6.35cm; margin-bottom: 0cm">1.<FONT SIZE=1><FONT FACE="Times New Roman">
</FONT></FONT><FONT SIZE=2><FONT FACE="Garamond"><B>Xine 0.9.12
</B>(Complete with its plugin capabilities makes Xine hard to beat)</FONT></FONT></P>
<P STYLE="margin-left: 6.35cm; margin-bottom: 0cm">2.<FONT SIZE=1><FONT FACE="Times New Roman">
</FONT></FONT><FONT SIZE=2><FONT FACE="Garamond"><B>Ogle 0.8.2 </B>(Fast
and quick DVD-only player that supports DVD menus)</FONT></FONT></P>
<P STYLE="margin-left: 6.35cm; margin-bottom: 0cm">3.<FONT SIZE=1><FONT FACE="Times New Roman">
</FONT></FONT><FONT SIZE=2><FONT FACE="Garamond"><B>Mplayer 0.90</B>
(Mainly Console-based player with an unusual assortment of options.
Mplayer will play almost any type of file format available today
including VOB, VIVO, ASF/WMV, QT/MOV, Xanim, AVI, DiVX, VCD, SVCD,
and of course DVDs It has a GUI option with skins.)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Both
Xine and the Mplayer now offer FULL multi-channel (5.1) surround
audio.</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>To compile
mplayer:</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Requirements</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">libdvdread 0.8 <B>and</B>
libcss (<U>not</U> libdvdcss)</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>or</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><A HREF="http://www.dtek.chalmers.se/groups/dvd/downloads.shtml">libdvdread
0.9</A> <B>and</B> <A HREF="http://www.videolan.org/">libdvdcss 0.0.3</A>
(not libcss NOR libdvdcss 1.0)</P>
<P STYLE="margin-bottom: 0cm">all may be obtained at
<A HREF="http://www.dtek.chalmers.se/groups/dvd">www.dtek.chalmers.se/groups/dvd</A></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">The libdvdcss is
used to decrypt the DVD and libdvdread to read its contents, and for
chapter support.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">I recommend you use
<B>ALSA 0.9.0rc2</B>, for audio, if you have a modern sound card, such
as the SoundBlaster Live! 5.1 series. The Audigy range may work, but
alas, I don't have one :-(</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><I>Please read
the </I>INSTALL<I> and </I>README<I> files in all packages</I></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 1</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">libdvdcss</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">./configure</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">compile install it
with "make && make install && ldconfig"</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 2</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">libdvdread</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">compile and install
as above</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 3</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">mplayer 0.90</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">./configure –help</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">make &&
make install</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">It should then
install itself in /usr/local/bin as mplayer</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 4</B></FONT></P>
<P STYLE="margin-bottom: 0cm">(a) if /dev/hdc is your dvd drive,
make a link <I><FONT FACE="Garamond">ln -s /dev/hdc /dev/dvd</FONT></I></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">(only needs to be
done once)</FONT></P>
<P STYLE="margin-bottom: 0cm">type<I><FONT FACE="Garamond"> mplayer
-dvd 1 -ao oss</FONT></I></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
software should give some info such as the encryption key for the
DVD, and then start to play the "encrypted" movie.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">There are a
gazillion options available, too numerous to dig into here, but
multichannel audio is possible with <I><FONT FACE="Garamond">-channels
x</FONT></I>, where x is 2,4 or 6 speakers. Remember, it is pointless
if you have a basic 2-channel card. These multichannel cards are
affordable these days so spoil yourself and get one!
</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Other
useful options:</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-title
x</FONT></I>
– select DVD title</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-chapter
y</FONT></I>
– select chapter in title specified above</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-ss
hh:mm:ss</FONT></I>
–jump to specific time point</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-vcd
x</FONT></I>
- play vcd chapter</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">-channels 4
- play thru 4 discrete channels (front & rear)</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">On-screen
display is also available, but not regular DVD subtitles.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">Mplayer has rapidly
become the most widely downloaded Linux software by a far margin (see
<A HREF="http://freshmeat.net/stats/#popularity">http://freshmeat.net/stats/#popularity</A>
if you don’t believe me), but it is not as easy to set up as
Xine, if you don’t like compiling apps.0</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><FONT SIZE=4 STYLE="font-size: 13pt"><B>To
get Xine up and running in 5 minutes flat.</B></FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 1</B></FONT></P>
<P STYLE="margin-bottom: 0cm">download the latest xine releases from
<A HREF="http://xine.sourceforge.net/">xine.sourceforge.net</A></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">You will need the
following RPMs if you do not feel like compiling. x86 refers to your
type of Pentium processor; i686 for Pentium III or higher, i586 for
Pentium and AMD K6</FONT></P>
<UL>
<LI> xine-lib-0.9.12-x86.rpm
<LI> xine-lib-0.9.12-oss-x86.rpm
<LI> xine-lib-0.9.12-oggvorbis-x86.rpm
<LI> xine-lib-0.9.12-xv.rpm
<LI> xine-lib-0.9.12-x86.rpm
<LI> xine-ui-0.9.12-x86.rpm
<LI> xine-lib-dvdnav-0.9.10-x86.rpm
</UL>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><I>There are
others, but these are the bare essentials.</I></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 2</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Copy all the RPMs
into an empty folder and from there, logged in as root, run the
following:</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">rpm -Uvh xine*.rpm</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">If you are averse
to using the console, call up kpackage or gnorpm and install them in
the GUI instead.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 3</B></FONT></P>
<P STYLE="margin-bottom: 0cm">In GUI, open up a console (purely to
see the output from the player, once you are comfortable with the
settings, you won't need the console), and type the following (mind
the case sensitivity of each letter) <I><FONT FACE="Garamond">xine
-pq -A oss -V xv -u0 dvdnav://</FONT></I></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">It may look cryptic
but it is easy to explain. The purpose of the switches is to set
defaults for audio and video in the config file which is stored in </FONT>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">“.xine/config”
in your home folder.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-pq play
immediately, and quit when done</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-A oss use oss as
the audio driver</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-V xv use xv as the
video driver</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-u0 select the
first subtitle (usually English, u1 refers to French, etc.)</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">dvdnav:// is the
optional plugin that actually plays the DVD. It also has menu
functionality and allows you to jump from chapter to chapter with 9/3
on the numeric keypad.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Type "xine
--help" or man xine for full details.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">As stated earlier,
the skin may be changed in the menu. All settings are also possible
in the menu including multichannel audio.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Xine plays a whole
range of media: DVDs, VCDs, CDs, ogg, mp3, wav, DiVX... on and on and
on.</FONT></P>
<P STYLE="margin-bottom: 0cm"> </P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>URLs</B></FONT></P>
<P STYLE="margin-bottom: 0cm">xine: <A HREF="http://xine.sourceforge.net/">xine.sourceforge.net</A></P>
<P STYLE="margin-bottom: 0cm">ogle: <A HREF="http://www.dtek.chalmers.se/groups/dvd">www.dtek.chalmers.se/groups/dvd</A></P>
<P STYLE="margin-bottom: 0cm">mplayer: <A HREF="http://www.mplayerhq.hu/homepage">www.mplayerhq.hu/homepage</A></P>
<P STYLE="margin-bottom: 0cm">ALSA: <A HREF="http://www.alsa-project.org/">www.alsa-project.org</A></P>
<P STYLE="margin-bottom: 0cm">xinedvdnav plugin (to decrypt DVDs,
with DVD menus): <A HREF="http://dvd.sourceforge.net/d">http://dvd.sourceforge.net/</A></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">I hope to keep you
posted with a more detailed paper sometime soon, with tips and
tricks.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">'Later.</FONT></P>
<P STYLE="margin-bottom: 0cm"> </P>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Tunji Durodola</H4>
<EM>Tunji is a Lagos-based computer consultant specialising in Linux solutions.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Tunji Durodola.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Is Your Memory Not What It Used To Be?</font></H1>
<H4>By <a href="http://www.geocities.com/madhumkurup/mailme.html">Madhu M Kurup</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h2>Intent</h2>
The intent of this article is to provide an understanding of memory
leak detection and profiling tools currently available. It also aims at
providing you with enough information to be able to make a choice between
the different tools for your needs.<br>
<h2>Leaks and Corruption</h2>
We are talking software here, not plumbing. And yes, any fairly large,
non trivial program is bound to have a problem with memory and or leaks.<br>
<h3>Where do problems occur?</h3>
First, leaks and such memory problems do not occur in some languages.
These languages believe that memory management is <i>so important</i> that
it should never be handled by the users of that language. It is better
handled by the <i>language designers</i>. Examples of such languages are
Perl, Java and so on.<br>
However, in some other languages (notably C and
C++) the language designers have felt that memory management is <i>so important</i>
that it can only be taken care of by the <i>users</i> of the language.
A leak is said to occur when you dynamically allocate memory and then forget
to return it. In addition to leaks, other memory problems such as <a
href="http://www.tuxedo.org/%7Eesr/jargon/html/entry/buffer-overflow.html">buffer
overflows</a>, <a
href="http://www.tuxedo.org/%7Eesr/jargon/html/entry/dangling-pointer.html">dangling
pointers</a> also occur when programmers manage memory themselves.
These problems are caused where there is a mismatch between what
the program (and by extension the programmer) believes the state of memory
is, as opposed to what it really is.<br>
<h3>What are the problems?</h3>
In order for programs to be able to deal with data whose size is
not known at compile time, the program may need to request memory from
the runtime environment (operating system). However, having obtained a
chunk of memory, it may be possible that the program does not return to
back to the environment after use. An even more severe condition results
when the address of the block that was obtained is lost, which means that
it is no longer possible to identify that allocated memory. Other
problems include trying to access memory after it has been returned (dangling
pointers). Another common problem is trying to access more memory that was
originally requested and so on (buffer overflow).<br>
<h3>Why should these problems bother me?</h3>
Leaks may not be a problem for short-lived programs that finish their
work quickly. Unfortunately, many programs are designed to function
without termination for a long period. A good example would be the Apache
webserver that is currently providing you this web page. In such a situation,
a malfunctioning leaky program could keep requesting memory from the system
and not return it. Eventually this would lead to the system running out
of memory and all programs running on that machine to suffer. This is obviously
not a good thing. In addition to a program requiring more memory,
leaks can also make a program sluggish. The speed at which the program
is context-switched in and out can decrease if the memory load increases.
While not as severe as causing the machine to crash, an excessive memory
load on a machine could cause it to thrash, swapping data back and forth.<br>
Dangling pointers can result in subtle corruption
and bugs that are extremely unusual, obscure and hard to solve. Buffer overflows
are probably the most dangerous of the three forms of memory problems.
They lead to most of the security exploits that you read about[<a
href="#Secure_Programming_">SEC</a>]. In addition to the problems
described above, it may be possible that the same memory chunk is returned
back to the system multiple times. This obviously indicates a programming
error. A programmer may wish to see how the memory requests are made by
a program over the course of the lifetime of the program in order to find
and fix bugs.<br>
<h3>Combating these problems</h3>
There are some run time mechanisms to combat memory problems. Leaks can
be solved by periodically stopping and restarting the offending program
<cite></cite> [<a href="#OOM_killer">OOM</a>]. Dangling pointers can be
made repeatable by zeroing out all memory returned back to the operating
systems. Buffer overflows have a variety of solutions, some of which are
described in more detail <a
href="http://www.geocities.com/madhumkurup/papers/Buffer.ps">here</a>. <br>
Typically, the overhead of combating these problems at
runtime or late in development cycle is so high that finding them and
fixing them at the program level is often the more optimal solution.<br>
<h2>Open Source </h2>
<h3>GCC-based alternatives</h3>
The <a
href="http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/boehm-gc/">gcc</a> toolset
now includes a garbage collector which facilitates the easy detection
and elimination of many memory problems. Note that while this can be used
to detect leaks, the primary reason for creating this was to implement
a good garbage collector[<a href="#Garbage_Collectors">GC</a>]. This work
is currently being led by Hans-J. Boehm at HP.
<h4>Technology</h4>
The technology used here is <a
href="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html">Boehm-Demers-Weiser</a>
technique for keeping track of allocated memory. Allocation of memory
is done using the algorithm's version of the standard memory allocation
functions. The program is then compiled with these functions and when executed,
the algorithm can analyze the behavior of the program. This algorithm is
fairly well known and well understood. It should not cause any problems
and/or interfere with programs. It can be made thread safe and can even
scale onto a multiprocessor system.<br>
<h4>Performance</h4>
Good performance with reduction in speed in line with expectations.
The code is extremely portable and is also available directly with gcc.
The version shipped with gcc is slightly older, but can be upgraded.<br>
There is no interface - it is difficult to use
and requires much effort for it to be useful. Existing systems may not
have this compiler configuration and may require some additional work to
get it going. In addition, in order for the calls to be trapped, all memory
calls (such as <i>malloc()</i> and <i>free()</i> ) have to be replaced with
equivalents provided by the garbage collector. One could use a macro, but
that is still not very flexible. Also this approach implicitly requires
source code for all pieces that require memory profiling with the ability
to shift from the real functions to those provided.<br>
<h4>Verdict</h4>
If you need a solution across multiple platforms (architectures,
operating systems) where you have control over all relevant source, this
could be it.<br>
<h3>Memprof</h3>
<a href="http://people.redhat.com/otaylor/memprof/">Memprof</a> is
an attractive easy to use package, created by Owen Talyor of Red Hat. This
tool is a nice clean GNOME front-end to the Boehm-Demers-Weiser garbage
collector.<br>
<h4>Technology</h4>
At the heart of the profiling, memprof is no different from the toolset
described above. However, how it implements this functionality is to trap
all memory requests from the program and redirect it at runtime to the
garbage collector. While not as functional as the gcc alternative on threads
and multiprocessors, the program can be asked to follow forks as they happen.<br>
<h4>Performance</h4>
The performance of this tool is pretty good. The GUI was well designed,
responsive and informative. This tools works directly with executables,
and it works without any changes needed to the source. This tool also graphically
displays the memory profile as the program executes which helps in understanding
memory requirements of the program during its lifetime.<br>
This tool is currently available only for the x86
and PPC architecture on Linux. If you need help on other platforms, you
will need to look elsewhere. This tool is not a GTK application, it needs
the full-blown GNOME environment. This may not be feasible everywhere.
Finally, development on this tool appears to be static (version 0.4.1.
for a while). While it is possible that it does what it is required to do
well, it does not seem that this too will do anything more than just leak
detection.<br>
<h4>Verdict</h4>
If you like GUI tools and don't mind GNOME and Linux, this is a
tool for you.<br>
<h3>Valgrind</h3>
<a href="http://developer.kde.org/%7Esewardj/">Valgrind</a> is a
program that attempts to solve a whole slew of memory problems, leaks
being just one of them. This tool is the product of Julian Seward (of
<a href="http://sources.redhat.com/bzip2/index.html">bzip2</a> and <a
href="http://www.cacheprof.org">cacheprof</a> fame). It terms itself "an open source
memory debugger for x86 linux" and it certainly fits that bill. In addition,
it can profile the usage of the CPU cache, something that is fairly unusual.
<h4>Technology</h4>
The technology used in this program is fairly complex and <a
href="http://developer.kde.org/%7Esewardj/docs/techdocs.html">well documented</a>.
Each byte of memory allocated by the program is tracked by nine status
bits, which are then used for housekeeping purposes to identify what is
going on. At the cost of tremendously increasing the memory load of an
executing program, this tool enables a much greater set of checks. As all
the reads and writes are intercepted, cache profiling of the CPU's various
L caches can also be done.<br>
<h4>Performance</h4>
The tool was the slowest of the three detailed here, for obvious
reasons. However, for the reduction in speed, this tool provides a wealth
of information is probably the most detailed of the three. In addition
to the usual suspects, this tool can identify a variety of other memory
and even some POSIX pthread issues. Cache information is probably overkill
for most applications, but it is an interesting way to look at the performance
of an application. The biggest plus for Valgrind is that it is under rapid
development with a pro-active developer and an active community. In fact
the web page of Valgrind proclaims the following from the author - <i>"If
you have problems with Valgrind, don't suffer in silence. Mail me."</i>.<br>
The tool however, is very x86 specific. Portability
is fairly limited and to x86 Linux. The interface is purely command-line
driven and while usable, sometimes the tool gives you too much information
for it to be useful. This tool also directly works with binaries, so while
recompiles are not required, it will require diligence to go through the
output of this tool to find what you are looking for. You can suppress memory
profiling for various system libraries by creating suppression files, but
writing these files is not easy. In addition, threading support is not complete,
although this tool has been used on Mozilla, OpenOffice and such other
large threaded programs. If this tool had a GUI front end, it would
win hands down.<br>
<h4>Verdict</h4>
If you are on x86 and know your code well and do not mind a CLI interface,
this program will take you another level.<br>
<h3>Other Open Source tools</h3>
Before I get sent to the stake for not having mentioned your favorite
memory tool, I must confess that few compare in completeness to these three
in terms of the data that they provide. A more comprehensive list
of leak detection tools is available <a
href="http://www.sslug.dk/emailarkiv/bog/2001_08/msg00030.html">here</a>.
<br>
<h2>Commercial</h2>
These tools are mentioned here only for completeness.
<h3>Purify</h3>
The <a href="http://www.rational.com/products/pqc/pplus_ux.jsp">big
daddy</a> of memory tools, does <i>not work</i> on Linux, so you can stop
asking that question.
<h3>Geodesic</h3>
A latecomer to this arena, <a
href="http://www.geodesic.com/solutions/solutions_linux.html">Geodesic</a>
is known most in the Linux community for their <a
href="http://www.geodesic.com/solutions/products_gc_demo.html">Mozilla</a>
demo, in which they use their tools to help find memory problems in the
Mozilla codebase. How much use this has been to the Mozilla team is yet
to be quantified, but their open-source friendliness can't hurt. Works
for Solaris/Linux with a fully functional trial. Works on Windows as well.<br>
<h3>Insure++</h3>
A C++ specific tool, but still fairly well known, Parasoft's <a
href="http://www.parasoft.com/jsp/products/home.jsp?product=Insure">Insure++</a>
is a fairly complete memory profiling / leak detection tool. In addition,
it can find some C++ specific errors as well, so that can't hurt. This tool
works with a variety of compilers and operating systems, a free trial version
is available too.
<h2>Miscellaneous Notes:</h2>
<h3><a name="Secure_Programming_"></a>Secure Programming </h3>
Secure programming involves many components, but probably the most significant
is the careful use of memory. More details are available <a
href="http://www.theorygroup.com/Theory/FAQ/Secure-Programs-HOWTO-1.html">here</a>.<br>
<h3><a name="OOM_killer"></a>OOM killer</h3>
Some the newer Linux kernels employ an algorithm which is known as the
Out Of Memory (OOM) killer. This code is invoked when the kernel completely
runs out of memory, at which point active programs / processes are chosen
to be executed (as in killed, end_of_the_road, happy hunting grounds, etc).
More details are available <a
href="http://linux-mm.org/docs/oom-killer.shtml">here</a>.<br>
<h3><a name="Garbage_Collectors"></a>Garbage Collectors </h3>
One of the other reasons why garbage collection is not always a preferred
solution is that it is really tough to implement. They have severe problems
with self-referential structures (i.e. structures that link to themselves)
as aptly described <a
href="http://www.tuxedo.org/%7Eesr/jargon/html/Some-AI-Koans.html">here</a>.<br>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Madhu Kurup</H4>
<EM>I'm a CS engineer from Bangalore, India and formerly of the
<a href="http://www.linux-bangalore.org">ILUG Bangalore</a>. I've
been working and playing with Linux for a while and while programming is
my first love, Linux comes a close second. I work at the Data Mining group
at <a href="http://www.yahoo.com">Yahoo!</a> Inc and work on algorithms,
scalability and APIs there. I moonlight on the Linux messenger client and
dabble in various software projects when (if ever) I can find any free time.
<P> And yes, if you want to know, I use C++, vi, mutt, Windowmaker
and Mandrake; let the flame wars begin :) </EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Madhu M Kurup.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Exploring Perl Modules - Part 1: On-The-Fly Graphics with GD</font></H1>
<H4>By <a href="mailto:p_padala@yahoo.com">Pradeep Padala</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h3 name="intro"> Welcome To "Exploring Perl Modules" !!!</h3>
<p>
Perl modules are considered to be one of the strongest points for perl's
success. They contain a lot of re-usable code and of course are free.
This is an attempt to trap the treasure trove. There are lot
of tutorials and even books written on popular modules like CGI, DBI etc..
For less popular modules, users are left with documentation which is cryptic
and sometimes incomplete.
<p>
I am starting a series of articles that will attempt to explain some of the less popular but
useful modules.
During the last year, I came across and programmed with
numerous perl modules. I will explain the modules with numerous
useful examples from my experience. We will take one module at a time
and explore its various uses.
<h3 name="whoread"> Who should be reading these</h3>
<p>
Well, you should know perl. We won't be delving much into the basics of perl.
There are plenty of documentation, articles and books on perl.
<a href=http://www.oreilly.com/catalog/lperl3/>Learning Perl</a> is
often recommended for beginners. Once you gain experience, you can try
<a href=http://www.oreilly.com/catalog/pperl3/>Programming Perl</a>.
<p>
If you are an average perl programmer and haven't used lot of modules, this
is the right place. Modules provide a great way to re-use code and write
efficient and compact applications. In each article we will graduate from
simple examples to complex examples ending in a real-world application,
if appropriate.
<h3 name="intromodules"> Introduction to Modules </h3>
Modules provide an effective mechanism to import code and use it. The
following line imports a module and makes its functions accessible.
<pre>
use module;
</pre>
For example if you want to use GD, you would write
<pre>
use GD;
</pre>
<h3> Finding and Installing Modules </h3>
<p>
Before we plunge into the details of programming, here are some instructions
for finding and installing modules. We will be using various modules, and most
of them are not installed by default. Some modules require libraries which
may or may not have been installed. I will mention the things
required whenever appropriate. Here are generic instructions for downloading
and installing modules.
<p>
An easy way to install the module is by using the CPAN module. Run CPAN in
interactive mode as
<pre>
perl -MCPAN -e shell
</pre>
<p>
Then you can do various tasks like downloading, decompressing and installing
modules. For example, for installing GD you can use
<pre>
install GD
</pre>
<p>
If you are like me and and are accustomed to configure, make, make install method,
here are the steps to install a module.
<ul>
<li> Find the module in CPAN's
<a href=http://www.cpan.org/modules/00modlist.long.html>list</a> of all modules.
<li> Download the latest version of the module. For example, the latest GD
module can be downloaded from
<a href=http://www.cpan.org/authors/id/LDS/GD-1.40.tar.gz>http://www.cpan.org/authors/id/LDS/GD-1.40.tar.gz</a>
<li> Unzip the module
<pre>
tar zxvf GD-1.40.tar.gz
</pre>
<li> Build the module
<pre>
perl Makefile.PL
(or)
perl Makefile.PL PREFIX=/my/perl/directory
(if you want to install in /my/perl/directory)
make
make test (optional)
</pre>
<li> Install the module
<pre>
make install
</pre>
</ul>
<h3> Ready to Go ... </h3>
<p>
So you have installed your favourite module and are raring to learn. In this article we
will explore the perl GD module, which provides an interface to <a href="http://www.boutell.com/gd/">GD library</a>. We will also be using the CGI module
for the web interface. You don't need to know a great deal of CGI to understand
this article. I will explain things where necessary.
<h3> Graphics with GD </h3>
<p>
Let's start the wheels with a simple and effective example
<pre>
Text version of the file can be found <a href=misc/padala/simple.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -w</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">100</font>,<font color="#ff00ff">100</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">$white</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>);
<font color="#008b8b">$black</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$red</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$blue</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">255</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>->transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>->interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#0000ff"># Put a black frame around the picture</font>
<font color="#008b8b">$im</font>->rectangle(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">99</font>,<font color="#ff00ff">99</font>,<font color="#008b8b">$black</font>);
<font color="#0000ff"># Draw a blue oval</font>
<font color="#008b8b">$im</font>->arc(<font color="#ff00ff">50</font>,<font color="#ff00ff">50</font>,<font color="#ff00ff">95</font>,<font color="#ff00ff">75</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">360</font>,<font color="#008b8b">$blue</font>);
<font color="#0000ff"># And fill it with red</font>
<font color="#008b8b">$im</font>->fill(<font color="#ff00ff">50</font>,<font color="#ff00ff">50</font>,<font color="#008b8b">$red</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">"</font><font color="#ff00ff">>picture.png</font><font color="#ff00ff">"</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">"</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>->png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
This is the example given in the
<a href= http://stein.cshl.org/WWW/software/GD/>GD man page</a>
with little modifications. This produces a small rectangle
with a red oval with blue border. Let's dissect the program.
<p>
One of the first things you do with GD library, is create an image handle to
work with. The line
<pre>
$im = new GD::Image($width, $height)
</pre>
<p>
creates and image with the specified width and height. You can also create
an image from an existing image as well. It is useful for manipulating existing
images. We will see an example on this in the later part of the article.
<p>
Next we need to allocate some colors. As you can guess, the RGB intensities
need to be specified for initializing colors. Since we will be using lots of
colors, let's write a small function which will initialize a bunch of colors
for use.
<pre>
Text version of the file can be found <a href=misc/padala/init_colors.pl.txt>here</a>.
<font color="#0000ff"># Save this as init_colors.pl </font>
<font color="#0000ff"># Other scripts call this function</font>
</font>
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">InitColors</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$im</font>) = <font color="#008b8b">$_</font>[<font color="#ff00ff">0</font>];
<font color="#0000ff"># Allocate colors</font>
<font color="#008b8b">$white</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>);
<font color="#008b8b">$black</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$red</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$blue</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">255</font>);
<font color="#008b8b">$green</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">0</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>);
<font color="#008b8b">$brown</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">0x99</font>, <font color="#ff00ff">0</font>);
<font color="#008b8b">$violet</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">255</font>);
<font color="#008b8b">$yellow</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>);
}
</pre>
<p>
I often refer to this <a href=http://www.hypersolutions.org/pages/rgbhex.html>
page</a> for some nice rgb combinations.
<p>
The next few lines are straightforward and pretty much self-explanatory.
The last lines regarding the file creation require special mention.
Since we will be writing an image to a file, we need to put the file handle
in binary mode with
<pre>
binmode MYFILEHANDLE;
</pre>
<p> This actually is a no-op on most UNIX-like systems.
<p>
Then we write to the file with the usual print command. GD can print the image
in various formats. For example if you want to print a jpeg image instead of
png, all you need to do is
<pre>
print MYFILEHANDLE $im->jpeg;
</pre>
<h3> Simple Drawing </h3>
<p>
GD offers some simple drawing primitives which can be combined to generate complex
graphics. Examine the following script that gives a whirlwind tour of all the
simple primitives.
<pre>
Text version of the file can be found <a href=misc/padala/drawing.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>do</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">init_colors.pl</font><font color="#ff00ff">"</font>;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">640</font>,<font color="#ff00ff">400</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">&InitColors</font>(<font color="#008b8b">$im</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>->transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>->interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#008b8b">$x1</font> = <font color="#ff00ff">10</font>;
<font color="#008b8b">$y1</font> = <font color="#ff00ff">10</font>;
<font color="#008b8b">$x2</font> = <font color="#ff00ff">200</font>;
<font color="#008b8b">$y2</font> = <font color="#ff00ff">200</font>;
<font color="#0000ff"># Draw a border</font>
<font color="#008b8b">$im</font>->rectangle(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">639</font>, <font color="#ff00ff">399</font>, <font color="#008b8b">$black</font>);
<font color="#0000ff"># A line</font>
<font color="#008b8b">$im</font>->line(<font color="#008b8b">$x1</font>,<font color="#008b8b">$y1</font>,<font color="#008b8b">$x2</font>,<font color="#008b8b">$y2</font>,<font color="#008b8b">$red</font>);
<font color="#0000ff"># A Dashed Line</font>
<font color="#008b8b">$im</font>->dashedLine(<font color="#008b8b">$x1</font> + <font color="#ff00ff">100</font>, <font color="#008b8b">$y1</font>, <font color="#008b8b">$x2</font>, <font color="#008b8b">$y2</font>, <font color="#008b8b">$blue</font>);
<font color="#0000ff"># Draw a rectangle</font>
<font color="#008b8b">$im</font>->rectangle(<font color="#008b8b">$x1</font> + <font color="#ff00ff">200</font>, <font color="#008b8b">$y1</font>, <font color="#008b8b">$x2</font> + <font color="#ff00ff">200</font>, <font color="#008b8b">$y2</font>, <font color="#008b8b">$green</font>);
<font color="#0000ff"># A filled rectangle</font>
<font color="#008b8b">$im</font>->filledRectangle(<font color="#008b8b">$x1</font> + <font color="#ff00ff">400</font>, <font color="#008b8b">$y1</font>, <font color="#008b8b">$x2</font> + <font color="#ff00ff">400</font>, <font color="#008b8b">$y2</font>, <font color="#008b8b">$brown</font>);
<font color="#0000ff"># A circle</font>
<font color="#008b8b">$im</font>->arc(<font color="#008b8b">$x1</font> + <font color="#ff00ff">100</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">200</font> + <font color="#ff00ff">100</font>, <font color="#ff00ff">50</font>, <font color="#ff00ff">50</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">360</font>, <font color="#008b8b">$violet</font>);
<font color="#0000ff"># A polygon</font>
<font color="#0000ff"># Make the polygon</font>
<font color="#008b8b">$poly</font> = <font color="#a52a2a"><b>new</b></font> GD::Polygon;
<font color="#008b8b">$poly</font>->addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">200</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">200</font>);
<font color="#008b8b">$poly</font>->addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">250</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">230</font>);
<font color="#008b8b">$poly</font>->addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">300</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">310</font>);
<font color="#008b8b">$poly</font>->addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">400</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">300</font>);
<font color="#0000ff"># Draw it</font>
<font color="#008b8b">$im</font>->polygon(<font color="#008b8b">$poly</font>, <font color="#008b8b">$yellow</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">"</font><font color="#ff00ff">>picture.png</font><font color="#ff00ff">"</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">"</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>->png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
The output looks like
<a href="misc/padala/picture1.png">this</a>.
<p>
The above script is self-explanatory. The polygon needs a little bit
of explanation. In order to draw a polygon, you first have to make the polygon and then
draw it. Of course, a polygon must have at least three vertices.
<h3> Drawing Text </h3>
<p>
So what about text? You can draw text in some of the simple fonts
provided by GD or use a True Type font available on your system.
There are two simple functions available to draw text.
<pre>
# Draw the text
$im->string($font, $x, $y, $string, $color);
# Print text rotated 90 degrees
$im->stringUp($font, $x, $y, $string, $color);
</pre>
The following script shows various simple fonts provided by GD.
<pre>
Text version of the file can be found <a href=misc/padala/text.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>do</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">init_colors.pl</font><font color="#ff00ff">"</font>;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">200</font>, <font color="#ff00ff">80</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">&InitColors</font>(<font color="#008b8b">$im</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>->transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>->interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#0000ff"># Create a Border around the image</font>
<font color="#008b8b">$im</font>->rectangle(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">199</font>, <font color="#ff00ff">79</font>, <font color="#008b8b">$black</font>);
<font color="#008b8b">$x1</font> = <font color="#ff00ff">2</font>;
<font color="#008b8b">$y1</font> = <font color="#ff00ff">2</font>;
<font color="#0000ff"># Draw text in small font</font>
<font color="#008b8b">$im</font>->string(gdSmallFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font>, <font color="#ff00ff">"</font><font color="#ff00ff">Small font</font><font color="#ff00ff">"</font>, <font color="#008b8b">$blue</font>);
<font color="#008b8b">$im</font>->string(gdMediumBoldFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">20</font>, <font color="#ff00ff">"</font><font color="#ff00ff">Medium Bold Font</font><font color="#ff00ff">"</font>, <font color="#008b8b">$green</font>);
<font color="#008b8b">$im</font>->string(gdLargeFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">40</font>, <font color="#ff00ff">"</font><font color="#ff00ff">Large font</font><font color="#ff00ff">"</font>, <font color="#008b8b">$red</font>);
<font color="#008b8b">$im</font>->string(gdGiantFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">60</font>, <font color="#ff00ff">"</font><font color="#ff00ff">Giant font</font><font color="#ff00ff">"</font>, <font color="#008b8b">$black</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">"</font><font color="#ff00ff">>picture.png</font><font color="#ff00ff">"</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">"</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>->png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
The output picture looks like this.<br>
<img alt="Output image of above script" src=misc/padala/picture2.png width=200 height=80>
<p>
As you can see, these fonts are quite limited and not so attractive. The
following section shows the usage of True Type Fonts with GD
<h3> True Type Fonts </h3>
<p>
You can use the true type fonts available on your system to draw some nice
text. The function <code>stringFT</code> is used to draw in TTF font.
<pre>
# $fontname is an absolute or relative path to a TrueType font.
stringFT($fgcolor,$fgcolor,$fontname,$ptsize,$angle,$x,$y,$string);
</pre>
<p>
Here's an example showing the usage
<pre>
Text version of the file can be found <a href=misc/padala/ttf.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>do</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">init_colors.pl</font><font color="#ff00ff">"</font>;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">270</font>, <font color="#ff00ff">80</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">&InitColors</font>(<font color="#008b8b">$im</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>->transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>->interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#008b8b">$im</font>->rectangle(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">269</font>, <font color="#ff00ff">79</font>, <font color="#008b8b">$black</font>);
<font color="#008b8b">$x1</font> = <font color="#ff00ff">10</font>;
<font color="#008b8b">$y1</font> = <font color="#ff00ff">20</font>;
<font color="#0000ff"># Draw text in a TTF font</font>
<font color="#008b8b">$font</font> = <font color="#ff00ff">"</font><font color="#ff00ff">/usr/X11R6/lib/X11/fonts/TTF/luxisri.ttf</font><font color="#ff00ff">"</font>;
<font color="#008b8b">$im</font>->stringFT(<font color="#008b8b">$red</font>, <font color="#008b8b">$font</font>, <font color="#ff00ff">15</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font>, <font color="#ff00ff">"</font><font color="#ff00ff">A TTF font</font><font color="#ff00ff">"</font>);
<font color="#008b8b">$anotherfont</font> = <font color="#ff00ff">"</font><font color="#ff00ff">/usr/share/fonts/default/TrueType/starbats.ttf</font><font color="#ff00ff">"</font>;
<font color="#008b8b">$im</font>->stringFT(<font color="#008b8b">$blue</font>, <font color="#008b8b">$font</font>, <font color="#ff00ff">20</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">40</font>, <font color="#ff00ff">"</font><font color="#ff00ff">Another one here !!!</font><font color="#ff00ff">"</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">"</font><font color="#ff00ff">>picture.png</font><font color="#ff00ff">"</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">"</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>->png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
The output looks like this.<br>
<img alt="Output image for above script" src=misc/padala/picture3.png width=270 height=80>
<h3> Let's go Online </h3>
<p>
Now that we have seen some basic uses of GD, let's turn our attention to
web graphics. So how do you output an image through CGI? Simple. Add the
following lines to the scripts instead of printing to a file.
<pre>
# To disable buffering of image content.
select(STDOUT);
$| = 1;
undef $/;
print "Content-type: image/jpeg\n\n";
print $im->jpeg(100);
</pre>
<p>
This is all you need to know about CGI for now. If you already know CGI,
you can enhance your code for handling complex web interaction. Let's write a small program which
reads an image and displays a resized version of it. It might be useful
for showing thumbnails.
<pre>
Text version of the file can be found <a href=misc/padala/resize.cgi.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -wT</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>CGI <font color="#ff00ff">'</font><font color="#ff00ff">:standard</font><font color="#ff00ff">'</font>;
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#0000ff"># create a new image</font>
<font color="#008b8b">$image_file</font> = <font color="#ff00ff">"</font><font color="#ff00ff">images/surfing.jpg</font><font color="#ff00ff">"</font>;
<font color="#008b8b">$im</font> = GD::Image->newFromJpeg(<font color="#008b8b">$image_file</font>);
(<font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>) = <font color="#008b8b">$im</font>->getBounds();
<font color="#008b8b">$newwidth</font> = <font color="#008b8b">$width</font> / <font color="#ff00ff">3</font>;
<font color="#008b8b">$newheight</font> = <font color="#008b8b">$height</font> / <font color="#ff00ff">3</font>;
<font color="#008b8b">$outim</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>);
<font color="#0000ff"># make the background transparent and interlaced</font>
<font color="#008b8b">$outim</font>->copyResized(<font color="#008b8b">$im</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>, <font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>);
<font color="#0000ff"># make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">STDOUT</font>;
<font color="#a52a2a"><b>select</b></font>(STDOUT);
<font color="#008b8b">$|</font> = <font color="#ff00ff">1</font>;
<font color="#a52a2a"><b>undef</b></font> <font color="#008b8b">$/</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">Content-type: image/jpeg</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$outim</font>->jpeg();
</pre>
<p>
In this example, the function newFromJpeg() reads a jpeg file. Then we
then calculated the boundaries and resized it accordingly. A demo of the resizing
can be found <a href=http://www.cise.ufl.edu/~ppadala/perl/exploring/cgi-bin/resize.cgi>here</a>
<h3> A Photo Album </h3>
<p>
With this resizing knowledge we can create a small online photo album. In this
we use resizing to show
smaller images and display the original image when the user clicks on the smaller images.
<pre>
Text version of the file can be found <a href=misc/padala/album.cgi.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -wT</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>CGI <font color="#ff00ff">'</font><font color="#ff00ff">:standard</font><font color="#ff00ff">'</font>;
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#008b8b">$imnum</font> = param(<font color="#ff00ff">'</font><font color="#ff00ff">imnum</font><font color="#ff00ff">'</font>);
<font color="#a52a2a"><b>if</b></font>(!<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$imnum</font>)) {
<font color="#008b8b">$imnum</font> = <font color="#ff00ff">0</font>;
}
<font color="#008b8b">$orig</font> = param(<font color="#ff00ff">'</font><font color="#ff00ff">orig</font><font color="#ff00ff">'</font>);
<font color="#a52a2a"><b>if</b></font>(!<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$imnum</font>)) {
<font color="#008b8b">$orig</font> = <font color="#ff00ff">0</font>;
}
<font color="#a52a2a"><b>select</b></font>(STDOUT);
<font color="#008b8b">$|</font> = <font color="#ff00ff">1</font>;
<font color="#008b8b">@images</font> = (<font color="#ff00ff">"</font><font color="#ff00ff">surfing.jpg</font><font color="#ff00ff">"</font>, <font color="#ff00ff">"</font><font color="#ff00ff">boat.jpg</font><font color="#ff00ff">"</font>, <font color="#ff00ff">"</font><font color="#ff00ff">boston-view.jpg</font><font color="#ff00ff">"</font>, <font color="#ff00ff">"</font><font color="#ff00ff">seashore.jpg</font><font color="#ff00ff">"</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">Content-type: text/html</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><font color=green>Click on the image to make it bigger or smaller<br></font>
<font color="#ff00ff">You can browse through the small images using the buttons or by clicking</font>
<font color="#ff00ff">on the numbers </font></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><table><tr></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$imnum</font> > <font color="#ff00ff">0</font> && <font color="#008b8b">$imnum</font> < <font color="#008b8b">@images</font>) {
<font color="#a52a2a"><b>printf</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><td><a href=album.cgi?imnum=</font><font color="#008b8b">%d</font><font color="#ff00ff">><img src=images/prev.gif border=0></a></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>, <font color="#008b8b">$imnum</font><font color="#ff00ff">-1</font>;
}
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$imnum</font> >= <font color="#ff00ff">0</font> && <font color="#008b8b">$imnum</font> < <font color="#008b8b">@images</font> - <font color="#ff00ff">1</font>) {
<font color="#a52a2a"><b>printf</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><td><a href=album.cgi?imnum=</font><font color="#008b8b">%d</font><font color="#ff00ff">><img src=images/next.gif border=0></a></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>, <font color="#008b8b">$imnum</font><font color="#ff00ff">+1</font>;
}
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><td></font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>for</b></font>(<font color="#008b8b">$i</font> = <font color="#ff00ff">0</font>; <font color="#008b8b">$i</font> < <font color="#008b8b">@images</font>; ++<font color="#008b8b">$i</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><a href=album.cgi?imnum=</font><font color="#008b8b">$i</font><font color="#ff00ff">></font><font color="#008b8b">$i</font><font color="#ff00ff">|</a></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>;
}
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"></tr></table></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$imnum</font> < <font color="#ff00ff">0</font> || <font color="#008b8b">$imnum</font> >= <font color="#008b8b">@images</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><b>No such image</b></font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>exit</b></font>;
}
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$orig</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><a href=album.cgi?imnum=</font><font color="#008b8b">$imnum</font><font color="#ff00ff">><img src=images/</font><font color="#008b8b">$images</font><font color="#ff00ff">[</font><font color="#008b8b">$imnum</font><font color="#ff00ff">] border=0></img></a></font><font color="#6a5acd">\n</font><font color="#ff00ff">"</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#008b8b">$im</font> = GD::Image->newFromJpeg(<font color="#ff00ff">"</font><font color="#ff00ff">images/</font><font color="#008b8b">$images</font><font color="#ff00ff">[</font><font color="#008b8b">$imnum</font><font color="#ff00ff">]</font><font color="#ff00ff">"</font>);
<font color="#0000ff"># create a new image</font>
(<font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>) = <font color="#008b8b">$im</font>->getBounds();
<font color="#008b8b">$newwidth</font> = <font color="#ff00ff">200</font>;
<font color="#008b8b">$newheight</font> = <font color="#ff00ff">200</font>;
<font color="#008b8b">$outim</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>);
<font color="#008b8b">$outim</font>->copyResized(<font color="#008b8b">$im</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>, <font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>);
<font color="#008b8b">$tmpfile</font> = <font color="#ff00ff">"</font><font color="#ff00ff">images/tmp</font><font color="#008b8b">$imnum</font><font color="#ff00ff">.jpg</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>if</b></font> (<font color="#008b8b">$tmpfile</font> =~<font color="#a52a2a"><b> /</b></font><font color="#ff00ff">^</font><font color="#6a5acd">(</font><font color="#ff00ff">[-</font><font color="#6a5acd">\@\w</font><font color="#6a5acd">.</font><font color="#6a5acd">\/</font><font color="#ff00ff">]</font><font color="#6a5acd">+)</font><font color="#ff00ff">$</font><font color="#a52a2a"><b>/</b></font>) { <font color="#0000ff"># For the tainting stuff</font>
<font color="#008b8b">$tmpfile</font> = <font color="#008b8b">$1</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">Should never happen</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>exit</b></font>; <font color="#0000ff"># Should never happen</font>
}
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">TMP</font>, <font color="#ff00ff">"</font><font color="#ff00ff">></font><font color="#008b8b">$tmpfile</font><font color="#ff00ff">"</font>) || <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">Cannot open file</font><font color="#ff00ff">"</font>);
<font color="#a52a2a"><b>binmode</b></font>(TMP);
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">TMP</font> <font color="#008b8b">$outim</font>->jpeg(<font color="#ff00ff">100</font>);
<font color="#a52a2a"><b>close</b></font>(TMP);
<font color="#a52a2a"><b>chmod</b></font>(<font color="#ff00ff">0644</font>, <font color="#008b8b">$tmpfile</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff"><a href=album.cgi?imnum=</font><font color="#008b8b">$imnum</font><font color="#ff00ff">&orig=1><img src=</font><font color="#008b8b">$tmpfile</font><font color="#ff00ff"> border=0></a></font><font color="#ff00ff">"</font>;
}
</pre>
<p>
This script uses a few CGI features. The function param returns the parameter
value, if supplied. This value is used to display the proper image. If
the user wants to see an original image, it is displayed. Otherwise a
temporary resized image is created and displayed.
<p>
A <a href=http://www.cise.ufl.edu/~ppadala/perl/exploring/cgi-bin/album.cgi>demo</a>
of the album is
<a href=http://www.cise.ufl.edu/~ppadala/perl/exploring/cgi-bin/album.cgi>here</a>
<h3> A Graphical Hit Counter </h3>
<p>
Now let us turn our attention to another popular web application "A Hit Counter".
There are many counter scripts available on web. Here's our attempt to
write one.
<p>
The counter works like this. Every time a web-page is accessed, the cgi script
records the hit count and creates an image on-the-fly. So why wait? Let's
write it.
<pre>
Text version of the file can be found <a href=misc/padala/counter.cgi.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -wT</font>
<font color="#a52a2a"><b>use </b></font>CGI <font color="#ff00ff">'</font><font color="#ff00ff">:standard</font><font color="#ff00ff">'</font>;
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>use strict</b></font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$LOCK_SH</font>, <font color="#008b8b">$LOCK_EX</font>, <font color="#008b8b">$LOCK_NB</font>, <font color="#008b8b">$LOCK_UN</font>);
<font color="#008b8b">$LOCK_SH</font> = <font color="#ff00ff">1</font>;
<font color="#008b8b">$LOCK_EX</font> = <font color="#ff00ff">2</font>;
<font color="#008b8b">$LOCK_NB</font> = <font color="#ff00ff">4</font>;
<font color="#008b8b">$LOCK_UN</font> = <font color="#ff00ff">8</font>;
<font color="#a52a2a"><b>select</b></font>(STDOUT);
<font color="#008b8b">$|</font> = <font color="#ff00ff">1</font>;
<font color="#008b8b">&main</font>;
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">main</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$id</font>, <font color="#008b8b">$iformat</font>, <font color="#008b8b">$show</font>);
<font color="#008b8b">$id</font> = param(<font color="#ff00ff">"</font><font color="#ff00ff">id</font><font color="#ff00ff">"</font>);
<font color="#008b8b">$iformat</font> = param(<font color="#ff00ff">"</font><font color="#ff00ff">iformat</font><font color="#ff00ff">"</font>);
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$counter_value</font>);
<font color="#008b8b">$counter_value</font> = <font color="#008b8b">&update_counter_value</font>(<font color="#008b8b">$id</font>);
<font color="#a52a2a"><b>chomp</b></font>(<font color="#008b8b">$counter_value</font>);
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$iformat</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">jpg</font><font color="#ff00ff">"</font> || <font color="#008b8b">$iformat</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">png</font><font color="#ff00ff">"</font>) {
<font color="#008b8b">&print_counter</font>(<font color="#008b8b">$iformat</font>, <font color="#008b8b">$counter_value</font>);
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#008b8b">&print_error_image</font>(<font color="#ff00ff">"</font><font color="#ff00ff">Image format </font><font color="#008b8b">$iformat</font><font color="#ff00ff"> not supported</font><font color="#ff00ff">"</font>);
}
}
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">print_counter</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$iformat</font>, <font color="#008b8b">$counter_value</font>) = <font color="#008b8b">@_</font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$COUNTER_SIZE</font>) = <font color="#ff00ff">4</font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$im</font>) = GD::Image-><font color="#a52a2a"><b>new</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">${iformat}s/0.${iformat}</font><font color="#ff00ff">"</font>);
<font color="#a52a2a"><b>if</b></font>(!<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$im</font>)) {
<font color="#008b8b">&print_error_image</font>(<font color="#ff00ff">"</font><font color="#6a5acd">\$</font><font color="#ff00ff">im couldn't be initialized</font><font color="#ff00ff">"</font>);
<font color="#a52a2a"><b>exit</b></font>;
}
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$w</font>, <font color="#008b8b">$h</font>) = <font color="#008b8b">$im</font>->getBounds();
<font color="#a52a2a"><b>undef</b></font> <font color="#008b8b">$im</font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$printim</font>) = GD::Image-><font color="#a52a2a"><b>new</b></font>(<font color="#008b8b">$w</font> * <font color="#008b8b">$COUNTER_SIZE</font>, <font color="#008b8b">$h</font>);
<font color="#008b8b">$printim</font>->colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>);
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$pos</font>, <font color="#008b8b">$l</font>, <font color="#008b8b">$temp</font>, <font color="#008b8b">$digit</font>, <font color="#008b8b">$x</font>, <font color="#008b8b">$srcim</font>);
<font color="#008b8b">$x</font> = <font color="#ff00ff">0</font>;
<font color="#a52a2a"><b>for</b></font>(<font color="#008b8b">$pos</font> = <font color="#008b8b">$COUNTER_SIZE</font> - <font color="#ff00ff">1</font>; <font color="#008b8b">$pos</font> >= <font color="#ff00ff">0</font>; <font color="#008b8b">$pos</font>--) {
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$pos</font> > <font color="#a52a2a"><b>length</b></font>(<font color="#008b8b">$counter_value</font>) - <font color="#ff00ff">1</font>) {
<font color="#008b8b">$digit</font> = <font color="#ff00ff">0</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#008b8b">$l</font> = <font color="#a52a2a"><b>length</b></font>(<font color="#008b8b">$counter_value</font>);
<font color="#008b8b">$temp</font> = <font color="#008b8b">$l</font> - <font color="#008b8b">$pos</font> - <font color="#ff00ff">1</font>;
<font color="#008b8b">$digit</font> = <font color="#a52a2a"><b>substr</b></font>(<font color="#008b8b">$counter_value</font>, <font color="#008b8b">$temp</font>, <font color="#ff00ff">1</font>);
}
<font color="#008b8b">$srcim</font> = GD::Image-><font color="#a52a2a"><b>new</b></font>(<font color="#ff00ff">"</font><font color="#ff00ff">${iformat}s/${digit}.${iformat}</font><font color="#ff00ff">"</font>);
<font color="#008b8b">$printim</font>->copy(<font color="#008b8b">$srcim</font>, <font color="#008b8b">$x</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$w</font>, <font color="#008b8b">$h</font>);
<font color="#008b8b">$x</font> += <font color="#008b8b">$w</font>;
<font color="#a52a2a"><b>undef</b></font> <font color="#008b8b">$srcim</font>;
}
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$iformat</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">jpg</font><font color="#ff00ff">"</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">Content-type: image/jpeg</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$printim</font>->jpeg(<font color="#ff00ff">100</font>);
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">Content-type: image/png</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$printim</font>->png;
}
}
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">print_error_image</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$error_string</font> = <font color="#008b8b">$_</font>[<font color="#ff00ff">0</font>];
<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(
gdMediumBoldFont->width * <font color="#a52a2a"><b>length</b></font>(<font color="#008b8b">$error_string</font>),
gdMediumBoldFont->height);
<font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>);
<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$red</font> = <font color="#008b8b">$im</font>->colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>);
<font color="#008b8b">$im</font>->string(gdMediumBoldFont, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$error_string</font>, <font color="#008b8b">$red</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">"</font><font color="#ff00ff">Content-type: image/jpeg</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$im</font>->jpeg(<font color="#ff00ff">100</font>);
<font color="#a52a2a"><b>exit</b></font>;
}
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">update_counter_value</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$file_name</font>, <font color="#008b8b">$counter_value</font>);
<font color="#008b8b">$file_name</font> = <font color="#ff00ff">"</font><font color="#008b8b">$_</font><font color="#ff00ff">[0].counter</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>if</b></font> (<font color="#008b8b">$file_name</font> =~<font color="#a52a2a"><b> /</b></font><font color="#ff00ff">^</font><font color="#6a5acd">(</font><font color="#ff00ff">[-</font><font color="#6a5acd">\@\w</font><font color="#6a5acd">.</font><font color="#ff00ff">]</font><font color="#6a5acd">+)</font><font color="#ff00ff">$</font><font color="#a52a2a"><b>/</b></font>) { <font color="#0000ff"># For the tainting stuff</font>
<font color="#008b8b">$file_name</font> = <font color="#008b8b">$1</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#a52a2a"><b>exit</b></font>; <font color="#0000ff"># Should never happen</font>
}
<font color="#a52a2a"><b>if</b></font>(<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#ff00ff">"</font><font color="#ff00ff">+<</font><font color="#008b8b">$file_name</font><font color="#ff00ff">"</font>) == <font color="#ff00ff">0</font>) {
<font color="#0000ff"># Getting accessed for the first time</font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#ff00ff">"</font><font color="#ff00ff">></font><font color="#008b8b">$file_name</font><font color="#ff00ff">"</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">COUNTERFILE</font> <font color="#ff00ff">"</font><font color="#ff00ff">1</font><font color="#ff00ff">"</font>;
<font color="#a52a2a"><b>close</b></font>(COUNTERFILE);
<font color="#a52a2a"><b>return</b></font> <font color="#ff00ff">1</font>;
}
<font color="#a52a2a"><b>flock</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#008b8b">$LOCK_EX</font>);
<font color="#008b8b">$counter_value</font> = <font color="#008b8b"><COUNTERFILE></font>;
<font color="#a52a2a"><b>seek</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>);
++<font color="#008b8b">$counter_value</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">COUNTERFILE</font> <font color="#008b8b">$counter_value</font>;
<font color="#a52a2a"><b>flock</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#008b8b">$LOCK_UN</font>);
<font color="#a52a2a"><b>close</b></font>(COUNTERFILE);
<font color="#a52a2a"><b>return</b></font>(<font color="#008b8b">$counter_value</font> - <font color="#ff00ff">1</font>);
}
</pre>
<p>
This script can be used by adding a line like this in your web page.
<pre>
<img src=counter.cgi?id=my_html_file.html&iformat=jpg>
</pre>
<p>
The id needs to be unique. A sample counter can be seen on my
<a href=http://www.cise.ufl.edu/~ppadala>home page</a>.
<p>
Now to the innards of the script. The counter script has three important
functions.
<pre>
update_counter_value: This function reads the hit count from a file named
html_file.counter and increments it. It creates the
counter file, if one already doesn't exist. It also
locks the file to avoid conflicts due to multiple
simultaneous accesses.
print_counter: Prints the counter by attaching the counter digits in a new
image. The digits are read from an appropriate directory.
print_error_image: This is a useful function to show error images. You
can use it in your programs, for reporting errors
through GD.
</pre>
<p>
You need to have the digits (0-9) in jpg or png format. Sites like
<a href="http://www.counterart.com/">Counter Art dot Com</a> provide free
counter digits. In my next article, I'll discuss how to generate digits on
the fly.
<p>
I developed a <a href=http://pstats.sourceforge.net>personal website statistics</a>
package woven around this counter concept. It provides much more than a simple
counter. It logs the accesses, shows visitor statistics and much more. Check
it out at <a href=http://pstats.sourceforge.net>pstats</a> page.
<p>
You can also use the <a href=http://search.cpan.org/doc/GAAS/File-CounterFile-0.12/CounterFile.pm>File::CounterFile</a>
module for managing the counter file.
<h3> Coming Up.. </h3>
<p>
I hope you enjoyed reading this article. In the coming months, we will look at
GD::Graph and PerlMagick modules. Send me comments at
<a href="mailto:p_padala@yahoo.com">this address</a>.
<p>
Have Fun !!!</a>
<h3> Acknowledgements </h3>
<p>
My best friend <a href=http://www.ece.arizona.edu/~parimi>ravi</a> has become
the official editor for all my writings. I am indebted to him for looking
through all the gibberish I write and make sense out of it. Thanks ravi :-)
<p>
I thank <a href=mailto:ben-fuzzybear@yahoo.com>Benjamin A. Okopnik</a> for
reviewing the article and pointing out some nice perl hacks.
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Pradeep Padala</H4>
<EM>I am a master's student at University of Florida. I love hacking and
adore Linux. My interests include solving puzzles and playing board
games. I can be reached through
<a href="mailto:p_padala@yahoo.com">p_padala@yahoo.com</a> or <a
href="http://www.cise.ufl.edu/~ppadala">my web site</a>.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Pradeep Padala.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Programming in Ruby, part 1</font></H1>
<H4>By <a href="mailto:hiran_rk@rediffmail.com">Hiran Ramankutty</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<H2><B> Introduction </B></H2>
<p>
<p><TD align=right><TD align=left>
Ruby is an interpreted, pure Object Oriented language designed by
Yukihiro Matsumoto of Japan, where it is reported to be more
popular than Python and Perl! The first part of this series is
meant to be a tutorial introduction, with more advanced stuff
in the pipeline.
</TD></TD>
<p>
Of course, I need not go through the ritual of advocating the
`advantages of Ruby compared to languages X, Y and Z' - most people
realize that each language has a unique flavour and character of
its own - whether you choose Python or Ruby for your next open
source project depends more on the peculiar affinity which you as an
individual feel for one over the other, and the availability of
standard library facilities, rather than on arcane technical
issues. So let's enjoy that unique Ruby flavour!
</p>
<H2><B>Requirements</B></H2>
<p>
I presume that your development environment is Linux and you have Ruby installed on
it. Ruby is free software, and there are no restrictions on it's usage. You can
get it from the <a href="http://www.ruby-lang.org"> Ruby Home Page </a>.
</p>
<H2><B>Hello World</B></H2>
<p>
Let's start with the mandatory `Hello, World'.
<pre>
% cat > hello.rb
print "Hello World\n"
^D
% ruby hello.rb
Hello World
%
</pre>
<H2><B>Variables</B></H2>
<p>
Categorization is done on the basis of the first character of the name of the
identifier:
<pre>
$ global variable
@ instance variable
a-z or '_' local variable
A-Z constant
</pre>
<p>
The two `pseudo-variables' are exceptions to the above stated rule. They are `self'
and `nil'.
<ul>
<li> self refers to the currently executing object
<li> nil meaningless or FALSE or value assigned to uninitialized variables
</ul>
<p>
Both are named as if they are local variables, but they are not! We will see their
real meaning later on.
<H2><B>Global variables</B></H2>
<p>
A global variable has it's name starting with $. As such, it can be
referred to from anywhere in the program. It is to be noted that a global variable
assumes the value 'nil' before initialization. You can test this out:
<pre>
% ruby
print $foo,"\n"
$foo = 5
print $foo,"\n"
^D
%
</pre>
The interpreter responds
<pre>
nil
5
</pre>
It is possible for us to `bind' procedures to global variables,
the procedures being automatically invoked when the variable
is changed. More about this later!
<p>
Some special kinds of global variables formed with a single character following a '$'
sign are, as a collection, interpreted by Ruby as major system variables
(made read-only). Some of them are given below along with their meanings.
<ul>
<li> $! latest error message
<li> $@ location of error
<li> $_ string last read by gets
<li> $. line number last read by interpreter
<li> $& string last matched by regexp
<li> $~ the last regexp match, as an array of subexpressions
<li> $n the nth subexpression in the last match (same as $~[n])
<li> $= case-insensitivity flag
<li> $0 the name of the ruby script file
<li> $* the command line arguments
<li> $$ interpreter's process ID
<li> $? exit status of last executed child process
</ul>
<H2><B>Local variables</B></H2>
<p>
A local variable has it's name starting with a lower case letter or an '_'. Unlike
globals and instance variables, they do not assume the value 'nil', but they
behave as shown below:
<pre>
% ruby
print foo
^D
</pre>
You will get an error message:
<pre>
"undefined local variable or method 'foo' for #(object...)".
</pre>
<p>
The scope of a local variable is confined to one of
<ul>
<li> proc {....}
<li> loop {....}
<li> def .... end
<li> class .... end
<li> module .... end
<li> the entire program (unless one of the above applies)
</ul>
If we initialize a local variable in any block(or a procedure), then it remains
undefined after exiting from the loop. For example:
<pre>
def foo(n)
k = 2 * n
print "\n",k,"\n"
print defined? k,"\n"
end
foo 3
print defined? k,"\n"
^D
</pre>
The output is:
<pre>
6
local-variable
nil
</pre>
<p>
In the above example `defined?' is an operator which checks whether it's argument
is defined or not. The results "local-variable" and "nil" (to indicate false) must make it
clear.
</p>
<H2><B>Constants</B></H2>
<p>
Any name with characters following an uppercase letter is treated as a constant. But
Ruby programmers, to avoid confusion, use names with all uppercase letters. So 'Foo' as well
as 'FOO' are constants. As in case of local variables, a constant is defined by a
substitution and an access to an undefined constant or alteration of a defined constant
causes an error. Check for yourself.
<H2><B> Strings </B></H2>
<p>
Strings in ruby can be single quoted('...') or double quoted("...").
But both are different. Use double quotes if the string contains
backslash-escaped characters. Also results of evaluation are
embedded for contained expressions quoted by #{}. See examples:
</p>
<pre>
print "\n"
print '\n'
print "\001","\n"
print '\001',"\n"
print "abcd #{5*3} efg","\n"
var = " abc "
print "1234#{var}567","\n"
^D
\n
\001
abcd 15 efg
1234abc567
</pre>
<p>
We will learn more about strings in the next section, arrays. This is to
include the features that are similar and are held by both arrays and strings.
</p>
<H2><B>Arrays</B></H2>
<p>
Arrays can be quoted using '[]'. One of the features of Ruby is that arrays
are heterogenous.
<pre>
a = [1,2,"3"]
print a,"\n"
^D
</pre>
<p>
Now, if you write a Ruby program to add all the elements of the array shown in the
above program, you will get an error:
<pre>
Error!!String cannot be coerced into Fixnum
</pre>
The `3' in the array is stored as a string. Now, if it is done like this:
<pre>
a = [1,2,"3"]
b = a[0] + a[1] + a[2].to_i
print b,"\n"
^D
</pre>
The program will be executed without any errors. The attachment to a[2] i.e. '.to_i'
is to convert the content of a[2] to an integer.You can also try '.to_s'.
<p>
Operations like concatenation and repetition can be done on arrays.
<pre>
a = [1,2,"3"]
print a + ["foo","bar"]
print a * 2
^D
</pre>
We get
<pre>
123foobar
123123
</pre>
<p>
It's possible to `slice and dice' arrays. Here are some examples:
<pre>
a = [1,2,"3","foo","bar"]
print a[0],"\n"
print a[0,2],"\n"
print a[0..3],"\n"
print a[-2..2],"\n"
print a[-3..-1],"\n"
</pre>
</p>
<p>
Arrays and strings are inter-convertible. An array can be converted to a string
with 'join', and a string is split up into an array with 'split'.
<pre>
a = [1,2,3]
print a[2],"\n"
a = a.join(":")
print a[2],"\n"
print a,"\n"
a = a.split(":")
print a[2],"\n"
print a,"\n"
^D
</pre>
<p>
The Associative Array is another important data structure - it's also
called a `hash' or a `dictionary'. It's basically a name-value mapping,
as shown below:
<pre>
h = {1 => 2, "2" => "4"}
print hash,"\n"
print hash[1],"\n"
print hash["2"],"\n"
print hash[5],"\n"
^D
</pre>
I hope the results are convincing!
</p>
<H2><B>Control structures</B></H2>
<H3><B>If - else</B></H3>
<p>
Let us write the factorial function.The mathematical
definition is:
<pre>
n! = 1 (when n==0)
n! = n * (n-1)! (otherwise)
</pre>
In ruby this can be written as:
<pre>
def fact(n)
if n == 0
1
else
n * fact(n-1)
end
end
print fact 4,"\n"
</pre>
You get 24.
<p>
Ruby has been called `Algol like' because of the repeated
occurrence of `end'. In this recursive call, you may notice the
lack of the return statement. In fact, use of return is
permissible but unnecessary because a ruby function returns
the last evaluated expression (does this sound a wee bit
Lispish? If you insist, you sure can do Lisp in Ruby!)
</p>
<H3><B>The for loop</B></H3>
<p>
<pre>
for i in 0..4
body-of-for
end
</pre>
<p>
Here i is the variable and 0..4 is the range.In the case of
strings, you can very well write:
<pre>
for i in "abc"
</pre>
<H3><B>The while loop</B></H3>
<p>
Try this out
</p>
<pre>
i=0
while i < 10
print i+=1,"\n"
end
</pre>
<H3><B> Case </B></H3>
<p>
We use the case statement to test a sequence of conditions. Try this out.
</p>
<pre>
i = 7
case i
when 1,2..5
print "i in 2 to 5\n"
when 6..10
print "i in 6 to 10\n"
end
^D
</pre>
<p>
You get
</p>
<pre>
i in 6 to 10
</pre>
<p>
2..5 means the range including 2 and 5. It checks whether i falls
within that range.
</p>
<p>
This can be applied to strings as shown below.
</p>
<pre>
case 'abcdef'
when 'aaa','bbb'
print 'contains aaa or bbb \n"
when /def/
print "contains def \n"
end
^D
contains def
</pre>
<p>
Note the slash used with "def". It is used for quoting a regular expression.
We shall see it later.
</p>
<H3><B> Modifications with control structures </B></H3>
<p>
The case statement mentioned just above actually tests for the range
(i in 2..5) as
</p>
<pre>(2..5) === i </pre>
<p>The relationship operator '===' is used by case to check for several
conditions at a time. '===' is interpreted by ruby suitably for the
object that appears in the when condition.
</p>
<p>
Thereby in the example with strings equality is tested with first when
and an expression is matched with the second when.
</p>
<p>
Now try using the operator '===' with if structure(try implementing
functions like isalnum(),isalpha(),isnum() etc.).
</p>
<p>
Your code can be shortened when we have to use if and while constructs
for individual statements: as shown below
</p>
<pre>
i = 7
print "contained in 5..10\n" if (5..10) === i
print i-=1,"\n" while i > 0
^D
contained in 5..10
6
5
4
3
2
1
0
</pre>
<p>
You may at times want to negate the test conditions. An unless is
a negated if, and an until is a negated while. This is left up to you to
experiment with.
</p>
<p>
There are four ways to interrupt the processing of statements of a loop
from inside. First, as in C, break means, to escape from the loop
entirely. Second, next skips to beginning of the next iteration of the
loop (corresponds to continue statement in C). Third ruby has redo,
which restarts the current iteration. The following is C code
illustrating the meanings of break, next, and redo:
</p>
<pre>
while(condition) {
label_redo:
goto label_next; /* ruby's "next" */
goto label_break; /* ruby's "break"*/
goto label_redo; /* ruby's "redo" */
...
...
label_next:
}
label_break:
...
</pre>
<p>
The return statement is actually the fourth way to get out of a loop
from inside. In fact return causes escape not only from the loop
but also from the method that contains the loop.
</p>
<H2><B> Conclusion </B></H2>
We have examined some elementary language features - enough to get
you started with a bit of `quick-and-dirty' coding. As I learn more
about this `gem' of a language, I shall be sharing my experience
with you through future articles. Good bye!
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Hiran Ramankutty</H4>
<EM>I am a final year student of Computer Science at Government Engineering
College, Trichur. Apart from Linux, I enjoy learning Physics.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Hiran Ramankutty.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Process Tracing Using Ptrace</font></H1>
<H4>By <a href="mailto:sk_nellayi@rediffmail.com">Sandeep S</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<EM><B>The ptrace system call is crucial to the working of debugger programs like gdb - yet its behaviour is not very well documented - unless you believe that the best documentation is kernel source itself! I shall attempt to demonstrate how ptrace can be used to implement some of the functionality available in tools like gdb.</B></EM>
<H2><A NAME="s1">1. Introduction</A></H2>
<P><B>ptrace()</B> is a system call that enables one process to control the execution
of another. It also enables a process to change the core image of
another process. The traced process behaves normally until a signal is caught.
When that occurs the process enters stopped state and informs the
tracing process by a <B>wait()</B> call. Then tracing process decides how the
traced process should respond. The only exception is SIGKILL which surely kills
the process.
<P>The traced process may also enter the stopped state in response to some
specific events during its course of execution. This happens only if the
tracing process has set any event flags in the context of the traced process.
The tracing process can even <B>kill</B> the traced one by setting the exit code
of the traced process. After tracing, the tracer process may kill the traced
one or leave to continue with its execution.
<P>
<P><B>Note:</B> Ptrace() is highly dependent on the architecture of the
underlying hardware. Applications using ptrace are not easily portable across
different architectures and implementations.
<P>
<H2><A NAME="s2">2. More Details </A></H2>
<P>The prototype of ptrace() is as follows.
<BLOCKQUOTE><CODE>
<HR>
<PRE>
#include <sys/ptrace.h>
long int ptrace(enum __ptrace_request request, pid_t pid,
void * addr, void * data)
</PRE>
<HR>
</CODE></BLOCKQUOTE>
<P>
<P>Of the four arguments, the value of <B>request</B> decides what to be
done. <B>Pid</B> is the ID of the process to be traced. <B>Addr</B> is the
offset in the user space of the traced process to where the <B>data</B> is
written when instructed to do so. It is the offset in user space of the traced
process from where a word is read and returned as the result of the call.
<P>
<P>The parent can fork a child process and trace it by calling ptrace with
<B>request</B> as PTRACE_TRACEME. Parent can also trace an existing process using
PTRACE_ATTACH. The different values of <B>request</B> are discussed below.
<P>
<H2>2.1 How does ptrace() work.</H2>
<P>Whenever ptrace is called, what it first does is to lock the kernel. Just
before returning it unlocks the kernel. Let's see its working in between
this for different values of <B>request</B>.
<P>
<H3><B>PTRACE_TRACEME</B>:</H3>
<P>This is called when the child is to be traced by the
parent. As said above, any signals (except SIGKILL), either delivered from
outside or from the <B>exec</B> calls made by the process, causes it to stop and
lets the parent decide how to proceed. Inside ptrace(), the only thing that is checked is
whether the ptrace flag of the current process is set. If not, permission
is granted and the flag is set. All the parameters other than <B>request</B> are
ignored.
<P>
<H3><B>PTRACE_ATTACH</B>:</H3>
<P>Here a process wants to control another. One thing to
remember is that nobody is allowed to trace/control the <B>init</B> process.
A process is not allowed to control itself. The current process (caller) becomes
the parent of the process with process ID <B>pid</B>. But a <B>getpid()</B> by the
child (the one being traced) returns the process ID of the real parent.
<P>
<P>What goes behind the scenes is that when a call is made, the usual permission
checks are made along with whether the process is init or current or it is
already traced. If there is no problem, permission is given and the flag
is set. Now the links of the child process are rearranged; e.g., the child is
removed from the task queue and its parent process field is changed (the
original parent remains the same). It is put to the queue again in such a
position that <B>init</B> comes next to it. Finally a SIGSTOP signal is delivered
to it. Here <B>addr</B> and <B>data</B> are ignored.
<P>
<H3><B>PTRACE_DETACH</B>:</H3>
<P>Stop tracing a process. The tracer may decide whether the child should continue
to live. This undoes all the effects made by PTRACE_ATTACH/PTRACE_TRACEME. The
parent sends the exit code for the child in <B>data</B>. Ptrace flag of the child
is reset. Then the child is moved to its original position in the task queue.
The pid of real parent is written to the parent field. The single-step bit
which might have been set is reset. Finally the child is woken up as nothing
had happened to it; <B>addr</B> is ignored.
<P>
<P>
<H3><B>PTRACE_PEEKTEXT, PTRACE_PEEKDATA, PTRACE_PEEKUSER</B>:</H3>
<P>These options read data from child's memory and user space. PTRACE_PEEKTEXT
and PTRACE_PEEKDATA read data from memory and both these options have the same
effect. PTRACE_PEEKUSER reads from the user space of child. A word is read and
placed into a temporary data structure, and with the help of put_user()
(which copies a string from the kernel's memory segment to the
process' memory segment) the required data is written to <B>data</B> and returns
0 on success.
<P>
<P>In the case of PTRACE_PEEKTEXT/PTRACE_PEEKDATA, <B>addr</B> is the address of
the location to be read from child's memory. In PTRACE_PEEKUSER <B>addr</B> is
the offset of the word in child's user space; <B>data</B> is ignored.
<P>
<H3><B>PTRACE_POKETEXT, PTRACE_POKEDATA, PTRACE_POKEUSER</B>:</H3>
<P>These options are analogous to the three explained above. The difference is
that these are used to write the <B>data</B> to the memory/user space of the
process being traced. In PTRACE_POKETEXT and PTRACE_POKEDATA a word from
location <B>data</B> is copied to the child's memory location <B>addr</B>.
<P>
<P>In PTRACE_POKEUSER we are trying to modify some locations in the
<CODE>task_struct</CODE> of the process. As the integrity of the kernel has to be
maintained, we need to be very careful. After a lot of security checks made
by ptrace, only certain portions of the task_struct is allowed to change. Here
<B>addr</B> is the offset in child's user area.
<P>
<H3><B>PTRACE_SYSCALL, PTRACE_CONT</B>:</H3>
<P>Both these wakes up the stopped process. PTRACE_SYSCALL makes the child to
stop after the next system call. PTRACE_CONT just allows the child to continue.
In both, the exit code of the child process is set by the ptrace() where the
exit code is contained in <B>data</B>. All this happens only if the
signal/exit code is a valid one. Ptrace() resets the single step bit of the
child, sets/resets the syscall trace bit, and wakes up the process; <B>addr</B> is ignored.
<P>
<H3><B>PTRACE_SINGLESTEP</B>;</H3>
<P>Does the same as PTRACE_SYSCALL except that the child is stopped after
every instruction. The single step bit of the child is set. As above <B>data</B>
contains the exit code for the child; <B>addr</B> is ignored.
<P>
<H3><B>PTRACE_KILL</B>:</H3>
<P>When the child is to be terminated, PTRACE_KILL may be used. How the murder
occurs is as follows. Ptrace() checks whether the child is already dead or not.
If alive, the exit code of the child is set to <B>sigkill</B>. The single step bit
of the child is reset. Now the child is woken up and when it starts to work it
gets killed as per the exit code.
<P>
<H2>2.2 More machine-dependent calls</H2>
<P>The values of <B>request</B> discussed above were independent on the
architecture and implementation of the system. The values discussed below are
those that allow the tracing process to get/set (i.e., to read/write) the
registers of child process. These register fetching/setting options are more
directly dependent on the architecture of the system. The set of registers
include general purpose registers, floating point registers and extended
floating point registers. These more machine-dependent options are discussed
below. When these options are given, a direct interaction between the
registers/segments of the system is required.
<P> <H3><B>PTRACE_GETREGS,
PTRACE_GETFPREGS, PTRACE_GETFPXREGS</B>:</H3>
<P>These values give the value of general purpose, floating point, extended
floating point registers of the child process. The registers are
read to the location <B>data</B> in the parent. The usual checks for access on the
registers are made. Then the register values are copied to the location
specified by <B>data</B> with the help of getreg() and __put_user() functions;
<B>addr</B> is ignored.
<P>
<H3><B>PTRACE_SETREGS, PTRACE_SETFPREGS, PTRACE_SETFPXREGS</B>:</H3>
<P>These are values of <B>request</B> that allow the tracing process to set the
general purpose, floating point, extended floating point registers of the child
respectively. There are some restrictions in the case of setting the registers.
Some are not allowed to be changed. The data to be copied to the registers will
be taken from the location <B>data</B> of the parent. Here also <B>addr</B> is
ignored.
<P>
<H2>2.3 Return values of ptrace()</H2>
<P>A successful ptrace() returns zero. Errors make it return -1 and set
<B>errno</B>. Since the return value of a successful PEEKDATA/PEEKTEXT may
be -1, it is better to check the <B>errno</B>. The errors are
<P>
<P>EPERM : The requested process couldn't be traced. Permission denied.
<P>
<P>ESRCH : The requested process doesn't exist or is being traced.
<P>
<P>EIO : The request was invalid or read/write was made from/to invalid area
of memory.
<P>
<P>EFAULT: Read/write was made from/to memory which was not really mapped.
<P>
<P>It is really hard to distinguish between the reasons of EIO and EFAULT.
These are returned for almost identical errors.
<P>
<H2><A NAME="s3">3. A small example.</A></H2>
<P>
If you found the parameter description to be a bit dry, don't
despair. I shall not attempt anything of that sort again. I will
try to write simple programs which illustrate many of the
points discussed above.
<P>
<P>Here is the first one. The parent process counts
the number of instructions executed by the test program run by the child.
<P>Here the test program is listing the entries of the current directory.
<P>
<BLOCKQUOTE><CODE>
<HR>
<PRE>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <syscall.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
int main(void)
{
long long counter = 0; /* machine instruction counter */
int wait_val; /* child's return value */
int pid; /* child's process id */
puts("Please wait");
switch (pid = fork()) {
case -1:
perror("fork");
break;
case 0: /* child process starts */
ptrace(PTRACE_TRACEME, 0, 0, 0);
/*
* must be called in order to allow the
* control over the child process
*/
execl("/bin/ls", "ls", NULL);
/*
* executes the program and causes
* the child to stop and send a signal
* to the parent, the parent can now
* switch to PTRACE_SINGLESTEP
*/
break;
/* child process ends */
default:/* parent process starts */
wait(&wait_val);
/*
* parent waits for child to stop at next
* instruction (execl())
*/
while (wait_val == 1407 ) {
counter++;
if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0)
perror("ptrace");
/*
* switch to singlestep tracing and
* release child
* if unable call error.
*/
wait(&wait_val);
/* wait for next instruction to complete */
}
/*
* continue to stop, wait and release until
* the child is finished; wait_val != 1407
* Low=0177L and High=05 (SIGTRAP)
*/
}
printf("Number of machine instructions : %lld\n", counter);
return 0;
}
</PRE>
<HR>
</CODE></BLOCKQUOTE>
<P>
<P>open your favourite editor and write the program. Then run it by typing
<P><CODE>cc file.c</CODE>
<P><CODE>a.out</CODE>
<P>You can see the number of instructions needed for listing of your current
directory. <CODE>cd</CODE> to some other directory and run the program from there
and see whether there is any difference. (note that it may take some time
for the output to appear, if you are using a slow machine).
<P>
<H2><A NAME="s4">4. Conclusion</A></H2>
<P>
<P>Ptrace() is heavily used for debugging. It is also used for system call
tracing. The debugger forks and the
child process created is traced by the parent. The program which is to
be debugged is exec'd by the child (in the above program it was
"ls") and after each instruction the parent can examine the register
values of the program being run. I shall demonstrate programs which
exploit ptrace's versatility in the next part of this series. Good
bye till then.
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Sandeep S</H4>
<EM>I am a final year student of Government Engineering College in Thrissur,
Kerala, India. My areas of interests include FreeBSD, Networking and also
Theoretical Computer Science.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Sandeep S.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Secure and Robust Computer Systems for Primary and Secondary Schools</font></H1>
<H4>By <a href="mailto:rsevenic@netscape.net">Richard A Sevenich</a> and Michael P Angelo</H4>
</center>
<P> <HR> <P>
<!-- END header -->
<P>A wealthy school district will have the
option of purchasing new software and hardware at some appropriate
interval. It may also have the technical staff to install and
maintain the hardware and software. Even in this idealized school
district, the computer system environment is a harsh one, with its
many student users, some of whom start as relatively computer
illiterate and may not have acquired the discipline to follow
administrative rules intended to ameliorate system virus infections
and other external attacks on the system. The technical staff has the
added burden of attempting to maintain system security in this nearly
impossible environment, characterized by intermittent, unplanned
intense work shifts in response to system security disasters.
Providing the necessary level of technical expertise is quite
expensive and consequently rather rare in our school systems. In
fact, many of the primary and secondary schools in the USA have
computer facilities that are in dire straits. Perhaps the major
problems are these two:</P>
<UL>
<LI><P>The networks are plagued by
viruses etc. and suffer significant down time. Further, loss of
files and of attendant work time is routine.</P>
<LI><P>Often the computers are a hodgepodge of donated and purchased
computers with various versions of Microsoft operating systems and
software.</P>
</UL>
<P>Let's consider each of the two problems
in more detail. Cleaning a network of virus infections is a
time-consuming thankless job. Making a system in a school environment
virus proof in practice is probably not possible currently. Other
hostile system attacks (even internal) are quite likely. A teacher
who depends on such a system to be consistently available will be
routinely disappointed.</P>
<P>If we focus on the second problem,
these are its consequences:</P>
<UL>
<LI><P>The various software versions are
not always compatible with each other, so work cannot be dependably
moved from one computer to another.</P>
<LI><P>The original versions of the
software and the corresponding licenses are sometimes missing.
Microsoft is beginning to seize on this issue, requiring an
expensive solution.</P>
</UL>
<P>In this note we propose a
straightforward solution. The idea came to us when we began playing
with version 3.0 of Demo Linux (<A HREF="http://www.demolinux.org/">http://www.demolinux.org</A>).
It provides the start of a solution. When you boot a machine with
Demo Linux, you end up with a machine running Linux from the CD. The
network will be configured as will X Windows. The old Star Office 5.2
is also included. The hard drive may be mounted. We had remarkable
success booting a variety of machines, including laptops, from the
Demo Linux CD.
</P>
<P>Forgetting about the hard drive for the
moment, a school could have such CDs in all their computers and turn
them on each morning to start with a virus-free environment,
compatible software in all machines, and no licensing problems.
Rather than requiring the constant application of security patches,
the system is reborn each day. The solution is not expensive and is
ultimately robust due to its simplicity. Well, it is almost that
simple and convenient, but not quite. Here are three drawbacks:</P>
<OL>
<LI><P>Some system configuration (e.g.
network parameters) is needed at each boot, requiring that somebody
knowledgeable make the appropriate entries. This is time intensive
when the number of systems is large - assuming that a knowledgeable
person is even available.</P>
<LI><P>The hard drive remains a virus
target.</P>
<LI><P>Applications running from the CD
will run relatively slowly; perhaps unacceptably slowly on some
machines.</P>
</OL>
<P>We next suggest solutions to each of
these problems.</P>
<OL>
<LI><P>Automate system
configuration at boot. To implement this we would add a feature to a
clone of Demo Linux. In particular, on the very first boot have the
system configuration choices made by the appropriate sysadmin or
technician and then have the system automatically hard code those
choices by producing an ISO image to be burned onto a new boot CD,
tailored to that specific machine. The new boot CD would
automatically configure the system as desired. Boot CDs could be
updated on whatever schedule the administration would deem
appropriate (e.g. once a year in August).</P>
<LI><P>We'll assume that
the machines at the school do not have an NFS/NIS file sharing
setup. If that assumption were wrong, we would do things a different
way,
We'll further assume that when
this new system is first installed, the hard drive is ours; i.e. any
files stored on the hard drive have been archived by the owner.
We'll propose a severe solution and insist that machine users
either save their daily work on a floppy or transmit it (e.g. via
scp) to a secure machine serving as a repository. The description of
that secure repository machine is outside the scope of this
discussion. Copying work to a floppy or transmitting it to a secure
repository would be made reasonably convenient and intuitive; e.g.
via some GUI interface. The CD boot process would clean all the
prior day's files from the hard drive. This is the aforementioned
severe solution and more involved and intelligent solutions might be
contrived. However, this solution appears to guarantee a virus free
environment at each new boot and is simple. Note that the hard drive
cleaning is not all that time consuming because it involves only
those files created since the previous boot.</P>
<LI><P>Application speed
can be enhanced by having the boot CD move the appropriate
applications to the hard drive during the boot process, after the
hard drive has been cleaned as described in the prior step.</P>
</OL>
<P>It must be admitted that
this approach is not going to produce a well performing system for
very dated machines with limited resources. Open Office, for example,
would not perform well. A small footprint Linux version and other
resource-conserving software could prove viable. Such are available
in the embedded Linux world and could be adapted to resource-limited
machines. This may be too small a market to pursue, however.</P>
<P>We've explored the
preceding ideas for feasibility, tailoring and burning some boot-up
CDs and the like. However, we have various other commitments and
cannot take the concept to full fruition as a polished, flexible
product in a reasonable time frame, although we will continue to work
on it. We see this as having the potential to:
</P>
<UL>
<LI><P>save school
districts a significant amount of money</P>
<LI><P>obviate the
necessity for occasional audits by Microsoft or other vendors</P>
<LI><P>simplify the system
administration task</P>
<LI><P>make systems much
more secure and robust</P>
<LI><P>remove the need to
respond with unplanned, intense work shifts to repair system
security breaches</P>
</UL>
<P>Pretending that such a
product will actually be created, there is the one remaining hurdle -
the initial deployment. School districts with technical personnel
could easily handle the initial CD boot and the creation of the
second, machine-specific boot CD. The cost of the initial
installation would be amortized very quickly. Alternatively, the CD
provider might supply on site initial installation services at a
reasonable cost. Because of the open nature of Linux, other
consultants would become available. Finally, financially hard-pressed
school districts might get such services free from a nearby Linux
User Group.
</P>
<P>Teachers, already
overburdened, will need to learn enough Linux to function. They will
be resistant, because their time is precious. Those of us who
switched to Linux at some point in the past had to travel a learning
curve. However, Linux has progressed to the point where the learning
curve is no longer significant. There are distributions that are
configured to look and act rather like the Microsoft interface. Old
Microsoft Office files can, in most cases, be imported into something
like Open Office and so on. The direct benefits to the teachers
should outweigh the slight pain of conversion.
</P>
<P>We haven't seen this
concept in this form in print before, although all its elements are
out there. Hence, we wanted to put it before the Linux community. If
the proposal bears up under scrutiny and appears viable, we hope some
entity, such as the Demo Linux folks or a Linux distribution, with
appropriate expertise and resources, adopts it as a project. We have
posed it as a solution to certain difficult problems typically faced
by school districts in the USA. Obviously, it could be applied in
other areas. To some extent, time is of the essence - the need and
opportunity are there now.
</P>
<!-- *** BEGIN bio *** -->
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Richard A Sevenich and Michael P Angelo.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Creating Reusable Software Libraries</font></H1>
<H4>By <a href="mailto:robt@robtougher.com">Rob Tougher</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<dl>
<dt><a href=#1>1. Introduction</a>
<dt><a href=#2>2. Making It Easy To Use</a>
<dd><a href=#2.1>2.1 Keeping It Simple</a>
<dd><a href=#2.2>2.2 Being Consistent</a>
<dd><a href=#2.3>2.3 Making It Intuitive</a>
<dt><a href=#3>3. Testing Thoroughly</a>
<dt><a href=#4>4. Providing Detailed Error Information</a>
<dt><a href=#5>5. Conclusion</a>
</dl>
<a name=1></a>
<h3>1. Introduction</h3>
<p>
Software libraries provide functionality to
application developers. They consist of reusable code that
developers can utilize in their projects.
Software libraries targeted for Linux are usually available in both
binary and source code form.
</p>
<p>
A well-written software library:
</p>
<ul>
<li>is easy to use
<li>works flawlessly
<li>provides detailed error information
</ul>
<p>
This article describes the above principles of library creation,
and gives examples in C++.
</p>
<table width=80% border=1>
<tr>
<td bgcolor=#EEEEEE>
<font>
<h4>
Is This Article For You?
</h4>
<p>
Create software libraries only when you have to.
Ask yourself
these questions before proceeding:
</p>
<ul>
<li><i>Will anyone (including you) need functionality X in future applications?</i>
<li><i>If so, does a library implementing functionality X already exist?</i>
</ul>
<p>
If no one will need the functionality you are developing,
or a software library implementing it already exists,
don't create a new library.
</p>
</font>
</td>
</tr>
</table>
<a name=2></a>
<h3>2. Making It Easy To Use</h3>
<p>
The first step in creating a software library is designing
its <b>interface</b>.
Interfaces written in procedural languages, like C, contain
functions. Interfaces written in object-oriented languages,
like C++ and Python, can contain both functions and classes.
</p>
<p>
Remember this motto when designing your interface:
</p>
<ul>
<li><i>The easier to use, the better</i>
</ul>
<p>
As a library designer, I am constantly faced with
finding the right balance between functionality and
ease of use. The above motto helps me resist
adding too much functionality into my designs.
</p>
<p>
Stick with the following guidelines, and you'll be fine.
</p>
<a name=2.1></a>
<h4>2.1 Keeping It Simple</h4>
<p>
The more complex a library, the harder it
is to use.
</p>
<ul>
<li><i>Keep It Simple, Stupid</i>
</ul>
<p>
I recently encountered a C++ library that consisted of
one class. This class contained 150 methods.
<i>150 methods!</i>
The designer was most likely a C veteran using C++ - the
class acted like a C module.
Because this class was so complex, it was
<i>very difficult</i> to learn.
</p>
<p>
Avoid complexity in your designs, and your interfaces will
be cleaner and easier to understand.
</p>
<a name=2.2></a>
<h4>2.2 Being Consistent</h4>
<p>
Users learn consistent interfaces more easily. After learning
the rules once, they feel confident in applying those
rules across all classes and methods, even if they
haven't used those classes and methods before.
</p>
<p>
One example I am guilty of involves public accessors
for private variables. I sometimes do the following:
</p>
<pre>
class point
{
public:
int get_x() { return m_x; }
int set_x ( int x ) { m_x = x; }
int y() { return m_y; }
private:
int m_x, m_y;
};
</pre>
<p>
Do you see the problem here? For the m_x member, the public accessor
is "get_x()", but for the m_y member, the public accessor is
"y()". This inconsistency generates more work for the users - they
have to look up the definition of each accessor before using it.
</p>
<p>
Here's another example of an inconsistent interface:
</p>
<pre>
class DataBase
{
public:
recordset get_recordset ( const std::string sql );
void RunSQLQuery ( std::string query, std::string connection );
std::string connectionString() { return m_connection_string; }
long m_sError;
private:
std::string m_connection_string;
};
</pre>
<p>
Can you spot its problems? I can think of at least
these items:
</p>
<ul>
<li>Methods and variables are not named consistently
<li>Two different terms, <i>sql</i> and <i>query</i>, are
used to denote a SQL string
<li><i>m_sError</i> does not have a public accessor
<li><i>get_recordset()</i> does not have a <i>connection</i> in
its argument list
</ul>
<p>
Here is a revised version that solves these problems:
</p>
<pre>
class database
{
public:
recordset get_recordset ( const std::string sql );
void run_sql_query ( std::string sql );
std::string connection_string() { return m_connection_string; }
long error() { return m_error; }
private:
std::string m_connection_string;
long m_error;
};
</pre>
<p>
Keep your interfaces as consistent as possible - your users will
find them much easier to learn.
</p>
<a name=2.3></a>
<h4>2.3 Making It Intuitive</h4>
<p>
Design an interface how you would expect it to
work from a user's point of view - don't design it
with the internal implementation in mind.
</p>
<p>
I find that the easiest way to design an intuitive interface
is to write code that will use the library <i>before</i> actually
writing the library. This forces me to think about the
library from the user's standpoint.
</p>
<p>
Let's look at an example. I was recently considering writing
an encryption library based
on OpenSSL. Before thinking about the library
design, I wrote some code snippets:
</p>
<pre>
crypto::message msg ( "My data" );
crypto::key k ( "my key" );
// blowfish algorithm
msg.encrypt ( k, crypto::blowfish );
msg.decrypt ( k, crypto::blowfish ):
// rijndael algorithm
msg.encrypt ( k, crypto::rijndael );
msg.decrypt ( k, crypto::rijndael ):
</pre>
<p>
This code helped me think about how I should design the interface -
it put me in the user's shoes. If I decide to implement this
library, my design will flow from these initial ideas.
</p>
<a name=3></a>
<h3>3. Testing Thoroughly</h3>
<p>
A software library should work flawlessly. Well not
<i>flawlessly</i>, but as close to flawless as possible.
Users of a library need to know that the library is performing
its tasks correctly.
</p>
<ul>
<li><i>Why use a software library if it doesn't work correctly?</i>
</ul>
<p>
I test my software libraries using automated scripts.
For each library, I create a corresponding
application that exercises all features of the library.
</p>
<p>
For example, say I decided to develop the encryption
library I introduced in the previous section. My test
application would look like the following:
</p>
<pre>
#include "crypto.hpp"
int main ( int argc, int argv[] )
{
//
// 1. Encrypt, decrypt, and check
// message data.
//
crypto::message msg ( "Hello there" );
crypto::key k ( "my key" );
msg.encrypt ( k, crypto::blowfish );
msg.decrypt ( k, crypto::blowfish );
if ( msg.data() != "Hello there" )
{
// Error!
}
//
// 2. Encrypt with one algorithm,
// decrypt with another, and check
// message data.
//
// etc....
}
</pre>
<p>
I would occasionally run this application to make
sure that my software library did not have any major
errors.
</p>
<a name=4></a>
<h3>4. Providing Detailed Error Information</h3>
<p>
Users need to know when a software library cannot perform
its tasks correctly.
</p>
<ul>
<li><i>Alert the user when there is a problem</i>
</ul>
<p>
Software libraries written in C++ use
<b>exceptions</b> to pass information to its
users. Consider the following example:
</p>
<pre>
#include <string>
#include <iostream>
class car
{
public:
void accelerate() { throw error ( "Could not accelerate" ); }
};
class error
{
public:
Error ( std::string text ) : m_text ( text ) {}
std::string text() { return m_text; }
private:
std::string m_text;
};
int main ( int argc, int argv[] )
{
car my_car;
try
{
my_car.accelerate();
}
catch ( error& e )
{
std::cout << e.text() << "\n";
}
}
</pre>
<p>
The <i>car</i> class uses the <b>throw</b> keyword to
alert the caller to an erroneous situation. The caller
catches this exception with the <b>try</b> and
<b>catch</b> keywords, and deals with the problem.
</p>
<p>
</p>
<a name=5></a>
<h3>5. Conclusion</h3>
<p>
In this article I explained the important principles
of well-written software libraries.
Hopefully I've explained everything clearly enough so
that you can incorporate these principles into your
own libraries.
</p>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Rob Tougher</H4>
<EM>Rob is a C++ software engineer in the New York City area.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Rob Tougher.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">SysRq: The Process-nuke</font></H1>
<H4>By <a href="mailto:vikasgp386@hotmail.com">Vikas G P</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<p>
So you thought you could always kill an offending program with <code>kill -9</code> ?
But what if it's your X server that has crashed, or that nifty svgalib program
you wrote ? That's where magic SysRq comes in.
<p>
<h2>What is it</h2>
<p>
Magic SysRq is a key combination directly intercepted by the kernel and
can be used, among other things, to perform an emergency shutdown. It is
described in Documentation/sysrq.txt and implemented in drivers/char/sysrq.c
in the kernel source tree. It exists primarily for kernel hackers, but it can be
useful to people in user-space also. Since it is implemented as a part of the
<a href="http://www.linuxjournal.com/article.php?sid=1080">keyboard driver,</a>
it is guaranteed to work most of the time, unless the
kernel itself is dead.
<p>
A note: In the rest of this article, when I say "SysRq key" I mean the single key
beside the Scroll lock key. But when I say "magic SysRq" I mean the <em>combination
</em>< Alt+SysRq >.
<p>
<h2>Enabling</h2>
<p>
To do the SysRq magic, your kernel needs to be compiled with CONFIG_MAGIC_SYSRQ.
Most distributions would have enabled it by default. If your's hasn't, you'll
just have to
<A href="http://www.tldp.org/HOWTO/Kernel-HOWTO.html">recompile</a>... :)</p>
<p>
After everything is OK with the kernel, check if SysRq is enabled by default.
</p>
<pre>
$ cat /proc/sys/kernel/sysrq
0
</pre>
If it shows zero, it's not enabled. Writing any non-zero value to
/proc/sys/kernel/sysrq will enable it.
<pre>
$ echo "1" > /proc/sys/kernel/sysrq
</pre>
If you want it to be always enabled, append these lines to one of your initialization
scripts(preferably rc.local).
<pre>
#Enable SysRq
echo -e "Enabling SysRq\n"
echo "1" > /proc/sys/kernel/sysrq
</pre>
<p>
Alternatively, you might look for a file called /etc/sysctl or /etc/sysctl.conf
which some distributions have(mine, RedHat, does). You can add a line like this to
it, and sysrq will be enabled at boot-time.
<pre>
kernel.sysrq = 1
</pre>
<p>
The magic SysRq combination is a unique one. Now, every key on the keyboard sends
a code when pressed or released, called the scan-code. The magic SysRq combination
(Alt+SysRq), however, sends only <em>one</em> scan-code(0x54, decimal 84) even though
two keys have been pressed. Check this out using <code>showkey -s</code>.
<p>
<h2>What can I do with it ?</h2>
<p>
Magic SysRq is invoked as < Alt+SysRq > + < command >. The SysRq key is
also labelled as Print Screen. The commands are:
<p>
k: Secure access key - This kills all processes running on the current virtual
console, so that no snoopy program can grab your keystrokes while you type your
password.
<p>
u: Attempts to unmount the root device, and remount it read-only. In addition to an
emergency shutdown, this command also comes in handy if you have only
one partition for Linux and need to do an fsck or low-level filesystem
editing(for example, ext2 undeletion. See
<a href="http://www.tldp.org/HOWTO/mini/Ext2fs-Undeletion.html">
Ext2fs Undeletion Howto</a>
<p>
s: This command syncs the kernel buffers to disk. You should do this
before unmounting.
<p>
b: Does an immediate reboot, pretty much like pressing the reset button. For a
safe shutdown, precede this with a sync and Unmount.
<p>
p: Prints the contents of the CPU registers.
<p>
m: Shows memory information.
<p>
t: Shows information about the tasks currently running.
<p>
0-9: Sets the console log-level to the specified number.
<p>
e: Sends a SIGTERM to all processes, except init.
<p>
i: Sends a SIGKILL(sure kill) to all processes, except init.
<p>
l: Sends a SIGKILL to all processes, including init(you won't be able to anything
after this).
<p>
<h2>Getting out</h2>
<p>
How do you get out of SysRq mode ? There is no definite documentation about this in
sysrq.txt. It talks about having to press the left and right control,alt and
shift keys, but a simpler thing worked for me. Just press Alt+SysRq once again,
and you'll get out of it.
<p>
The way I understand this is:
The kernel remembers the state of the magic SysRq combination: it's either down or
up. When you press the key for the first time, the state is changed to down. And when
you press any other key while SysRq's state is down, the kernel interprets it
as a command. If you press SysRq again, the state is changed to up, and further
keystrokes are handed to whatever program requests it.
<br>
(Actually, it's not that simple. Sometimes, the above mentioned method doesn't work.
I believe it's because the kernel uses a separate translation table when magic SysRq
is down.)
<p>
The SysRq key originally meant, as you can guess, "System Request". It was used by
early IBM terminals to get the attention of a central computer to execute a command.
The key seems to have few uses now, except in the linux kernel.
<p>
<h2> Security</h2>
<p>
Leaving magic SysRq enabled on a production machine can be potentially
dangerous. Anyone with physical access to the machine can bring it
down instantly.<br>
You should also disable SysRq if other people can log in to your system
remotely. A < break > sent from a remote console will be interpreted
as < Alt+SysRq >, and the consequences can be disastrous. See the
<a href="http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/index.html">
Remote-Serial-Console-HOWTO
</a> for more details.
<p>
<h2>Conclusion</h2>
<p>
The magic SysRq hack can come in very handy at times. However, it must be used
with care. It can also give you some insights into the inner workings of the kernel.
If you are enterprising, you might even hack the kernel and add new commands !
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Vikas G P</H4>
<EM>I'm in the last year of high school and live in Hassan, Karnataka in India,
trying to balance my studies and linuxing.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright © 2002, Vikas G P.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <hr> <P>
<H1><font color="maroon">The Back Page</font></H1>
<ul>
<li><a HREF="#reunion">LG Reunion</a>
<li><a HREF="#wacko">Wacko Topic of the Month</a>
</ul>
<a name="reunion"></a>
<P> <hr> <P>
<!--====================================================================-->
<center><H3><font color="maroon">LG Reunion</font></H3></center>
<P> <HR> <P>
<!--======================================================================-->
<P>
<IMG ALT="[picture]" SRC="misc/backpage/chester.jpg" WIDTH="601" HEIGHT="315">
<BR CLEAR="all">
<P> That's me, Didier from Belgium (of The Answer Gang fame) and Mick from
Ireland (of News Bytes fame) in Chester, England during my UK trip in July. We
spent the day in Chester walking on the medieval wall, looking at Roman
columns, and visiting the Roman amphitheater and the Chester Cathedral. More
pictures from my trip are at
<A HREF="http://iron.cx/pix/">http://iron.cx/pix/</A> in the 2002 section.
<a name="wacko"></a>
<P> <hr> <P>
<!--====================================================================-->
<center><H3><font color="maroon">Wacko Topic of the Month</font></H3></center>
<P> <HR> <P>
<!--======================================================================-->
<P>
<P> All this talk about England reminded Ben of a pseudo-<EM>Beowulf</EM>
quote his <CODE>fortune</CODE> program doth said once:
<BLOCKQUOTE><PRE>
Meanehwael, baccat meaddehaele, monstaer lurccen;
Fulle few too many drincce, hie luccen for fyht.
[D]en Hreorfneorht[d]hwr, son of Hrwaerow[p]heororthwl,
AEsccen aewful jeork to steop outsyd.
[P]hud! Bashe! Crasch! Beoom! [D]e bigge gye
Eallum his bon brak, byt his nose offe;
Wicced Godsylla waeld on his asse.
Monstaer moppe fleor wy[p] eallum men in haelle.
Beowulf in bacceroome fonecall bemaccen waes;
Hearen sond of ruccus saed, "Hwaet [d]e helle?"
Graben sheold strang ond swich-blaed scharp
Sond feorth to fyht [d]e grimlic foe.
"Me," Godsylla saed, "mac [d]e minsemete."
Heoro cwyc geten heold wi[p] faemed half-nelson
Ond flyng him lic frisbe bac to fen.
Beowulf belly up to meaddehaele bar,
Saed, "Ne foe beaten mie faersom cung-fu."
Eorderen cocca-colha yce-coeld, [d]e reol [p]yng.
-- Not Chaucer, for certain
</PRE></BLOCKQUOTE>
<P> If that's not wacko enough, see this
<A HREF="http://www.gilchriststudios.com/nancy/images/061802.gif">Nancy cartoon</A>.
<HR> <!-- ************************************************************** -->
<P> Happy Linuxing!
<P> Mike ("Iron") Orr<br>
Editor, <A HREF="http://www.linuxgazette.com/"><i>Linux Gazette</i></A>, <A
HREF="mailto:gazette@ssc.com">gazette@ssc.com</a>
<BR CLEAR="all">
<!-- *** END Not Linux *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <P>
<H5 ALIGN=center>
Copyright © 2002, the Editors of <I>Linux Gazette</I>.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
</BODY></HTML>
|