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
|
diff --git a/FEATURE-REMOVAL-SCHEDULE b/FEATURE-REMOVAL-SCHEDULE
new file mode 100644
index 0000000..50c81f8
--- /dev/null
+++ b/FEATURE-REMOVAL-SCHEDULE
@@ -0,0 +1,70 @@
+The following is a list of files and features that are going to be removed in
+the source tree. Every entry should contain what exactly is going away, why it
+is happening, and who is going to be doing the work. When the feature is
+removed, it should also be removed from this file.
+
+---------------------------
+
+What: rc_sys automatic detection code
+ - Functions for removal: rc_sys_v1, rc_sys_v2
+
+When: 2011/03/01
+
+Why: The original automatic sub-system detection is flawed in that it cannot
+ safely detect some variables (Using cgroups confused it to think you were
+ using LXC, and Prefix cannot be detect by definition). Also, almost all of
+ the detection requires that /proc is available and readable. During early
+ boot, /proc may not be mounted yet, leading to mis-detection. The readable
+ condition can also fail under some hardened kernels when running as an
+ unprivileged user.
+
+ The new rc_sys_v2 function uses the rc_sys variable from rc.conf. After
+ the removal, the contents of the rc_sys_v2 function will move into the
+ rc_sys function.
+
+Who: Robin H. Johnson <robbat2@gentoo.org>
+
+---------------------------
+
+What: oldnet ADSL rp-pppoe mode
+
+When: undecided
+
+Why: Replaced by the oldnet PPP module
+
+Who: Robin H. Johnson <robbat2@gentoo.org>
+
+---------------------------
+
+What: oldnet /etc/conf.d/wireless
+
+When: undecided
+
+Why: All configuration moved to /etc/conf.d/net
+
+Who: Robin H. Johnson <robbat2@gentoo.org>
+
+---------------------------
+
+What: Service pause action
+
+When: Removed already, compatbility warning in place.
+
+Why: ...
+
+Who:
+
+---------------------------
+
+What: Service --startas, --chuid , --oknodo
+
+When: undecided
+
+Why: Obsolete or replaced by other options.
+ --startas => use --name or --exec
+ --chuid => use --user
+ --oknodo => ignore return code instead
+
+Who:
+
+---------------------------
diff --git a/Makefile b/Makefile
index 8f9cc95..dd427d0 100644
--- a/Makefile
+++ b/Makefile
@@ -4,23 +4,18 @@
include Makefile.inc
-SUBDIR= conf.d etc init.d man scripts sh src
+SUBDIR= conf.d etc init.d local.d man scripts sh src
# Build our old net foo or not
-_OLDNET_SH= case "${MKOLDNET}" in \
- [Yy][Ee][Ss]) echo "net doc";; \
- *) echo "";; \
- esac
-_OLDNET!= ${_OLDNET_SH}
-SUBDIR+= ${_OLDNET}$(shell ${_OLDNET_SH})
+ifeq (${MKOLDNET},yes)
+SUBDIR+= net doc
+endif
# Build pkgconfig or not
-_PKGCONFIG_SH= case "${MKPKGCONFIG}" in \
- [Yy][Ee][Ss]|"") echo "pkgconfig";; \
- *) echo "";; \
- esac
-_PKGCONFIG!= ${_PKGCONFIG_SH}
-SUBDIR+= ${_PKGCONFIG}$(shell ${_PKGCONFIG_SH})
+MKPKGCONFIG?= yes
+ifeq (${MKPKGCONFIG},yes)
+SUBDIR+= pkgconfig
+endif
# We need to ensure that runlevels is done last
SUBDIR+= runlevels
diff --git a/README b/README
index 07f181f..2a2eac3 100644
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ OpenRC README
Installation
------------
make install
-Yup, that simple. Works with GNU make and BSD make.
+Yup, that simple. Works with GNU make.
You may wish to tweak the installation with the below arguments
PROGLDFLAGS=-static
@@ -12,6 +12,7 @@ LIBNAME=lib64
DESTDIR=/tmp/openrc-image
MKPAM=pam
MKPKGCONFIG=no
+MKSELINUX=yes
MKTERMCAP=ncurses
MKTERMCAP=termcap
MKOLDNET=yes
diff --git a/README.net b/README.net
deleted file mode 100644
index 41db1c5..0000000
--- a/README.net
+++ /dev/null
@@ -1,36 +0,0 @@
-OpenRC Network Ideals
----------------------
-
-The new style networking for OpenRC is very simplistic - provide a basic means
-of configuring static interface address and routes whilst allowing the
-possibility to run any command at any point.
-
-In a nutshell, init.d/network is a wrapper around ifconfig(8) and
-init.d/staticroute is wrapper around route(8).
-
-In the Perfect World (TM) ifconfig should be able to configure everything
-about the interface easily * . The BSD family almost get this right and Linux
-epically fails.
-
-* Only static configuration, including link setup.
-For dynamic, static, IPv4LL, arping and per ssid IPv4 setup dhcpcd-5.x
-provides your needs.
-
-It fails because there are many tools to do the same job and often have
-vastly different syntax where they could be similar. In other words, there
-is no coherence.
-
-OpenRC-0.4.x and older (inc Gentoo baselayout-1) had a collection of scripts
-for each tool and allowed a script per interface. Over the years, this design
-has proven very hard to maintain as each user has their own idea of how
-things should work. Also, there were (and still are) race conditions.
-
-So where do we go from here?
-Well, it's possible to use the new network scripts using the tools
-currently available. It's just harder as you have to know them and their
-documentation can be lacking at times.
-The correct end goal is a BSD style ifconfig tool.
-I've started work on it, but the project has stalled somewhat.
-It's display only right now and the source is not yet publicly available.
-If you have the skills and share the vision then contact me privately and
-we'll take it from there.
diff --git a/README.newnet b/README.newnet
new file mode 100644
index 0000000..2e157e2
--- /dev/null
+++ b/README.newnet
@@ -0,0 +1,40 @@
+The following applies only to the newnet stack, which is not presently
+maintained in OpenRC. The oldnet stack is maintained instead.
+- Robin H. Johnson <robbat2@gentoo.org>, 2011/02/21
+
+OpenRC Network Ideals
+---------------------
+
+The new style networking for OpenRC is very simplistic - provide a basic means
+of configuring static interface address and routes whilst allowing the
+possibility to run any command at any point.
+
+In a nutshell, init.d/network is a wrapper around ifconfig(8) and
+init.d/staticroute is wrapper around route(8).
+
+In the Perfect World (TM) ifconfig should be able to configure everything
+about the interface easily * . The BSD family almost get this right and Linux
+epically fails.
+
+* Only static configuration, including link setup.
+For dynamic, static, IPv4LL, arping and per ssid IPv4 setup dhcpcd-5.x
+provides your needs.
+
+It fails because there are many tools to do the same job and often have
+vastly different syntax where they could be similar. In other words, there
+is no coherence.
+
+OpenRC-0.4.x and older (inc Gentoo baselayout-1) had a collection of scripts
+for each tool and allowed a script per interface. Over the years, this design
+has proven very hard to maintain as each user has their own idea of how
+things should work. Also, there were (and still are) race conditions.
+
+So where do we go from here?
+Well, it's possible to use the new network scripts using the tools
+currently available. It's just harder as you have to know them and their
+documentation can be lacking at times.
+The correct end goal is a BSD style ifconfig tool.
+I've started work on it, but the project has stalled somewhat.
+It's display only right now and the source is not yet publicly available.
+If you have the skills and share the vision then contact me privately and
+we'll take it from there.
diff --git a/STYLE b/STYLE
new file mode 100644
index 0000000..f1ae5c1
--- /dev/null
+++ b/STYLE
@@ -0,0 +1,34 @@
+This is the openrc style manual. It governs the coding style of all code
+in this repository. Follow it. Contact openrc@gentoo.org for any questions
+or fixes you might notice.
+
+##########
+# C CODE #
+##########
+
+The BSD Kernel Normal Form (KNF) style is used:
+ http://en.wikipedia.org/wiki/Indent_style#BSD_KNF_style
+Basically, it's like K&R/LKML, but wrapped lines that are indented use 4 spaces.
+
+Highlights:
+ - no trailing whitespace
+ - indented code use tabs (not line wrapped)
+ - cuddle the braces (except for functions)
+ - space after native statements and before paren (for/if/while/...)
+ - no space between function and paren
+ - pointer asterisk cuddles the variable, not the type
+
+void foo(int c)
+{
+ int ret = 0;
+
+ if (c > 1000)
+ return;
+
+ while (c--) {
+ bar(c);
+ ret++;
+ }
+
+ return ret;
+}
diff --git a/TODO b/TODO
index e008fca..4309aa0 100644
--- a/TODO
+++ b/TODO
@@ -3,3 +3,5 @@
- add support somehow for optional translations
- oldnet[bridging]: Review setting of bridge configuration on dynamic interface add
+
+- Document rc-depend binary.
diff --git a/conf.d/Makefile b/conf.d/Makefile
index 034dc74..374bfdb 100644
--- a/conf.d/Makefile
+++ b/conf.d/Makefile
@@ -1,5 +1,5 @@
DIR= ${CONFDIR}
-CONF= bootmisc fsck hostname local localmount network staticroute urandom
+CONF= bootmisc fsck hostname localmount network staticroute urandom
TARGETS+= network staticroute
CLEANFILES+= network staticroute
diff --git a/conf.d/hwclock b/conf.d/hwclock
index 5321ba1..4e66ff9 100644
--- a/conf.d/hwclock
+++ b/conf.d/hwclock
@@ -9,6 +9,14 @@ clock="UTC"
# You normally don't need to do this if you run a ntp daemon.
clock_systohc="NO"
+# If you want to set the system time to the current hardware clock
+# during bootup, then say "YES" here. You do not need this if you are
+# running a modern kernel with CONFIG_RTC_HCTOSYS set to y.
+# Also, be aware that if you set this to "NO", the system time will
+# never be saved to the hardware clock unless you set
+# clock_systohc="YES" above.
+clock_hctosys="YES"
+
# If you wish to pass any other arguments to hwclock during bootup,
# you may do so here. Alpha users may wish to use --arc or --srm here.
clock_args=""
diff --git a/conf.d/local b/conf.d/local
deleted file mode 100644
index 97dbbcc..0000000
--- a/conf.d/local
+++ /dev/null
@@ -1,18 +0,0 @@
-# Here is where you can put anything you need to start
-# that there is not an init script for.
-
-local_start() {
- # This is a good place to load any misc programs
- # on startup (use &>/dev/null to hide output)
-
- # We should always return 0
- return 0
-}
-
-local_stop() {
- # This is a good place to unload any misc.
- # programs you started above.
-
- # We should always return 0
- return 0
-}
diff --git a/doc/net.example.BSD.in b/doc/net.example.BSD.in
index 977011e..287c644 100644
--- a/doc/net.example.BSD.in
+++ b/doc/net.example.BSD.in
@@ -23,7 +23,7 @@
# We now support modular networking scripts which means we can easily
# add support for new interface types and modules while keeping
# compatibility with existing ones.
-#
+#
# Modules load by default if the package they need is installed. If
# you specify a module here that doesn't have its package installed
# then you get an error stating which package you need to install.
@@ -212,7 +212,7 @@
# not find them in a scan
# "forcepreferredonly" means it forcibly connects to the APs in order and
# does not bother to scan
-# "forceany" does the same as forcepreferred + connects to any other
+# "forceany" does the same as forcepreferred + connects to any other
# available AP
# Default is "any"
#associate_order="any"
@@ -266,13 +266,13 @@
# won't have associated then)
# If you're using anything else to configure wireless on your interface AND
-# you have installed wpa_supplicant, you need to disable wpa_supplicant
+# you have installed wpa_supplicant, you need to disable wpa_supplicant
#modules="!iwconfig !wpa_supplicant"
#or
#modules="!wireless"
##############################################################################
-# WIRELESS SSID IN VARIABLES
+# WIRELESS SSID IN VARIABLES
##############################################################################
# Remember to change SSID to your SSID.
# Say that your SSID is My NET - the line
@@ -368,7 +368,7 @@
##############################################################################
# ADVANCED CONFIGURATION
-#
+#
# Four functions can be defined which will be called surrounding the
# start/stop operations. The functions are called with the interface
# name first so that one function can control multiple adapters. An extra two
diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index 42e5477..69c9ba6 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -24,7 +24,7 @@
# We now support modular networking scripts which means we can easily
# add support for new interface types and modules while keeping
# compatibility with existing ones.
-#
+#
# Modules load by default if the package they need is installed. If
# you specify a module here that doesn't have its package installed
# then you get an error stating which package you need to install.
@@ -49,7 +49,7 @@
##############################################################################
# INTERFACE HANDLERS
-#
+#
# We provide two interface handlers presently: ifconfig and iproute2.
# You need one of these to do any kind of network configuration.
# For ifconfig support, emerge sys-apps/net-tools
@@ -297,7 +297,7 @@
# Surround each SSID with the " character and separate them with a space
# If the first SSID isn't found then it moves onto the next
# If this isn't defined then it connects to the first one found
-#preferred_aps="SSID1 SSID2"
+#preferred_aps="SSID1 SSID2"
# You can also define a preferred_aps list per interface
#preferred_aps_eth0="SSID3 SSID4"
@@ -371,13 +371,13 @@
# won't have associated then)
# If you're using anything else to configure wireless on your interface AND
-# you have installed wpa_supplicant, you need to disable wpa_supplicant
+# you have installed wpa_supplicant, you need to disable wpa_supplicant
#modules="!iwconfig !wpa_supplicant"
#or
#modules="!wireless"
##############################################################################
-# WIRELESS SSID IN VARIABLES
+# WIRELESS SSID IN VARIABLES
##############################################################################
# Remember to change SSID to your SSID.
# Say that your SSID is My NET - the line
@@ -421,7 +421,7 @@
# Notes:
# - All clients send the current hostname to the DHCP server by default
# - dhcpcd does not daemonize when the lease time is infinite
-# - udhcp-0.9.3-r3 and earlier do not support getting NTP servers
+# - udhcp-0.9.3-r3 and earlier do not support getting NTP servers
# - pump does not support getting NIS servers
# - DHCP tends to erase any existing device information - so add
# static addresses after dhcp if you need them
@@ -467,7 +467,7 @@
#fallback_eth0="apipa"
#-----------------------------------------------------------------------------
-# ARPING Gateway configuration
+# ARPING Gateway configuration
# and
# Automatic Private IP Addressing (APIPA)
# For arpingnet / apipa support, emerge net-misc/iputils or net-analyzer/arping
@@ -527,7 +527,8 @@
#-----------------------------------------------------------------------------
# VLAN (802.1q support)
-# For VLAN support, emerge net-misc/vconfig
+# For VLAN support, emerge sys-apps/iproute2
+# The old vconfig based VLAN support is no longer available.
# Specify the VLAN numbers for the interface like so
# Please ensure your VLAN IDs are NOT zero-padded
@@ -537,10 +538,17 @@
# need it up.
#config_eth0="null"
-# You can also configure the VLAN - see for vconfig man page for more details
-#vconfig_eth0="set_name_type VLAN_PLUS_VID_NO_PAD"
-#vconfig_vlan1="set_flag 1
-#set_egress_map 2 6"
+# You can also configure the VLAN - see for ip man page for more details
+# To change the vlan interface name. If not set, the standard "iface.vlanid"
+# will be used
+#vlan1_name="vlan1"
+#vlan2_name="eth0.2"
+# Set the vlan flags
+#vlan1_flags="reorder_hdr off gvrp on loose_binding on"
+# Configure in/egress maps
+#vlan1_ingress="2:6 3:5"
+#vlan1_egress="1:2"
+
#config_vlan1="172.16.3.1/23"
#config_vlan2="172.16.2.1/23"
@@ -553,8 +561,7 @@
# This means you do not need to create init scripts in /etc/init.d for each
# vlan, you must need to create one for the physical interface.
# If you wish to control the configuration of each vlan through a separate
-# script, or wish to rename the vlan interface to something that vconfig
-# cannot then you need to do this.
+# script then you need to do this.
#vlan_start_eth0="no"
# If you do the above then you may want to depend on eth0 like so
@@ -582,7 +589,7 @@
#-----------------------------------------------------------------------------
-# Classical IP over ATM
+# Classical IP over ATM
# For CLIP support emerge net-dialup/linux-atm
# Ensure that you have /etc/atmsigd.conf setup correctly
@@ -620,7 +627,7 @@
#
# Here you should specify what pppd plugins you want to use
# Available plugins are: pppoe, pppoa, capi, dhcpc, minconn, radius,
-# radattr, radrealms and winbind
+# radattr, radrealms and winbind
#plugins_ppp0="pppoe" # Required plugin for PPPoE
#plugins_ppp0="pppoa vc-encaps" # Required plugin for PPPoA with an option
#plugins_ppp0="capi" # Required plugin for ISDN
@@ -660,7 +667,7 @@
# lcp-echo-interval 15 # Send a LCP echo every 15 seconds
# lcp-echo-failure 3 # Make peer dead after 3 consecutive
# # echo-requests
-#
+#
# Compression options - use these to completely disable compression
# noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp
#
@@ -793,7 +800,7 @@
# empty value variable is fine, but at least one of them must be set:
# brctl_IFVAR
-# You need to configure the ports to null values so dhcp does not get started
+# You need to configure the ports to null values so dhcp does not get started
#config_eth0="null"
#config_eth1="null"
@@ -820,7 +827,7 @@
#hairpin_mode_eth0="1"
#-----------------------------------------------------------------------------
-# RFC 2684 Bridge Support
+# RFC 2684 Bridge Support
# For RFC 2684 bridge support emerge net-misc/br2684ctl
# Interface names have to be of the form nas0, nas1, nas2, etc.
@@ -973,9 +980,75 @@
#ifplugd_eth0="--api-mode=wlan"
# man ifplugd for more options
+#-----------------------------------------------------------------------------
+# Interface hardware tuning & configuration via ethtool
+# If you need to change explicit hardware settings on your network card prior
+# to bringing the interface up, the following is available.
+#
+# For a full listing of settings, please consulting ethtool(8) and the output
+# of "ethtool --help".
+#
+# Multiple entries (seperated by newlines) are supported in all of the
+# variables as some settings cannot be changed at the same time.
+#
+# Valid variable name fragments: change pause coalesce ring offload
+# change_eeprom identify nfc flash rxfh_indir ntuple
+
+# Set Wake-On-Lan to listen for SecureOn MagicPacket(tm), the message level to
+# notify us of WOL changes, and the SecureOn password to 'DE:AD:BE:EF:CA:FE'.
+#ethtool_change_eth0="wol gs
+#msglvl wol on
+#sopass DE:AD:BE:EF:CA:FE"
+
+# Disable pause auto-negotiation and explicitly enable RX and TX pause.
+#ethtool_pause_eth0="autoneg off
+#rx on tx on"
+
+# Enasble adaptive RX and TX coalescing
+#ethtool_coalesce_eth0="adaptive-rx on adaptive-tx on"
+
+# Change ring buffer settings
+#ethtool_ring_eth0=""
+
+# Enable all offload settings
+#ethtool_offload_eth0="rx on tx on sg on tso on ufo on gso on gro on lro on"
+
+# Change specific bytes in the EEPROM
+#ethtool_change_eeprom_eth0=""
+
+# Run the identify sequence on the interface for 1 second (does not return until completion)
+#ethtool_identify_eth0="1"
+
+# Configure receive network flow classification
+#ethtool_nfc_eth0="
+#rx-flow-hash tcp4 f
+#rx-flow-hash udp4 s"
+
+# Flash firmware to all regions
+#ethtool_flash_eth0="/some/path/firmware1 0"
+
+# Flash firmware to region 1
+#ethtool_flash_eth0="/some/path/firmware2 1"
+
+# Set receive flow hash indirection table for even balancing between N receive queues
+#ethtool_rxfh_indir_eth0="equal 4"
+
+# Configure Rx ntuple filters and actions
+#ethtool_ntuple_eth0=""
+
+# Additionally, there is a special control variable, if you need to change the
+# order of option processing. The default order is:
+# flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple
+
+# Set global order to default
+#ethtool_order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple"
+
+# Hypothetical network card that requires a change-eeprom toggle to enable flashing
+#ethtool_order_eth0="change-eeprom flash change pause coalesce ring offload nfc rxfh-indir ntuple"
+
##############################################################################
# ADVANCED CONFIGURATION
-#
+#
# Four functions can be defined which will be called surrounding the
# start/stop operations. The functions are called with the interface
# name first so that one function can control multiple adapters. An extra two
@@ -1001,7 +1074,7 @@
# if mii-tool "${IFACE}" 2> /dev/null | grep -q 'no link'; then
# ewarn "No link on ${IFACE}, aborting configuration"
# return 1
-# fi
+# fi
#
# # Test for link on the interface prior to bringing it up. This
# # only works on some network adapters and requires the ethtool
diff --git a/etc/rc.conf.FreeBSD b/etc/rc.conf.FreeBSD
index 5682e1d..800c6cf 100644
--- a/etc/rc.conf.FreeBSD
+++ b/etc/rc.conf.FreeBSD
@@ -3,6 +3,10 @@
# "jail" - FreeBSD jails
# "prefix" - Prefix
# If unset, the old automagic detection code will be triggered. Said old code
-# is deprecated and be removed not later than 2010/03/01.
+# is deprecated and will be removed not later than 2011/03/01.
+#
+# This should be set to the value representing what environment this file is
+# PRESENTLY in, not what virtualization the environment is capable of.
+# See the OpenRC migration guide for more details.
rc_sys=""
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 001e9c0..b110a81 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -8,7 +8,11 @@
# "xen0" - Xen0 Domain
# "xenU" - XenU Domain
# If unset, the old automagic detection code will be triggered. Said old code
-# is deprecated and be removed not later than 2010/03/01.
+# is deprecated and will be removed not later than 2011/03/01.
+#
+# This should be set to the value representing what environment this file is
+# PRESENTLY in, not what virtualization the environment is capable of.
+# See the OpenRC migration guide for more details.
rc_sys=""
##############################################################################
diff --git a/etc/rc.conf.NetBSD b/etc/rc.conf.NetBSD
index 25d86a4..b29000b 100644
--- a/etc/rc.conf.NetBSD
+++ b/etc/rc.conf.NetBSD
@@ -4,6 +4,10 @@
# "xen0" - Xen0 Domain
# "xenU" - XenU Domain
# If unset, the old automagic detection code will be triggered. Said old code
-# is deprecated and be removed not later than 2010/03/01.
+# is deprecated and will be removed not later than 2011/03/01.
+#
+# This should be set to the value representing what environment this file is
+# PRESENTLY in, not what virtualization the environment is capable of.
+# See the OpenRC migration guide for more details.
rc_sys=""
diff --git a/etc/rc.conf.in b/etc/rc.conf.in
index 6aa3613..3c1210b 100644
--- a/etc/rc.conf.in
+++ b/etc/rc.conf.in
@@ -95,7 +95,7 @@
# We can set some things on a per service basis, like the nicelevel.
#export SSD_NICELEVEL="-19"
-# Pass ulimit parameters
+# Pass ulimit parameters
#rc_ulimit="-u 30"
# It's possible to define extra dependencies for services like so
diff --git a/etc/rc.in b/etc/rc.in
index edd7a5d..d267bec 100644
--- a/etc/rc.in
+++ b/etc/rc.in
@@ -6,7 +6,7 @@
# This gives us a nice colour boot :)
[ -z "$TERM" -o "$TERM" = "dumb" ] && export TERM="@TERM@"
-# Handle interrupts
+# Handle interrupts
trap : SIGINT
trap "echo 'Boot interrupted'; exit 1" SIGQUIT
diff --git a/etc/rc.shutdown.in b/etc/rc.shutdown.in
index e0231c7..115f212 100644
--- a/etc/rc.shutdown.in
+++ b/etc/rc.shutdown.in
@@ -2,7 +2,7 @@
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
-# Handle interrupts
+# Handle interrupts
trap : SIGINT SIGQUIT
# Try and use stuff in /lib over anywhere else so we can shutdown
diff --git a/init.d.misc/dnsmasq.in b/init.d.misc/dnsmasq.in
index de4bade..958a87e 100644
--- a/init.d.misc/dnsmasq.in
+++ b/init.d.misc/dnsmasq.in
@@ -10,7 +10,7 @@ required_files=/etc/dnsmasq.conf
extra_started_commands="reload"
depend()
-{
+{
provide dns
need localmount net
after bootmisc
diff --git a/init.d.misc/openvpn.in b/init.d.misc/openvpn.in
index eb1360b..a53a3ed 100644
--- a/init.d.misc/openvpn.in
+++ b/init.d.misc/openvpn.in
@@ -24,7 +24,7 @@ if yesno $openvpn_client; then
command_args="$command_args --up $openvpn_up"
command_args="$command_args --down $openvpn_down"
required_files="$required_files $openvpn_up $openvpn_down"
-
+
in_background_fake="start stop"
start_inactive=YES
fi
@@ -59,7 +59,7 @@ start_pre()
sysctl -a | grep -q '\.tap\.' || kldload if_tap
fi
fi
-
+
# If the config file does not specify the cd option, we do
if ! grep -q "^[ \t]*cd[ \t].*" "$openvpn_config"; then
command_args="$command_args --cd $openvpn_dir"
diff --git a/init.d.misc/sshd.in b/init.d.misc/sshd.in
index 3d02cab..403f43b 100644
--- a/init.d.misc/sshd.in
+++ b/init.d.misc/sshd.in
@@ -31,5 +31,5 @@ start_pre()
eend $? || return 1
fi
- $command -t
+ $command -t
}
diff --git a/init.d.misc/wpa_supplicant.in b/init.d.misc/wpa_supplicant.in
index f1d65c5..2426905 100644
--- a/init.d.misc/wpa_supplicant.in
+++ b/init.d.misc/wpa_supplicant.in
@@ -43,7 +43,7 @@ find_wireless()
done
;;
esac
-
+
return 1
}
diff --git a/init.d/Makefile b/init.d/Makefile
index 6a0323c..b7490d3 100644
--- a/init.d/Makefile
+++ b/init.d/Makefile
@@ -5,12 +5,10 @@ SRCS= bootmisc.in fsck.in hostname.in local.in localmount.in netmount.in \
BIN= ${OBJS}
# Build our old net foo or not
-_OLDNET_SH= case "${MKOLDNET}" in \
- [Yy][Ee][Ss]) echo "net.lo";; \
- *) echo "";; \
- esac
-_OLDNET!= ${_OLDNET_SH}
-_NET_LO= ${_OLDNET}$(shell ${_OLDNET_SH})
+ifeq (${MKOLDNET},yes)
+_OLDNET= net.lo
+endif
+_NET_LO= ${_OLDNET}
INSTALLAFTER= _installafter_${_NET_LO}
CLEANFILES+= ${_NET_LO}
diff --git a/init.d/adjkerntz.in b/init.d/adjkerntz.in
index ee09ac8..807d411 100644
--- a/init.d/adjkerntz.in
+++ b/init.d/adjkerntz.in
@@ -4,7 +4,7 @@
extra_commands="save"
-description="Sets the local clock to UTC or Local Time."
+description="Sets the local clock to UTC or Local Time."
description_save="Saves the current time in the BIOS."
: ${clock:=${CLOCK:-UTC}}
@@ -26,7 +26,7 @@ depend()
}
start()
-{
+{
ebegin "Starting the System Clock Adjuster [${utc}]"
if [ "$clock" != "UTC" ]; then
echo >/etc/wall_cmos_clock
diff --git a/init.d/bootmisc.in b/init.d/bootmisc.in
index 1298740..320e7e8 100644
--- a/init.d/bootmisc.in
+++ b/init.d/bootmisc.in
@@ -88,7 +88,7 @@ start()
eend 1 "failed to create needed directory $x"
return 1
fi
- fi
+ fi
done
if dir_writeable /var/run; then
@@ -137,7 +137,7 @@ start()
# Make sure our X11 stuff have the correct permissions
# Omit the chown as bootmisc is run before network is up
# and users may be using lame LDAP auth #139411
- rm -rf /tmp/.ICE-unix /tmp/.X11-unix
+ rm -rf /tmp/.ICE-unix /tmp/.X11-unix
mkdir -p /tmp/.ICE-unix /tmp/.X11-unix
chmod 1777 /tmp/.ICE-unix /tmp/.X11-unix
if [ -x /sbin/restorecon ]; then
diff --git a/init.d/consolefont.in b/init.d/consolefont.in
index d3acd75..75c2fd1 100644
--- a/init.d/consolefont.in
+++ b/init.d/consolefont.in
@@ -61,12 +61,6 @@ start()
done
cp "$font" "$RC_LIBEXECDIR"/console
echo "${font##*/}" >"$RC_LIBEXECDIR"/console/font
- if yesno ${unicode:-${UNICODE}}; then
- echo "" > "$RC_LIBEXECDIR"/console/unicode
- else
- rm -f "$RC_LIBEXECDIR"/console/unicode
- fi
-
fi
return $retval
diff --git a/init.d/hostid.in b/init.d/hostid.in
index 26ea9d6..a12e34a 100644
--- a/init.d/hostid.in
+++ b/init.d/hostid.in
@@ -68,7 +68,7 @@ reset()
start()
{
if [ -r "$hostid_file" ]; then
- _set $(cat "$hostid_file")
+ _set $(cat "$hostid_file")
else
reset
fi
diff --git a/init.d/hwclock.in b/init.d/hwclock.in
index e99900f..640d997 100644
--- a/init.d/hwclock.in
+++ b/init.d/hwclock.in
@@ -4,7 +4,7 @@
extra_commands="save show"
-description="Sets the local clock to UTC or Local Time."
+description="Sets the local clock to UTC or Local Time."
description_save="Saves the current time in the BIOS."
description_show="Displays the current time in the BIOS."
@@ -87,17 +87,21 @@ start()
_hwclock --adjust $utc_cmd
retval=$(($retval + $?))
fi
-
+
# If setting UTC, don't bother to run hwclock when first booting
# as that's the default
if [ "$PREVLEVEL" != N -o \
- "$utc_cmd}" != --utc -o \
+ "$utc_cmd" != --utc -o \
-n "$clock_args" ];
then
- _hwclock --hctosys $utc_cmd $clock_args
+ if yesno $clock_hctosys; then
+ _hwclock --hctosys $utc_cmd $clock_args
+ else
+ _hwclock --systz $utc_cmd $clock_args
+ fi
retval=$(($retval + $?))
fi
-
+
eend $retval "Failed to set the system clock"
return 0
@@ -126,7 +130,7 @@ stop()
_hwclock --systohc $utc_cmd $clock_args
retval=$?
- eend $retval "Failed to sync clocks"
+ eend $retval "Failed to sync clocks"
}
save()
diff --git a/init.d/ipfw.in b/init.d/ipfw.in
index 9d6faa4..ea6e22a 100644
--- a/init.d/ipfw.in
+++ b/init.d/ipfw.in
@@ -40,11 +40,11 @@ init() {
ipfw add deny all from any to 127.0.0.0/8
ipfw add deny ip from 127.0.0.0/8 to any
- if have_ip6; then
+ if have_ip6; then
ipfw add pass ip6 from any to any via lo0
ipfw add deny ip6 from any to ::1
ipfw add deny ip6 from ::1 to any
-
+
ipfw add pass ip6 from :: to ff02::/16 proto ipv6-icmp
ipfw add pass ip6 from fe80::/10 to fe80::/10 proto ipv6-icmp
ipfw add pass ip6 from fe80::/10 to ff02::/16 proto ipv6-icmp
@@ -78,7 +78,7 @@ start() {
ipfw add pass udp from 0.0.0.0 68 to 255.255.255.255 67 out
ipfw add pass udp from any 67 to me 68 in
ipfw add pass udp from any 67 to 255.255.255.255 68 in
- # Some servers will ping the IP while trying to decide if it's
+ # Some servers will ping the IP while trying to decide if it's
# still in use.
ipfw add pass icmp from any to any icmptype 8
@@ -88,11 +88,11 @@ start() {
if have_ip6; then
# Allow ICMPv6 destination unreach
ipfw add pass ip6 from any to any icmp6types 1 proto ipv6-icmp
-
+
# Allow NS/NA/toobig (don't filter it out)
ipfw add pass ip6 from any to any icmp6types 2,135,136 proto ipv6-icmp
fi
-
+
# Add permits for this workstations published services below
# Only IPs and nets in firewall_allowservices is allowed in.
for i in $ipfw_ip_in; do
@@ -107,7 +107,7 @@ start() {
for i in $ipfw_ip_trust; do
ipfw add pass ip from $i to me
done
-
+
ipfw add 65000 count ip from any to any
# Drop packets to ports where we don't want logging
@@ -117,7 +117,7 @@ start() {
# Broadcasts and muticasts
ipfw add deny ip from any to 255.255.255.255
- ipfw add deny ip from any to 224.0.0.0/24
+ ipfw add deny ip from any to 224.0.0.0/24
# Noise from routers
ipfw add deny udp from any to any 520 in
diff --git a/init.d/keymaps.in b/init.d/keymaps.in
index f37fbb5..776f3bb 100644
--- a/init.d/keymaps.in
+++ b/init.d/keymaps.in
@@ -17,7 +17,7 @@ start()
: ${unicode:=$UNICODE}
: ${keymap:=$KEYMAP}
: ${extended_keymaps:=$EXTENDED_KEYMAPS}
- : ${windowkeys:=$SET_WINDOWSKEYS}
+ : ${windowkeys:=$SET_WINDOWSKEYS}
: ${fix_euro:=$FIX_EURO}
: ${dumpkeys_charset:=${DUMPKEYS_CHARSET}}
diff --git a/init.d/killprocs.in b/init.d/killprocs.in
index d12f0f6..7132e9e 100644
--- a/init.d/killprocs.in
+++ b/init.d/killprocs.in
@@ -15,7 +15,7 @@ start()
killall5 -15
sleep 1
eend 0
- ebegin "Killing remaining processes"
+ ebegin "Killing remaining processes"
killall5 -9
sleep 1
eend 0
diff --git a/init.d/local.in b/init.d/local.in
index 63d5e92..4db492e 100644
--- a/init.d/local.in
+++ b/init.d/local.in
@@ -2,7 +2,7 @@
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
-description="Executes user commands in /etc/conf.d/local"
+description="Executes user programs in @SYSCONFDIR@/local.d"
depend()
{
@@ -12,22 +12,40 @@ depend()
start()
{
- ebegin "Starting local"
+ einfo "Starting local"
+
+ local file
+ for file in @SYSCONFDIR@/local.d/*.start ; do
+ [ -x "$file" ] && "$file"
+ done
if type local_start >/dev/null 2>&1; then
+ ewarn "@SYSCONFDIR@/conf.d/local should be removed."
+ ewarn "Please move the code from the local_start function"
+ ewarn "to scripts with an .start extension"
+ ewarn "in @SYSCONFDIR@/local.d"
local_start
fi
- eend $? "Failed to start local"
+ return 0
}
stop()
{
- ebegin "Stopping local"
+ einfo "Stopping local"
+
+ local file
+ for file in @SYSCONFDIR@/local.d/*.stop; do
+ [ -x "$file" ] && "$file"
+ done
if type local_start >/dev/null 2>&1; then
+ ewarn "@SYSCONFDIR@/conf.d/local should be removed."
+ ewarn "Please move the code from the local_stop function"
+ ewarn "to scripts with an .stop extension"
+ ewarn "in @SYSCONFDIR@/local.d"
local_stop
fi
- eend $? "Failed to stop local"
+ return 0
}
diff --git a/init.d/localmount.in b/init.d/localmount.in
index 2a8e96f..e2ea801 100644
--- a/init.d/localmount.in
+++ b/init.d/localmount.in
@@ -58,8 +58,8 @@ stop()
. "$RC_LIBEXECDIR"/sh/rc-mount.sh
- # Umount loopback devices
- einfo "Unmounting loopback devices"
+ # Umount loop devices
+ einfo "Unmounting loop devices"
eindent
do_unmount "umount -d" --skip-point-regex "$no_umounts_r" \
--node-regex "^/dev/loop"
diff --git a/init.d/moused.in b/init.d/moused.in
index a362228..33b8d02 100644
--- a/init.d/moused.in
+++ b/init.d/moused.in
@@ -21,13 +21,13 @@ depend()
start()
{
- ebegin "Starting $name"
+ ebegin "Starting $name"
if [ -z "$moused_device" ]; then
local dev=
for dev in /dev/psm[0-9]* /dev/ums[0-9]*; do
[ -c "$dev" ] || continue
- [ -e /var/run/moused-"${dev##*/}".pid ] && continue
+ [ -e /var/run/moused-"${dev##*/}".pid ] && continue
moused_device=$dev
eindent
einfo "Using mouse on $moused_device"
@@ -37,7 +37,7 @@ start()
fi
if [ -z "$moused_device" ]; then
- eend 1 "No mouse device found"
+ eend 1 "No mouse device found"
return 1
fi
@@ -49,7 +49,7 @@ start()
--pidfile "$pidfile" \
-- $args -p "$moused_device" -I "$pidfile"
local retval=$?
-
+
if [ $retval = 0 ]; then
local ttyv=
for ttyv in /dev/ttyv*; do
@@ -57,6 +57,6 @@ start()
: $((retval+= $?))
done
fi
-
+
eend $retval "Failed to start moused"
}
diff --git a/init.d/net.lo.in b/init.d/net.lo.in
index 30d0186..b194a23 100644
--- a/init.d/net.lo.in
+++ b/init.d/net.lo.in
@@ -180,7 +180,7 @@ _gen_module_list()
${update} || return 0
fi
- einfo "Caching network module dependencies"
+ einfo "Caching network module dependencies"
# Run in a subshell to protect the main script
(
after() {
@@ -215,7 +215,7 @@ _gen_module_list()
for MODULE in "${MODULESDIR}"/*.sh; do
sh -n "${MODULE}" || continue
- . "${MODULE}" || continue
+ . "${MODULE}" || continue
MODULE=${MODULE#${MODULESDIR}/}
MODULE=${MODULE%.sh}
eval ${MODULE}_depend
@@ -343,7 +343,7 @@ _load_modules()
# Wrap our provides
local f=
- for f in pre_start start post_start; do
+ for f in pre_start start post_start; do
eval "${provides}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }"
done
@@ -357,7 +357,7 @@ _load_modules()
*" ${mod} "*)
eval x=\$module_${mod}_provides
[ -z "${x}" ] && continue
- for f in pre_start start post_start; do
+ for f in pre_start start post_start; do
eval "${x}_${f}() { [ "$(command -v "${mod}_${f}")" = "${mod}_${f}" ] || return 0; ${mod}_${f} \"\$@\"; }"
done
eval module_${x}_providedby="${mod}"
@@ -379,7 +379,7 @@ _load_modules()
MODULES="${MODULES}${MODULES:+ }${mod}"
done
else
- for mod in ${LIST}; do
+ for mod in ${LIST}; do
MODULES="${mod}${MODULES:+ }${MODULES}"
done
fi
@@ -395,7 +395,7 @@ _load_config()
config_index=0
local IFS="$__IFS"
set -- ${config}
-
+
# We should support a space separated array for cidr configs
if [ $# = 1 ]; then
unset IFS
@@ -415,7 +415,7 @@ _load_config()
config_0="127.0.0.1/8"
config_index=1
fi
- else
+ else
if [ -z "$1" ]; then
ewarn "No configuration specified; defaulting to DHCP"
config_0="dhcp"
@@ -500,7 +500,7 @@ start()
fi
_up 2>/dev/null
-
+
for module in ${MODULES}; do
if [ "$(command -v "${module}_pre_start")" = "${module}_pre_start" ]; then
${module}_pre_start || exit $?
@@ -527,7 +527,7 @@ start()
_load_config
config_index=0
- eval our_metric=\$metric_${IFVAR}
+ eval our_metric=\$metric_${IFVAR}
if [ -n "${our_metric}" ]; then
metric=${our_metric}
elif [ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
@@ -536,7 +536,7 @@ start()
while true; do
eval config=\$config_${config_index}
- [ -z "${config}" ] && break
+ [ -z "${config}" ] && break
set -- ${config}
ebegin "$1"
@@ -638,7 +638,7 @@ ${routes}"
if [ "$(command -v postup)" = "postup" ]; then
ebegin "Running postup"
eindent
- postup
+ postup
eoutdent
fi
diff --git a/init.d/netmount.in b/init.d/netmount.in
index 88ce16f..3bdc63b 100644
--- a/init.d/netmount.in
+++ b/init.d/netmount.in
@@ -39,7 +39,7 @@ depend()
}
start()
-{
+{
local myneed= myuse= pmap="portmap" nfsmounts=
[ -x @SYSCONFDIR@/init.d/rpcbind ] && pmap="rpcbind"
diff --git a/init.d/network.in b/init.d/network.in
index 01e88ce..a563332 100644
--- a/init.d/network.in
+++ b/init.d/network.in
@@ -222,7 +222,7 @@ start()
einfo "Starting network"
routeflush
if [ "$RC_UNAME" = "Linux" ]; then
- ifconfig lo 127.0.0.1 netmask 255.0.0.0 || cr=1
+ ifconfig lo 127.0.0.1 netmask 255.0.0.0 || cr=1
route add -net 127.0.0.0 netmask 255.0.0.0 \
gw 127.0.0.1 reject 2>/dev/null
else
@@ -287,7 +287,7 @@ start()
[ $r != 0 ]
veend $?
fi
-
+
if [ -n "$defaultroute" ]; then
ebegin "Setting default route $defaultroute"
route add default $defaultroute
diff --git a/init.d/pf.in b/init.d/pf.in
index 15c9fc5..a36df26 100644
--- a/init.d/pf.in
+++ b/init.d/pf.in
@@ -44,7 +44,7 @@ reload()
{
ebegin "Reloading $name rules."
pfctl -q -n -f "$pf_conf" && \
- {
+ {
# Flush everything but existing state entries that way when
# rules are read in, it doesn't break established connections.
pfctl -q -Fnat -Fqueue -Frules -FSources -Finfo -FTables -Fosfp
diff --git a/init.d/swap-blk.in b/init.d/swap-blk.in
index 3c1c52c..f7d4367 100644
--- a/init.d/swap-blk.in
+++ b/init.d/swap-blk.in
@@ -13,11 +13,11 @@ start()
ebegin "Activating block swap devices"
swapctl -A -t blk >/dev/null
eend 0 # If swapon has nothing todo it errors, so always return 0
-}
+}
stop()
{
ebegin "Deactivating block swap devices"
swapctl -U -t blk >/dev/null
- eend 0
+ eend 0
}
diff --git a/init.d/swap.in b/init.d/swap.in
index d99b9b8..a1a931f 100644
--- a/init.d/swap.in
+++ b/init.d/swap.in
@@ -16,7 +16,7 @@ start()
*) swapon -a >/dev/null;;
esac
eend 0 # If swapon has nothing todo it errors, so always return 0
-}
+}
stop()
{
@@ -31,5 +31,5 @@ stop()
NetBSD|OpenBSD) swapctl -U -t noblk >/dev/null;;
*) swapoff -a >/dev/null;;
esac
- eend 0
+ eend 0
}
diff --git a/init.d/syscons.in b/init.d/syscons.in
index cb584b3..ba22bf5 100644
--- a/init.d/syscons.in
+++ b/init.d/syscons.in
@@ -15,13 +15,13 @@ start() {
done
eend $?
fi
-
+
if [ -n "$keymap" ]; then
ebegin "Setting keymap to $keymap"
kbdcontrol -l $keymap </dev/console
eend $?
fi
-
+
if [ -n "$keyrate" ]; then
ebegin "Setting keyrate to $keyrate"
kbdcontrol -r $keyrate </dev/console
@@ -40,7 +40,7 @@ start() {
done
eoutdent
fi
-
+
if [ -n "$cursor" ]; then
ebegin "Setting cursor"
vidcontrol -c $cursor
diff --git a/init.d/termencoding.in b/init.d/termencoding.in
index 734d220..fea27ee 100644
--- a/init.d/termencoding.in
+++ b/init.d/termencoding.in
@@ -31,5 +31,16 @@ start()
printf "\033%s" "$termencoding" >$ttydev$n
n=$(($n + 1))
done
+
+ # Save the encoding for use immediately at boot
+ if [ -w "$RC_LIBEXECDIR" ]; then
+ mkdir -p "$RC_LIBEXECDIR"/console
+ if yesno ${unicode:-${UNICODE}}; then
+ echo "" > "$RC_LIBEXECDIR"/console/unicode
+ else
+ rm -f "$RC_LIBEXECDIR"/console/unicode
+ fi
+ fi
+
eend 0
}
diff --git a/init.d/ttys.in b/init.d/ttys.in
index 178f182..b8a051d 100644
--- a/init.d/ttys.in
+++ b/init.d/ttys.in
@@ -2,7 +2,7 @@
# Copyright (c) 2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
-depend()
+depend()
{
after fsck
keyword -prefix
@@ -13,7 +13,7 @@ start()
ebegin "Setting tty flags"
ttyflags -a
eend $? || return $?
-
+
if [ -c /dev/ttyp0 ]; then
chmod 666 /dev/tty[p-uw-zP-T][0-9a-zA-Z]
fi
diff --git a/init.d/wscons.in b/init.d/wscons.in
index 3b18a24..916e27b 100644
--- a/init.d/wscons.in
+++ b/init.d/wscons.in
@@ -27,10 +27,10 @@ start()
font)
cmd=$wsfld
[ "$arg2" != "-" ] && cmd="$cmd -w $arg2"
- [ "$arg3" != "-" ] && cmd="$cmd -h $arg3"
+ [ "$arg3" != "-" ] && cmd="$cmd -h $arg3"
[ "$arg4" != "-" ] && cmd="$cmd -e $arg4"
cmd="$cmd -N $arg1 $arg5"
- eval "$cmd"
+ eval "$cmd"
;;
screen)
diff --git a/local.d/Makefile b/local.d/Makefile
new file mode 100644
index 0000000..7a7d31d
--- /dev/null
+++ b/local.d/Makefile
@@ -0,0 +1,6 @@
+DIR= ${LOCALDIR}
+CONF= README
+
+MK= ../mk
+include ${MK}/os.mk
+include ${MK}/scripts.mk
diff --git a/local.d/README b/local.d/README
new file mode 100644
index 0000000..d3c1156
--- /dev/null
+++ b/local.d/README
@@ -0,0 +1,9 @@
+This directory should contain programs or scripts which are to be run
+when the local service is started or stopped.
+
+If a file in this directory is executable and it has a .start extension,
+it will be run when the local service is started. If a file is
+executable and it has a .stop extension, it will be run when the local
+service is stopped.
+
+All files are processed in lexical order.
diff --git a/mk/.mk b/mk/.mk
deleted file mode 100644
index e69de29..0000000
diff --git a/mk/cc.mk b/mk/cc.mk
index 2c912d5..06556f0 100644
--- a/mk/cc.mk
+++ b/mk/cc.mk
@@ -5,9 +5,9 @@ CFLAGS?= -O2
# Default to using the C99 standard
CSTD?= c99
-_CSTD_SH= if test -n "${CSTD}"; then echo "-std=${CSTD}"; else echo ""; fi
-_CSTD!= ${_CSTD_SH}
-CFLAGS+= ${_CSTD}$(shell ${_CSTD_SH})
+ifneq (${CSTD},)
+CFLAGS+= -std=${CSTD}
+endif
# Try and use some good cc flags if we're building from git
# We don't use -pedantic as it will warn about our perfectly valid
@@ -29,5 +29,5 @@ _CC_FLAGS_SH= for f in ${_CCFLAGS}; do \
${CC} $$f -S -xc -o /dev/null - ; \
then printf "%s" "$$f "; fi \
done;
-_CC_FLAGS!= ${_CC_FLAGS_SH}
-CFLAGS+= ${_CC_FLAGS}$(shell ${_CC_FLAGS_SH})
+_CC_FLAGS:= $(shell ${_CC_FLAGS_SH})
+CFLAGS+= ${_CC_FLAGS}
diff --git a/mk/debug.mk b/mk/debug.mk
index 67e9ad1..bc98b58 100644
--- a/mk/debug.mk
+++ b/mk/debug.mk
@@ -3,14 +3,14 @@
# All rights reserved. Released under the 2-clause BSD license.
_RC_DEBUG_SH= case "${DEBUG}" in "") echo "";; *) echo "-DRC_DEBUG";; esac
-_RC_DEBUG!= ${_RC_DEBUG_SH}
-CPPFLAGS+= ${_RC_DEBUG}$(shell ${_RC_DEBUG_SH})
+_RC_DEBUG:= $(shell ${_RC_DEBUG_SH})
+CPPFLAGS+= ${_RC_DEBUG}
# Should we enable this with a different flag?
_LD_DEBUG_SH= case "${DEBUG}" in "") echo "";; *) echo "-Wl,--rpath=../librc -Wl,--rpath=../libeinfo";; esac
-_LD_DEBUG!= ${_LD_DEBUG_SH}
-LDFLAGS+= ${_LD_DEBUG}$(shell ${_LD_DEBUG_SH})
+_LD_DEBUG:= $(shell ${_LD_DEBUG_SH})
+LDFLAGS+= ${_LD_DEBUG}
_GGDB_SH= case "${DEBUG}" in "") echo "";; *) echo "-ggdb";; esac
-_GGDB!= ${_GGDB_SH}
-CFLAGS+= ${_GGDB}$(shell ${_GGDB_SH})
+_GGDB:= $(shell ${_GGDB_SH})
+CFLAGS+= ${_GGDB}
diff --git a/mk/depend-.mk b/mk/depend-.mk
deleted file mode 100644
index 9d13b52..0000000
--- a/mk/depend-.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-# This space left intentionally blank because gmake does not load .depend
-# by default
diff --git a/mk/depend-gmake.mk b/mk/depend-gmake.mk
deleted file mode 100644
index 947843e..0000000
--- a/mk/depend-gmake.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-# Tell gmake to include the optional dependency file.
-# This sucks, but I don't know any other way of portably making this work.
--include .depend
diff --git a/mk/depend.mk b/mk/depend.mk
index 067c1ef..44af378 100644
--- a/mk/depend.mk
+++ b/mk/depend.mk
@@ -10,9 +10,4 @@ IGNOREFILES+= .depend
depend: .depend extra_depend
-# Nasty hack. depend-.mk is a blank file, depend-gmake.mk has a gmake specific
-# command to optionally include .depend.
-# Someone should patch gmake to optionally include .depend if it exists.
-_INC_DEP= $(shell if ${MAKE} --version | grep -q "^GNU "; then \
- echo "gmake"; else echo ""; fi)
-include ${MK}/depend-${_INC_DEP}.mk
+-include .depend
diff --git a/mk/dist.mk b/mk/dist.mk
index 24ce130..fb58edc 100644
--- a/mk/dist.mk
+++ b/mk/dist.mk
@@ -9,14 +9,21 @@ DISTFILE?= ${DISTPREFIX}.tar.bz2
CLEANFILES+= ${NAME}-*.tar.bz2
_SNAP_SH= date -u +%Y%m%d%H%M
-_SNAP!= ${_SNAP_SH}
-SNAP= ${_SNAP}$(shell ${_SNAP_SH})
+_SNAP:= $(shell ${_SNAP_SH})
+SNAP= ${_SNAP}
SNAPDIR= ${DISTPREFIX}-${SNAP}
SNAPFILE= ${SNAPDIR}.tar.bz2
dist:
git archive --prefix=${DISTPREFIX}/ ${GITREF} | bzip2 > ${DISTFILE}
+distcheck: dist
+ rm -rf ${DISTPREFIX}
+ tar xf ${DISTFILE}
+ MAKEFLAGS= $(MAKE) -C ${DISTPREFIX}
+ MAKEFLAGS= $(MAKE) -C ${DISTPREFIX} check
+ rm -rf ${DISTPREFIX}
+
snapshot:
rm -rf /tmp/${SNAPDIR}
mkdir /tmp/${SNAPDIR}
diff --git a/mk/git.mk b/mk/git.mk
index 54a98ef..62cae5a 100644
--- a/mk/git.mk
+++ b/mk/git.mk
@@ -4,5 +4,5 @@ _GITVER_SH= if git rev-parse --short HEAD >/dev/null 2>&1; then \
else \
echo ""; \
fi
-_GITVER!= ${_GITVER_SH}
-GITVER= ${_GITVER}$(shell ${_GITVER_SH})
+_GITVER:= $(shell ${_GITVER_SH})
+GITVER= ${_GITVER}
diff --git a/mk/lib.mk b/mk/lib.mk
index 16c16a5..a5682dd 100644
--- a/mk/lib.mk
+++ b/mk/lib.mk
@@ -38,7 +38,7 @@ ${SHLIB_NAME}: ${SOBJS}
@${ECHO} building shared library $@
@rm -f $@ ${SHLIB_LINK}
@ln -fs $@ ${SHLIB_LINK}
- ${CC} ${LDFLAGS} -shared -Wl,-x \
+ ${CC} ${CFLAGS} ${LDFLAGS} -shared -Wl,-x \
-o $@ -Wl,-soname,${SONAME} \
${SOBJS} ${LDADD}
diff --git a/mk/ncurses.mk b/mk/ncurses.mk
deleted file mode 100644
index d93e8fb..0000000
--- a/mk/ncurses.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-LIBTERMCAP?= -lncurses
-CPPFLAGS+= -DHAVE_TERMCAP
-LDADD+= ${LIBTERMCAP}
diff --git a/mk/os.mk b/mk/os.mk
index 09f2aef..0cde8ae 100644
--- a/mk/os.mk
+++ b/mk/os.mk
@@ -4,8 +4,8 @@
# Generic definitions
_OS_SH= uname -s
-_OS!= ${_OS_SH}
-OS?= ${_OS}$(shell ${_OS_SH})
+_OS:= $(shell ${_OS_SH})
+OS?= ${_OS}
include ${MK}/os-${OS}.mk
RC_LIB= /$(LIBNAME)/rc
diff --git a/mk/pam.mk b/mk/pam.mk
index 65115d5..15ffb54 100644
--- a/mk/pam.mk
+++ b/mk/pam.mk
@@ -1,6 +1,10 @@
+ifeq (${MKPAM},pam)
LIBPAM?= -lpam
CPPFLAGS+= -DHAVE_PAM
LDADD+= ${LIBPAM}
PAMDIR?= /etc/pam.d
PAMMODE?= 0644
+else ifneq (${MKPAM},)
+$(error if MKPAM is defined, it must be "pam")
+endif
diff --git a/mk/prog.mk b/mk/prog.mk
index 33929fb..5bddf18 100644
--- a/mk/prog.mk
+++ b/mk/prog.mk
@@ -15,8 +15,8 @@ _DYNLINK_SH= if test "${PREFIX}" = "" && test -e /libexec/ld.elf_so; then \
else \
echo ""; \
fi
-_DYNLINK!= ${_DYNLINK_SH}
-LDFLAGS+= ${_DYNLINK}$(shell ${_DYNLINK_SH})
+_DYNLINK:= $(shell ${_DYNLINK_SH})
+LDFLAGS+= ${_DYNLINK}
LDFLAGS+= -Wl,-rpath=${PREFIX}/${LIBNAME}
LDFLAGS+= ${PROGLDFLAGS}
@@ -28,7 +28,7 @@ all: depend ${PROG}
${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@
${PROG}: ${SCRIPTS} ${OBJS}
- ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
+ ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
clean:
rm -f ${CLEANFILES}
diff --git a/mk/scripts.mk b/mk/scripts.mk
index bd7ec6b..3517aab 100644
--- a/mk/scripts.mk
+++ b/mk/scripts.mk
@@ -8,11 +8,11 @@ include ${MK}/os.mk
OBJS+= ${SRCS:.in=}
_PKG_SED_SH= if test "${PREFIX}" = "${PKG_PREFIX}"; then echo "-e 's:@PKG_PREFIX@::g'"; else echo "-e 's:@PKG_PREFIX@:${PKG_PREFIX}:g'"; fi
-_PKG_SED!= ${_PKG_SED_SH}
+_PKG_SED:= $(shell ${_PKG_SED_SH})
_LCL_SED_SH= if test "${PREFIX}" = "${LOCAL_PREFIX}"; then echo "-e 's:@LOCAL_PREFIX@::g'"; else echo "-e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'"; fi
-_LCL_SED!= ${_LCL_SED_SH}
+_LCL_SED:= $(shell ${_LCL_SED_SH})
-SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' ${_PKG_SED}$(shell ${_PKG_SED_SH}) ${_LCL_SED}$(shell ${_LCL_SED_SH})
+SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' -e 's:@PREFIX@:${PREFIX}:g' ${_PKG_SED} ${_LCL_SED}
# Tweak our shell scripts
.SUFFIXES: .sh.in .in
diff --git a/mk/sys.mk b/mk/sys.mk
index e22731b..b68afdb 100644
--- a/mk/sys.mk
+++ b/mk/sys.mk
@@ -12,8 +12,8 @@ SH= /bin/sh
PREFIX?=
_UPREFIX_SH= case "${PREFIX}" in "") echo /usr;; *) echo "${PREFIX}";; esac
-_UPREFIX!= ${_UPREFIX_SH}
-UPREFIX= ${_UPREFIX}$(shell ${_UPREFIX_SH})
+_UPREFIX:= $(shell ${_UPREFIX_SH})
+UPREFIX= ${_UPREFIX}
LOCAL_PREFIX= /usr/local
PICFLAG?= -fPIC
@@ -21,6 +21,7 @@ PICFLAG?= -fPIC
SYSCONFDIR?= ${PREFIX}/etc
INITDIR?= ${SYSCONFDIR}/init.d
CONFDIR?= ${SYSCONFDIR}/conf.d
+LOCALDIR?= ${SYSCONFDIR}/local.d
BINDIR?= ${PREFIX}/sbin
BINMODE?= 0755
@@ -29,8 +30,8 @@ INCDIR?= ${UPREFIX}/include
INCMODE?= 0444
_LIBNAME_SH= case `readlink /lib` in /lib64|lib64) echo "lib64";; *) echo "lib";; esac
-_LIBNAME!= ${_LIBNAME_SH}
-LIBNAME?= ${_LIBNAME}$(shell ${_LIBNAME_SH})
+_LIBNAME:= $(shell ${_LIBNAME_SH})
+LIBNAME?= ${_LIBNAME}
LIBDIR?= ${UPREFIX}/${LIBNAME}
LIBMODE?= 0444
SHLIBDIR?= ${PREFIX}/${LIBNAME}
diff --git a/mk/termcap.mk b/mk/termcap.mk
index 7a603e3..b716276 100644
--- a/mk/termcap.mk
+++ b/mk/termcap.mk
@@ -1,3 +1,11 @@
+ifeq (${MKTERMCAP},ncurses)
+LIBTERMCAP?= -lncurses
+CPPFLAGS+= -DHAVE_TERMCAP
+LDADD+= ${LIBTERMCAP}
+else ifeq (${MKTERMCAP},termcap)
LIBTERMCAP?= -ltermcap
CPPFLAGS+= -DHAVE_TERMCAP
LDADD+= ${LIBTERMCAP}
+else ifneq (${MKTERMCAP},)
+$(error If MKTERMCAP is defined, it must be ncurses or termcap)
+endif
diff --git a/net/Makefile.Linux b/net/Makefile.Linux
index 7006d74..f7fb087 100644
--- a/net/Makefile.Linux
+++ b/net/Makefile.Linux
@@ -1,7 +1,7 @@
SRCS+= iwconfig.sh.in
INC+= adsl.sh apipa.sh arping.sh bonding.sh br2684ctl.sh bridge.sh \
- ccwgroup.sh clip.sh iproute2.sh ifplugd.sh ip6to4.sh ipppd.sh \
- iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
+ ccwgroup.sh clip.sh ethtool.sh iproute2.sh ifplugd.sh ip6to4.sh \
+ ipppd.sh iwconfig.sh netplugd.sh pppd.sh pump.sh tuntap.sh udhcpc.sh \
vlan.sh
.SUFFIXES: .sh.Linux.in
diff --git a/net/apipa.sh b/net/apipa.sh
index f4e5f73..0ca3bda 100644
--- a/net/apipa.sh
+++ b/net/apipa.sh
@@ -21,7 +21,7 @@ apipa_start()
local iface="$1" i1= i2= addr= i=0
_exists true || return 1
-
+
einfo "Searching for free addresses in 169.254.0.0/16"
eindent
diff --git a/net/arping.sh b/net/arping.sh
index 307e8ef..b04f05d 100644
--- a/net/arping.sh
+++ b/net/arping.sh
@@ -19,7 +19,7 @@ arping_address()
esac
# We need to bring the interface up to test
- _exists "${iface}" || return 1
+ _exists "${iface}" || return 1
_up "${iface}"
eval w=\$arping_wait_${IFVAR}
@@ -43,7 +43,7 @@ arping_address()
sed -n -e 'y/abcdef/ABCDEF/' -e 's/.*\[\([^]]*\)\].*/\1/p')"
fi
[ -z "${foundmac}" ] && return 1
-
+
if [ -n "${mac}" ]; then
if [ "${mac}" != "${foundmac}" ]; then
vewarn "Found ${ip} but MAC ${foundmac} does not match"
@@ -74,7 +74,7 @@ arping_start()
fi
eindent
-
+
for x in ${gateways}; do
local IFS=,
set -- ${x}
@@ -119,7 +119,7 @@ arping_start()
fi
done
unset IFS
-
+
_load_config
return 0
fi
diff --git a/net/bonding.sh b/net/bonding.sh
index 415306c..209d4f0 100644
--- a/net/bonding.sh
+++ b/net/bonding.sh
@@ -115,7 +115,7 @@ bonding_pre_start()
bonding_stop()
{
- _is_bond || return 0
+ _is_bond || return 0
local slaves= s=
slaves=$( \
diff --git a/net/br2684ctl.sh b/net/br2684ctl.sh
index 3eea0d9..77dafc9 100644
--- a/net/br2684ctl.sh
+++ b/net/br2684ctl.sh
@@ -17,7 +17,7 @@ br2684ctl_depend()
}
_config_vars="$_config_vars bridge bridge_add brctl"
-
+
br2684ctl_pre_start()
{
local opts=
@@ -40,7 +40,7 @@ br2684ctl_pre_start()
return 1
;;
esac
-
+
einfo "Starting RFC 2684 Bridge control on ${IFACE}"
start-stop-daemon --start --exec $(_br2684ctl) --background \
--make-pidfile --pidfile "/var/run/br2684ctl-${IFACE}.pid" \
@@ -52,7 +52,7 @@ br2684ctl_post_stop()
{
local pidfile="/var/run/br2684ctl-${IFACE}.pid"
[ -e "${pidfile}" ] || return 0
-
+
einfo "Stopping RFC 2684 Bridge control on ${IFACE}"
start-stop-daemon --stop --quiet --pidfile "${pidfile}"
eend $?
diff --git a/net/bridge.sh b/net/bridge.sh
index c0172ed..91e68d6 100644
--- a/net/bridge.sh
+++ b/net/bridge.sh
@@ -38,15 +38,15 @@ bridge_pre_start()
local opts="$(_get_array "brctl_${IFVAR}")"
# brif is used for dynamic add
eval brif=\$bridge_add_${IFVAR}
-
+
# we need a way to if the bridge exists in a variable name, not just the
# contents of a variable. Eg if somebody has only bridge_add_eth0='br0',
# with no other lines mentioning br0.
eval bridge_unset=\${bridge_${IFVAR}-y\}
eval brctl_unset=\${brctl_${IFVAR}-y\}
-
- if [ -z "${brif}" -a "${brctl_unset}" == 'y' ]; then
- if [ -z "${ports}" -a "${bridge_unset}" == "y" ]; then
+
+ if [ -z "${brif}" -a "${brctl_unset}" = 'y' ]; then
+ if [ -z "${ports}" -a "${bridge_unset}" = "y" ]; then
#eerror "Misconfigured static bridge detected (see net.example)"
return 0
fi
@@ -186,6 +186,6 @@ bridge_post_stop()
brctl delbr "${iface}"
eend $?
fi
-
+
return 0
}
diff --git a/net/ccwgroup.sh b/net/ccwgroup.sh
index cf08943..6fcba1d 100644
--- a/net/ccwgroup.sh
+++ b/net/ccwgroup.sh
@@ -5,7 +5,7 @@ _config_vars="$_config_vars ccwgroup"
ccwgroup_depend()
{
- before interface
+ before interface
}
ccwgroup_pre_start()
@@ -42,7 +42,7 @@ ccwgroup_pre_stop()
{
# Erase any existing ccwgroup to be safe
service_set_value ccwgroup_device ""
-
+
[ ! -L /sys/class/net/"${FACE}"/driver ] && return 0
local driver="$(readlink /sys/class/net/"${IFACE}"/driver)"
case "${diver}" in
@@ -59,7 +59,7 @@ ccwgroup_post_stop()
{
local device="$(service_get_value ccwgroup_device)"
[ -z "${device}" ] && return 0
-
+
einfo "Disabling ccwgroup on ${iface}"
echo "0" >/sys/devices/qeth/"${device}"/online
echo "1" >/sys/devices/qeth/"${device}"/ungroup
diff --git a/net/clip.sh b/net/clip.sh
index 3cb84e7..35efa3f 100644
--- a/net/clip.sh
+++ b/net/clip.sh
@@ -97,7 +97,7 @@ clip_pre_start()
return 1
fi
fi
-
+
local started_here=
if ! are_atmclip_svcs_running; then
atmclip_svcs_start || return 1
diff --git a/net/ethtool.sh b/net/ethtool.sh
new file mode 100644
index 0000000..64b44a6
--- /dev/null
+++ b/net/ethtool.sh
@@ -0,0 +1,54 @@
+# Copyright (c) 2011 by Gentoo Foundation
+# All rights reserved. Released under the 2-clause BSD license.
+
+_ethtool() {
+ echo /usr/sbin/ethtool
+}
+
+ethtool_depend()
+{
+ program $(_ethtool)
+ before interface
+}
+
+# This is just to trim whitespace, do not add any quoting!
+_trim() {
+ echo $*
+}
+
+ethtool_pre_start() {
+ local order opt OFS="${OIFS}"
+ eval order=\$ethtool_order_${IFVAR}
+ [ -z "${order}" ] && eval order=\$ethtool_order
+ [ -z "${order}" ] && order="flash change-eeprom change pause coalesce ring offload identify nfc rxfh-indir ntuple"
+ # ethtool options not used: --driver, --register-dump, --eeprom-dump, --negotiate, --test, --statistics
+ eindent
+ for opt in ${order} ; do
+ local args
+ eval args=\$ethtool_${opt//-/_}_${IFVAR}
+
+ # Skip everything if no arguments
+ [ -z "${args}" ] && continue
+
+ # Split on \n
+ local IFS="$__IFS"
+
+ for p in ${args} ; do
+ IFS="${OIFS}"
+ local args_pretty="$(_trim "${p}")"
+ # Do nothing if empty
+ [ -z "${args_prety}" ] && continue
+ args_pretty="--${opt} $IFACE ${args_pretty}"
+ args="--${opt} $IFACE ${args}"
+ ebegin "ethtool ${args_pretty}"
+ $(_ethtool) ${args}
+ rc=$?
+ eend $rc "ethtool exit code $rc"
+ # TODO: ethtool has MANY different exit codes, with no
+ # documentation as to which ones are fatal or not. For now we
+ # simply print the exit code and don't stop the start sequence.
+ done
+ IFS="${OIFS}"
+ done
+ eoutdent
+}
diff --git a/net/ifconfig.sh.Linux.in b/net/ifconfig.sh.Linux.in
index 74fcc9f..f5c2064 100644
--- a/net/ifconfig.sh.Linux.in
+++ b/net/ifconfig.sh.Linux.in
@@ -139,7 +139,7 @@ _add_address()
return 0
fi
- case "$1" in
+ case "$1" in
*:*) ifconfig "${IFACE}" inet6 add "$@"; return $?;;
esac
@@ -225,7 +225,7 @@ _delete_addresses()
while true; do
local addr=$(_get_inet_address)
[ -z "${addr}" ] && break
-
+
if [ "${addr}" = "127.0.0.1/8" ]; then
# Don't delete the loopback address
[ "${IFACE}" = "lo" -o "${IFACE}" = "lo0" ] && break
@@ -246,7 +246,7 @@ _delete_addresses()
einfo "${addr}"
ifconfig "${IFACE}" inet6 del "${addr}"
done
-
+
return 0
}
diff --git a/net/ifplugd.sh b/net/ifplugd.sh
index 5831720..9f6c884 100644
--- a/net/ifplugd.sh
+++ b/net/ifplugd.sh
@@ -57,7 +57,7 @@ ifplugd_pre_start()
ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
elif [ ${timeout} -lt 0 ]; then
einfo "Backgrounding ..."
- exit 1
+ exit 1
fi
veinfo "Waiting for ${IFACE} to be marked as started"
@@ -84,7 +84,7 @@ ifplugd_stop()
local pidfile="/var/run/ifplugd.${IFACE}.pid"
[ ! -e "${pidfile}" ] && return 0
-
+
ebegin "Stopping ifplugd on ${IFACE}"
start-stop-daemon --stop --quiet --exec /usr/sbin/ifplugd \
--pidfile "${pidfile}" --signal QUIT
diff --git a/net/ifwatchd.sh b/net/ifwatchd.sh
index d9da15e..4e6b1c6 100644
--- a/net/ifwatchd.sh
+++ b/net/ifwatchd.sh
@@ -50,7 +50,7 @@ ifwatchd_stop()
-- -c "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \
-n "${RC_LIBEXECDIR}/sh/ifwatchd-nocarrier.sh" "${IFACE}" \
|| return 0
-
+
ebegin "Stopping ifwatchd on" "${IFACE}"
start-stop-daemon --stop --exec /usr/sbin/ifwatchd \
-- -c "${RC_LIBEXECDIR}/sh/ifwatchd-carrier.sh" \
diff --git a/net/ip6to4.sh b/net/ip6to4.sh
index 6bddb7e..2349429 100644
--- a/net/ip6to4.sh
+++ b/net/ip6to4.sh
@@ -56,7 +56,7 @@ ip6to4_start()
[ ${i} -lt 32 ] && continue
;;
esac
-
+
veinfo "IPv4 address on ${host}: ${ip}/${subnet}"
local ipa= ip6= IFS="${IFS}."
for i in ${ip}; do
@@ -87,7 +87,7 @@ ip6to4_start()
eend $? || return 1
_up
fi
-
+
# Now apply our config
eval config_${config_index}=\'"${new}"\'
config_index=$((${config_index} - 1))
diff --git a/net/iproute2.sh b/net/iproute2.sh
index 1cd4f42..a2e9db7 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -117,14 +117,14 @@ _add_address()
shift; shift; shift
set -- "${one}/$(_netmask2cidr "${three}")" "$@"
fi
-
+
# tunnel keyword is 'peer' in iproute2, but 'pointopoint' in ifconfig.
if [ "$2" = "pointopoint" ]; then
local one="$1"
shift; shift
set -- "${one}" "peer" "$@"
fi
-
+
# Always scope lo addresses as host unless specified otherwise
if [ "${IFACE}" = "lo" ]; then
set -- "$@" "scope" "host"
@@ -162,7 +162,7 @@ _add_route()
set -- "${one}" "${two}" via "$@"
fi
- local cmd= have_metric=false
+ local cmd= have_metric=false
while [ -n "$1" ]; do
case "$1" in
metric) cmd="${cmd} $1"; have_metric=true;;
@@ -221,7 +221,7 @@ _ip_rule_runner() {
local IFS="$__IFS"
for ru in $rules ; do
unset IFS
- ruN="$(trim "${ru}")"
+ ruN="$(_trim "${ru}")"
[ -z "${ruN}" ] && continue
vebegin "${cmd} ${ruN}"
ip rule ${cmd} ${ru}
@@ -239,9 +239,14 @@ iproute2_pre_start()
if [ -n "${tunnel}" ]; then
# Set our base metric to 1000
metric=1000
+ # Bug#347657: If the mode is 'ipip6' or 'ip6ip6', the -6 must be passed
+ # to iproute2 during tunnel creation.
+ local ipproto=''
+ [ "${tunnel##mode ipip6}" != "${tunnel}" ] && ipproto='-6'
+ [ "${tunnel##mode ip6ip6}" != "${tunnel}" ] && ipproto='-6'
ebegin "Creating tunnel ${IFVAR}"
- ip tunnel add ${tunnel} name "${IFACE}"
+ ip ${ipproto} tunnel add ${tunnel} name "${IFACE}"
eend $? || return 1
_up
fi
diff --git a/net/iwconfig.sh.BSD.in b/net/iwconfig.sh.BSD.in
index ec88e66..f94246b 100644
--- a/net/iwconfig.sh.BSD.in
+++ b/net/iwconfig.sh.BSD.in
@@ -477,7 +477,7 @@ iwconfig_defaults()
#ifconfig "${iface}" txpower 100 2>/dev/null
ifconfig "${IFACE}" bssid -
ifconfig "${IFACE}" ssid -
- ifconfig "${IFACE}" wepkey 1:- wepkey 2:- wepkey 3:- wepkey 4:-
+ ifconfig "${IFACE}" wepkey 1:- wepkey 2:- wepkey 3:- wepkey 4:-
ifconfig "${IFACE}" authmode open
ifconfig "${IFACE}" -mediaopt adhoc
ifconfig "${IFACE}" -mediaopt hostap
@@ -563,8 +563,8 @@ iwconfig_pre_start()
return 0
fi
- iwconfig_defaults
- iwconfig_user_config
+ iwconfig_defaults
+ iwconfig_user_config
# Set the base metric to be 2000
metric=2000
diff --git a/net/iwconfig.sh.Linux.in b/net/iwconfig.sh.Linux.in
index 28cdd23..600ffe7 100644
--- a/net/iwconfig.sh.Linux.in
+++ b/net/iwconfig.sh.Linux.in
@@ -47,7 +47,7 @@ _get_ssid()
_get_ap_mac_address()
{
- local mac="$(iwgetid --raw --ap "${IFACE}")"
+ local mac="$(iwgetid --raw --ap "${IFACE}")"
case "${mac}" in
"00:00:00:00:00:00") return 1;;
"44:44:44:44:44:44") return 1;;
@@ -163,7 +163,7 @@ iwconfig_setup_specific()
local key=$(iwconfig_get_wep_key)
iwconfig_set_mode "${mode}"
-
+
# Now set the key
if ! eval iwconfig "${IFACE}" key "${key}"; then
if [ "${key}" != "off" ]; then
@@ -185,10 +185,10 @@ iwconfig_setup_specific()
ewarn "${IFACE} does not support setting the channel to \"${channel:-3}\""
return 1
fi
-
+
# Finally apply the user Config
iwconfig_user_config
-
+
iwconfig_report
return 0
}
@@ -226,7 +226,7 @@ iwconfig_wait_for_association()
/proc/net/wireless)" != "0" ] && return 0
fi
fi
-
+
sleep 1
[ ${timeout} -eq 0 ] && continue
i=$((${i} + 1))
@@ -281,7 +281,7 @@ iwconfig_associate()
iwconfig "${IFACE}" freq "${freq}"
fi
[ -n "${mac}" ] && iwconfig "${IFACE}" ap "${mac}"
-
+
# Finally apply the user Config
iwconfig_user_config
@@ -377,10 +377,10 @@ iwconfig_scan()
for line; do
case "${line}" in
*Address:*)
- APS=$((${APS} + 1))
+ APS=$((${APS} + 1))
eval MAC_${APS}="\""$(echo "${line#*: }" | tr '[:lower:]' '[:upper:]')"\""
eval QUALITY_${APS}=0
- ;;
+ ;;
*ESSID:*)
x=${line#*\"}
x=${x%*\"}
@@ -455,7 +455,7 @@ iwconfig_scan()
eval a=\$QUALITY_${i}
eval b=\$QUALITY_${k}
local u=${k}
- # We need to split this into two tests, otherwise bash errors
+ # We need to split this into two tests, otherwise bash errors
[ -n "${a}" -a -n "${b}" ] && [ "${a}" -lt "${b}" ] && u=${i}
unset MAC_${u} SSID_${u} MODE_${u} CHAN_${u} QUALITY_${u} ENC_${u}
fi
@@ -581,7 +581,7 @@ iwconfig_connect_not_preferred()
break
fi
done
-
+
if ! ${pref}; then
SSID=${e}
eval mode=\$MODE_${i}
@@ -711,10 +711,10 @@ iwconfig_pre_start()
# wait if our scan returns nothing
LC_ALL=C iwconfig "${IFACE}" | sed -e '1d' | grep -q "Tx-Power=off"
local txpowerwasoff=$?
-
+
iwconfig_defaults
iwconfig_user_config
-
+
# Set the base metric to be 2000
metric=2000
diff --git a/net/macchanger.sh b/net/macchanger.sh
index 32bbdc9..9126d30 100644
--- a/net/macchanger.sh
+++ b/net/macchanger.sh
@@ -24,7 +24,7 @@ macchanger_pre_start()
# The interface needs to be up for macchanger to work most of the time
_down
-
+
mac=$(echo "${mac}" | tr '[:upper:]' '[:lower:]')
local hex="[0-9a-f][0-9a-f]"
case "${mac}" in
diff --git a/net/netplugd.sh b/net/netplugd.sh
index 0f46643..8f36ef2 100644
--- a/net/netplugd.sh
+++ b/net/netplugd.sh
@@ -59,7 +59,7 @@ netplugd_pre_start()
ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
elif [ ${timeout} -lt 0 ]; then
einfo "Backgrounding ..."
- exit 1
+ exit 1
fi
veinfo "Waiting for ${IFACE} to be marked as started"
@@ -86,7 +86,7 @@ netplugd_stop()
local pidfile="/var/run/netplugd-${IFACE}.pid"
[ ! -e "${pidfile}" ] && return 0
-
+
ebegin "Stopping netplug on" "${IFACE}"
start-stop-daemon --stop --quiet --exec /sbin/netplugd \
--pidfile "${pidfile}"
diff --git a/net/pppd.sh b/net/pppd.sh
index a8c8882..c7cfa44 100644
--- a/net/pppd.sh
+++ b/net/pppd.sh
@@ -31,7 +31,7 @@ pppd_pre_start()
if yesno ${IN_BACKGROUND}; then
local config=
eval config=\$config_${IFVAR}
- # If no config for ppp then don't default to DHCP
+ # If no config for ppp then don't default to DHCP
if [ -z "${config}" ]; then
eval config_${IFVAR}=null
fi
@@ -39,7 +39,7 @@ pppd_pre_start()
fi
local link= i= unit="${IFACE#ppp}" opts=
-
+
# PPP requires a link to communicate over - normally a serial port
# PPPoE communicates over Ethernet
# PPPoA communicates over ATM
@@ -92,7 +92,7 @@ pppd_pre_start()
&& [ -n "${password}" -o -z "${passwordset}" ]; then
opts="plugin passwordfd.so ${opts} passwordfd 0"
fi
-
+
if ! ${hasdefaultmetric}; then
local m=
eval m=\$metric_${IFVAR}
@@ -122,7 +122,7 @@ pppd_pre_start()
# Set unit
opts="unit ${unit} ${opts}"
-
+
# Setup connect script
local chatprog="/usr/sbin/chat -e -E -v" phone=
eval phone=\$phone_number_${IFVAR}
diff --git a/net/pump.sh b/net/pump.sh
index d03e2c8..ecceff0 100644
--- a/net/pump.sh
+++ b/net/pump.sh
@@ -35,7 +35,7 @@ pump_start()
ebegin "Running pump"
eval pump "${args}"
- eend $? || return 1
+ eend $? || return 1
_show_address
return 0
@@ -48,7 +48,7 @@ pump_stop()
start-stop-daemon --quiet --test --stop --exec /sbin/pump || return 0
# Check that pump is running on the interface
- if ! pump --status --interface "${IFACE}" >/dev/null 2>&1; then
+ if ! pump --status --interface "${IFACE}" >/dev/null 2>&1; then
return 0
fi
diff --git a/net/system.sh b/net/system.sh
index b22eee6..6680a7d 100644
--- a/net/system.sh
+++ b/net/system.sh
@@ -80,10 +80,10 @@ _system_nis()
eval servers=\$nis_servers_${IFVAR}
[ -z "${servers}" ] && servers=${nis_servers}
-
+
eval domain=\$nis_domain_${IFVAR}
[ -z "${domain}" ] && domain=${nis_domain}
-
+
[ -z "${servers}" -a -z "${domain}" ] && return 0
buffer="# Generated by net-scripts for interface ${iface}\n"
@@ -110,8 +110,8 @@ _system_nis()
system_pre_start()
{
_system_dns
- _system_ntp
- _system_nis
+ _system_ntp
+ _system_nis
return 0
}
diff --git a/net/vlan.sh b/net/vlan.sh
index c245051..1d50d4f 100644
--- a/net/vlan.sh
+++ b/net/vlan.sh
@@ -1,9 +1,18 @@
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
+_ip()
+{
+ if [ -x /bin/ip ]; then
+ echo /bin/ip
+ else
+ echo /sbin/ip
+ fi
+}
+
vlan_depend()
{
- program /sbin/vconfig
+ program $(_ip)
after interface
before dhcp
}
@@ -36,31 +45,12 @@ _check_vlan()
vlan_pre_start()
{
- local vc="$(_get_array "vconfig_${IFVAR}")"
- [ -z "${vc}" ] && return 0
-
- _check_vlan || return 1
- _exists || return 1
-
- local v= x= e=
- local IFS="$__IFS"
- for v in ${vc}; do
- unset IFS
- case "${v}" in
- set_name_type" "*) x=${v};;
- *)
- set -- ${v}
- x="$1 ${IFACE}"
- shift
- x="${x} $@"
- ;;
- esac
-
- e="$(vconfig ${x} 2>&1 1>/dev/null)"
- [ -z "${e}" ] && continue
- eerror "${e}"
+ local vconfig
+ eval vconfig=\$vconfig_${IFVAR}
+ if [ -n "${vconfig}" ]; then
+ eerror "You must convert your vconfig_ VLAN entries to vlan${N} entries."
return 1
- done
+ fi
}
vlan_post_start()
@@ -68,14 +58,26 @@ vlan_post_start()
local vlans=
eval vlans=\$vlans_${IFVAR}
[ -z "${vlans}" ] && return 0
-
+
_check_vlan || return 1
_exists || return 1
- local vlan= e= s=
+ local vlan= e= s= vname= vflags= vingress= vegress=
for vlan in ${vlans}; do
einfo "Adding VLAN ${vlan} to ${IFACE}"
- e="$(vconfig add "${IFACE}" "${vlan}" 2>&1 1>/dev/null)"
+ # We need to gather all interface configuration options
+ # 1) naming. Default to the standard "${IFACE}.${vlan}" but it can be anything
+ eval vname=\$vlan${vlan}_name
+ [ -z "${vname}" ] && vname="${IFACE}.${vlan}"
+ # 2) flags
+ eval vflags=\$vlan${vlan}_flags
+ # 3) ingress/egress map
+ eval vingress=\$vlan${vlan}_ingress
+ [ -z "${vingress}" ] || vingress="ingress-qos-map ${vingress}"
+ eval vegress=\$vlan${vlan}_egress
+ [ -z "${vegress}" ] || vegress="egress-qos-map ${vegress}"
+
+ e="$(ip link add link "${IFACE}" name "${vname}" type vlan id "${vlan}" ${vflags} ${vingress} ${vegress} 2>&1 1>/dev/null)"
if [ -n "${e}" ]; then
eend 1 "${e}"
continue
@@ -95,7 +97,7 @@ vlan_post_start()
start
) || mark_service_stopped "net.${ifname}"
done
-
+
return 0
}
@@ -110,7 +112,7 @@ vlan_post_stop()
stop
) && {
mark_service_stopped "net.${vlan}"
- vconfig rem "${vlan}" >/dev/null
+ ip link delete "${vlan}" type vlan >/dev/null
}
done
diff --git a/net/wpa_supplicant.sh b/net/wpa_supplicant.sh
index 379e615..c619f99 100644
--- a/net/wpa_supplicant.sh
+++ b/net/wpa_supplicant.sh
@@ -149,7 +149,7 @@ wpa_supplicant_pre_start()
if [ -z "${wpac}" ]; then
if service_started devd; then
ebegin "Backgrounding ..."
- exit 1
+ exit 1
fi
return 0
fi
@@ -167,7 +167,7 @@ wpa_supplicant_pre_start()
-P "/var/run/wpa_cli-${IFACE}.pid" -B
if eend $?; then
ebegin "Backgrounding ..."
- exit 1
+ exit 1
fi
# wpa_cli failed to start? OK, error here
diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index 0e581c1..9b04557 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -34,7 +34,7 @@ mount_svcdir()
[ $? -eq 0 ] && return 0
fi
fi
-
+
if grep -Eq "[[:space:]]+ramfs$" /proc/filesystems; then
fs="ramfs"
# ramfs has no special options
@@ -65,19 +65,27 @@ mount_svcdir()
# By default VServer already has /proc mounted, but OpenVZ does not!
# However, some of our users have an old proc image in /proc
# NFC how they managed that, but the end result means we have to test if
-# /proc actually works or not. We to this by comparing uptime to one a second
-# ago
+# /proc actually works or not. We to this by comparing two reads of
+# /proc/self/stat. They will not match, because at least the minor fault count
+# field (field 10) should have changed.
+#
+# We can use any file here that fills the following requirements:
+# - changes between sequential reads
+# - is world-readable (not blocked in hardened kernel)
+# - Is only a single line (ergo entire check is doable with no forks)
mountproc=true
-if [ -e /proc/uptime ]; then
- up="$(cat /proc/uptime)"
- sleep 1
- if [ "$up" = "$(cat /proc/uptime)" ]; then
+f=/proc/self/stat
+if [ -e $f ]; then
+ exec 9<$f ; read a <&9 ; exec 9<&-
+ exec 9<$f ; read b <&9 ; exec 9<&-
+ if [ "$a" = "$b" ]; then
eerror "You have cruft in /proc that should be deleted"
else
einfo "/proc is already mounted, skipping"
mountproc=false
fi
fi
+unset a b f
if $mountproc; then
procfs="proc"
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 947c2f7..229d1ee 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -111,7 +111,7 @@ start()
[ -n "$command" ] || return 0
local _background=
ebegin "Starting ${name:-$RC_SVCNAME}"
- if yesno "${command_background}"; then
+ if yesno "${command_background}"; then
_background="--background --pidfile"
fi
if yesno "$start_inactive"; then
@@ -252,7 +252,7 @@ while [ -n "$1" ]; do
eerror "$RC_SVCNAME: function \`$1' defined but does not exist"
exit 1
fi
- fi
+ fi
fi
done
eerror "$RC_SVCNAME: unknown function \`$1'"
diff --git a/src/libeinfo/Makefile b/src/libeinfo/Makefile
index 1569f8f..b93b5e5 100644
--- a/src/libeinfo/Makefile
+++ b/src/libeinfo/Makefile
@@ -10,4 +10,4 @@ MK= ../../mk
include ${MK}/lib.mk
include ${MK}/cc.mk
include ${MK}/debug.mk
-include ${MK}/${MKTERMCAP}.mk
+include ${MK}/termcap.mk
diff --git a/src/librc/Makefile b/src/librc/Makefile
index d3f9cc4..574aa2a 100644
--- a/src/librc/Makefile
+++ b/src/librc/Makefile
@@ -19,21 +19,26 @@ SED_CMD= -e 's:@PREFIX@:${PREFIX}:g'
SED_CMD+= -e 's:@LIB@:${LIBNAME}:g'
SED_CMD+= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
SED_CMD+= -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g'
-_PKG_PREFIX_SH= if test -n "${PKG_PREFIX}" && test "${PKG_PREFIX}" != "/" && test "${PKG_PREFIX}" != "${PREFIX}"; then \
- echo "-e 's:@PKG_PREFIX@:${PKG_PREFIX}:g'"; \
- else \
- echo "-e 's:.*@PKG_PREFIX@.*:\#undef RC_PKG_PREFIX:g'"; \
- fi
-_PKG_PREFIX!= ${_PKG_PREFIX_SH}
-SED_CMD+= ${_PKG_PREFIX}$(shell ${_PKG_PREFIX_SH})
-
-_LCL_PREFIX_SH= if test -n "${LOCAL_PREFIX}" && test "${LOCAL_PREFIX}" != "/" && test "${LOCAL_PREFIX}" != "${PREFIX}"; then \
- echo "-e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'"; \
- else \
- echo "-e 's:@LOCAL_PREFIX@::g'"; \
- fi
-_LCL_PREFIX!= ${_LCL_PREFIX_SH}
-SED_CMD+= ${_LCL_PREFIX}$(shell ${_LCL_PREFIX_SH})
+
+_PKG_PREFIX= -e 's:.*@PKG_PREFIX@.*:\#undef RC_PKG_PREFIX:g'
+ifneq (${PKG_PREFIX},)
+ifneq (${PKG_PREFIX},/)
+ifneq (${PKG_PREFIX},${PREFIX})
+_PKG_PREFIX= -e 's:@PKG_PREFIX@:${PKG_PREFIX}:g'
+endif
+endif
+endif
+SED_CMD+= ${_PKG_PREFIX}
+
+_LCL_PREFIX= -e 's:@LOCAL_PREFIX@::g'
+ifneq (${LOCAL_PREFIX},)
+ifneq (${LOCAL_PREFIX},/)
+ifneq (${LOCAL_PREFIX},${PREFIX})
+_LCL_PREFIX= -e 's:@LOCAL_PREFIX@:${LOCAL_PREFIX}:g'
+endif
+endif
+endif
+SED_CMD+= ${_LCL_PREFIX}
.SUFFIXES: .h.in .h
.h.in.h:
diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 1bedf29..dde62f9 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -40,7 +40,7 @@ pid_is_exec(pid_t pid, const char *exec)
int c;
bool retval = false;
- exec = basename_c(exec);
+ exec = basename_c(exec);
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
if ((fp = fopen(buffer, "r"))) {
while ((c = getc(fp)) != EOF && c != '(')
@@ -283,7 +283,7 @@ _match_daemon(const char *path, const char *file, RC_STRINGLIST *match)
}
static RC_STRINGLIST *
-_match_list(const char *exec, const char* const* argv, const char *pidfile)
+_match_list(const char *exec, const char *const *argv, const char *pidfile)
{
RC_STRINGLIST *match = rc_stringlist_new();
int i = 0;
@@ -297,7 +297,7 @@ _match_list(const char *exec, const char* const* argv, const char *pidfile)
rc_stringlist_add(match, m);
free(m);
}
-
+
while (argv && argv[i]) {
l = strlen(*argv) + strlen("argv_=") + 16;
m = xmalloc(sizeof(char) * l);
@@ -323,7 +323,7 @@ rc_service_daemon_set(const char *service, const char *exec,
const char *pidfile, bool started)
{
char dirpath[PATH_MAX];
- char file[PATH_MAX];
+ char file[PATH_MAX];
int nfiles = 0;
char oldfile[PATH_MAX] = { '\0' };
bool retval = false;
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c
index 765f595..54cd72a 100644
--- a/src/librc/librc-depend.c
+++ b/src/librc/librc-depend.c
@@ -114,7 +114,13 @@ get_deptype(const RC_DEPINFO *depinfo, const char *type)
}
RC_DEPTREE *
-rc_deptree_load(void)
+rc_deptree_load(void) {
+ return rc_deptree_load_file(RC_DEPTREE_CACHE);
+}
+librc_hidden_def(rc_deptree_load)
+
+RC_DEPTREE *
+rc_deptree_load_file(const char *deptree_file)
{
FILE *fp;
RC_DEPTREE *deptree;
@@ -127,7 +133,7 @@ rc_deptree_load(void)
char *e;
int i;
- if (!(fp = fopen(RC_DEPTREE_CACHE, "r")))
+ if (!(fp = fopen(deptree_file, "r")))
return NULL;
deptree = xmalloc(sizeof(*deptree));
@@ -172,16 +178,16 @@ rc_deptree_load(void)
}
fclose(fp);
free(line);
-
+
return deptree;
}
-librc_hidden_def(rc_deptree_load)
+librc_hidden_def(rc_deptree_load_file)
static bool
valid_service(const char *runlevel, const char *service, const char *type)
{
RC_SERVICE state;
-
+
if (!runlevel ||
strcmp(type, "ineed") == 0 ||
strcmp(type, "needsme") == 0)
@@ -393,7 +399,7 @@ visit_service(const RC_DEPTREE *deptree,
if (!(di = get_depinfo(deptree, service->value)))
continue;
provided = get_provided(di, runlevel, options);
-
+
if (TAILQ_FIRST(provided)) {
TAILQ_FOREACH(p, provided, entries) {
di = get_depinfo(deptree, p->value);
@@ -767,14 +773,14 @@ rc_deptree_update(void)
if (!depinfo || strcmp(depinfo->service, service) != 0) {
deptype = NULL;
depinfo = get_depinfo(deptree, service);
- if (!depinfo) {
+ if (!depinfo) {
depinfo = xmalloc(sizeof(*depinfo));
TAILQ_INIT(&depinfo->depends);
depinfo->service = xstrdup(service);
TAILQ_INSERT_TAIL(deptree, depinfo, entries);
}
}
-
+
/* We may not have any depends */
if (!type || !depends)
continue;
@@ -815,7 +821,7 @@ rc_deptree_update(void)
depend[l - 2] == 's' &&
depend[l - 1] == 'h')
continue;
-
+
/* Remove our dependency if instructed */
if (depend[0] == '!') {
rc_stringlist_delete(deptype->services, depend + 1);
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 97cec38..aa038a3 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -61,7 +61,7 @@ rc_getline(char **line, size_t *len, FILE *fp)
char *p;
size_t last = 0;
- while(!feof(fp)) {
+ while (!feof(fp)) {
if (*line == NULL || last != 0) {
*len += BUFSIZ;
*line = xrealloc(*line, *len);
@@ -218,3 +218,52 @@ rc_config_value(RC_STRINGLIST *list, const char *entry)
return NULL;
}
librc_hidden_def(rc_config_value)
+
+/* Global for caching the strings loaded from rc.conf to avoid reparsing for
+ * each rc_conf_value call */
+static RC_STRINGLIST *rc_conf = NULL;
+
+char *
+rc_conf_value(const char *setting)
+{
+ RC_STRINGLIST *old;
+ RC_STRING *s;
+ char *p;
+
+ if (! rc_conf) {
+ rc_conf = rc_config_load(RC_CONF);
+#ifdef DEBUG_MEMORY
+ atexit(_free_rc_conf);
+#endif
+
+ /* Support old configs */
+ if (exists(RC_CONF_OLD)) {
+ old = rc_config_load(RC_CONF_OLD);
+ TAILQ_CONCAT(rc_conf, old, entries);
+#ifdef DEBUG_MEMORY
+ free(old);
+#endif
+ }
+
+ /* Convert old uppercase to lowercase */
+ TAILQ_FOREACH(s, rc_conf, entries) {
+ p = s->value;
+ while (p && *p && *p != '=') {
+ if (isupper((unsigned char)*p))
+ *p = tolower((unsigned char)*p);
+ p++;
+ }
+ }
+ }
+
+ return rc_config_value(rc_conf, setting);
+}
+librc_hidden_def(rc_conf_value)
+
+#ifdef DEBUG_MEMORY
+static void
+_free_rc_conf(void)
+{
+ rc_stringlist_free(rc_conf);
+}
+#endif
diff --git a/src/librc/librc-stringlist.c b/src/librc/librc-stringlist.c
index c3825cb..818a31c 100644
--- a/src/librc/librc-stringlist.c
+++ b/src/librc/librc-stringlist.c
@@ -146,7 +146,7 @@ librc_hidden_def(rc_stringlist_sort)
void
rc_stringlist_free(RC_STRINGLIST *list)
{
- RC_STRING *s1;
+ RC_STRING *s1;
RC_STRING *s2;
if (!list)
diff --git a/src/librc/librc.c b/src/librc/librc.c
index 8a9fd79..e134547 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -72,7 +72,7 @@ ls_dir(const char *dir, int options)
{
DIR *dp;
struct dirent *d;
- RC_STRINGLIST *list = NULL;
+ RC_STRINGLIST *list = NULL;
struct stat buf;
size_t l;
char file[PATH_MAX];
@@ -198,23 +198,24 @@ file_regex(const char *file, const char *regex)
}
#endif
+/* New sys identification code
+ * Not to be used for any binaries outside of openrc. */
const char *
rc_sys_v2(void)
{
-#define __STRING_SWITCH(x) { char* __string_switch = x; if(false) {}
-#define __STRING_CASE(y) else if(strcmp(__string_switch,y) == 0)
+#define __STRING_SWITCH(x) { char *__string_switch = x; if (false) {}
+#define __STRING_CASE(y) else if (strcmp(__string_switch,y) == 0)
#define __STRING_SWITCH_END() }
- char* systype = rc_conf_value("rc_sys");
- /* New sys identification code */
- if(systype) {
- char* s = systype;
- // Convert to uppercase
- while(s && *s) {
- if(islower((unsigned char)*s))
- *s = toupper((unsigned char)*s);
+ char *systype = rc_conf_value("rc_sys");
+ if (systype) {
+ char *s = systype;
+ /* Convert to uppercase */
+ while (s && *s) {
+ if (islower((unsigned char) *s))
+ *s = toupper((unsigned char) *s);
s++;
}
- // Now do detection
+ /* Now do detection */
__STRING_SWITCH(systype)
__STRING_CASE(RC_SYS_PREFIX) { return RC_SYS_PREFIX; }
#ifdef __FreeBSD__
@@ -241,13 +242,14 @@ rc_sys_v2(void)
}
librc_hidden_def(rc_sys_v2)
-/* Old sys identification code */
+/* Old sys identification code.
+ * Not to be used for any binaries outside of openrc. */
const char *
rc_sys_v1(void)
{
#ifdef PREFIX
return RC_SYS_PREFIX;
-#else
+#else
#ifdef __FreeBSD__
int jailed = 0;
@@ -290,7 +292,7 @@ librc_hidden_def(rc_sys_v1)
const char *
rc_sys(void)
{
- if(rc_conf_value("rc_sys")) {
+ if (rc_conf_value("rc_sys")) {
return rc_sys_v2();
} else {
return rc_sys_v1();
@@ -389,7 +391,7 @@ bool
rc_runlevel_stack(const char *dst, const char *src)
{
char d[PATH_MAX], s[PATH_MAX];
-
+
if (!rc_runlevel_exists(dst) || !rc_runlevel_exists(src))
return false;
snprintf(s, sizeof(s), "../%s", src);
@@ -402,7 +404,7 @@ bool
rc_runlevel_unstack(const char *dst, const char *src)
{
char path[PATH_MAX];
-
+
snprintf(path, sizeof(path), "%s/%s/%s", RC_RUNLEVELDIR, dst, src);
return (unlink(path) == 0 ? true : false);
}
@@ -638,7 +640,7 @@ rc_service_mark(const char *service, const RC_SERVICE state)
}
skip_state = state;
}
-
+
if (state == RC_SERVICE_HOTPLUGGED || state == RC_SERVICE_FAILED) {
free(init);
return true;
@@ -786,7 +788,7 @@ rc_service_value_set(const char *service, const char *option,
{
FILE *fp;
char file[PATH_MAX];
- char *p = file;
+ char *p = file;
p += snprintf(file, sizeof(file), RC_SVCDIR "/options/%s", service);
if (mkdir(file, 0755) != 0 && errno != EEXIST)
diff --git a/src/librc/librc.h b/src/librc/librc.h
index dc97f1d..f04750d 100644
--- a/src/librc/librc.h
+++ b/src/librc/librc.h
@@ -72,6 +72,7 @@
#define librc_hidden_proto(x) hidden_proto(x)
#define librc_hidden_def(x) hidden_def(x)
+librc_hidden_proto(rc_conf_value)
librc_hidden_proto(rc_config_list)
librc_hidden_proto(rc_config_load)
librc_hidden_proto(rc_config_value)
@@ -79,6 +80,7 @@ librc_hidden_proto(rc_deptree_depend)
librc_hidden_proto(rc_deptree_depends)
librc_hidden_proto(rc_deptree_free)
librc_hidden_proto(rc_deptree_load)
+librc_hidden_proto(rc_deptree_load_file)
librc_hidden_proto(rc_deptree_order)
librc_hidden_proto(rc_deptree_update)
librc_hidden_proto(rc_deptree_update_needed)
diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in
index 3d0ffb4..5b06de2 100644
--- a/src/librc/rc.h.in
+++ b/src/librc/rc.h.in
@@ -43,6 +43,14 @@ __BEGIN_DECLS
#define RC_CONFDIR RC_SYSCONFDIR "/conf.d"
#define RC_PLUGINDIR RC_LIBDIR "/plugins"
+#define RC_PROFILE_ENV RC_SYSCONFDIR "/profile.env"
+#define RC_SYS_WHITELIST RC_LIBEXECDIR "/conf.d/env_whitelist"
+#define RC_USR_WHITELIST RC_SYSCONFDIR "/conf.d/env_whitelist"
+#define RC_CONF RC_SYSCONFDIR "/rc.conf"
+#define RC_CONF_OLD RC_SYSCONFDIR "/conf.d/rc"
+
+#define RC_PATH_PREFIX RC_LIBEXECDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin"
+
/* PKG_PREFIX is where packages are installed if different from the base OS
* On Gentoo this is normally unset, on FreeBSD /usr/local and on NetBSD
* /usr/pkg. */
@@ -342,7 +350,7 @@ typedef void *RC_DEPTREE;
* @param target
* @param mtime of newest target
* @param filename of the newest target (needs mtime param)
- * @return true if source is newer than target, otherwise false */
+ * @return true if source is newer than target, otherwise false */
bool rc_newer_than(const char *, const char *, time_t *, char *);
/*! Check to see if source is older than target.
@@ -351,7 +359,7 @@ bool rc_newer_than(const char *, const char *, time_t *, char *);
* @param target
* @param mtime of oldest target
* @param filename of the oldest target (needs mtime param)
- * @return true if source is older than target, otherwise false */
+ * @return true if source is older than target, otherwise false */
bool rc_older_than(const char *, const char *, time_t *, char *);
/*! Update the cached dependency tree if it's older than any init script,
@@ -375,6 +383,11 @@ bool rc_deptree_update_needed(time_t *, char *);
* @return pointer to the dependency tree */
RC_DEPTREE *rc_deptree_load(void);
+/*! Load a cached dependency tree from the specified file and return a pointer
+ * to it. This pointer should be freed with rc_deptree_free when done.
+ * @return pointer to the dependency tree */
+RC_DEPTREE *rc_deptree_load_file(const char *);
+
/*! List the depend for the type of service
* @param deptree to search
* @param type to use (keywords, etc)
@@ -457,6 +470,9 @@ RC_STRINGLIST *rc_config_load(const char *);
/*! Return the value of the entry from a key=value list. */
char *rc_config_value(RC_STRINGLIST *, const char *);
+/*! Return the value of the entry from rc.conf. */
+char *rc_conf_value(const char *);
+
/*! Check if a variable is a boolean and return its value.
* If variable is not a boolean then we set errno to be ENOENT when it does
* not exist or EINVAL if it's not a boolean.
@@ -503,7 +519,7 @@ RC_STRING *rc_stringlist_find(RC_STRINGLIST *, const char *);
RC_STRINGLIST *rc_stringlist_split(const char *, const char *);
-/*! Sort the list according to C locale
+/*! Sort the list according to C locale
* @param list to sort */
void rc_stringlist_sort(RC_STRINGLIST **);
diff --git a/src/librc/rc.map b/src/librc/rc.map
index 113f2d7..c5f10ad 100644
--- a/src/librc/rc.map
+++ b/src/librc/rc.map
@@ -1,5 +1,6 @@
RC_1.0 {
global:
+ rc_conf_value;
rc_config_list;
rc_config_load;
rc_config_value;
@@ -7,6 +8,7 @@ global:
rc_deptree_depends;
rc_deptree_free;
rc_deptree_load;
+ rc_deptree_load_file;
rc_deptree_order;
rc_deptree_update;
rc_deptree_update_needed;
diff --git a/src/rc/Makefile b/src/rc/Makefile
index 9d33192..5397415 100644
--- a/src/rc/Makefile
+++ b/src/rc/Makefile
@@ -41,9 +41,25 @@ include ${MK}/prog.mk
include ${MK}/git.mk
include ${MK}/cc.mk
-include ${MK}/${MKTERMCAP}.mk
+include ${MK}/termcap.mk
LDADD+= ${LIBDL} ${LIBKVM}
-include ${MK}/${MKPAM}.mk
+include ${MK}/pam.mk
+
+# create symlinks to rc if not an SELINUX system, otherwise create a wrapper
+# script to call rc with the proper name of the applet to execute.
+# $1 is a list of the links
+# $2 is the path+name of the target to link to (usually 'rc' or '/sbin/rc')
+# $3 is the path where the links are created
+define make-links
+ for x in $(1); do \
+ if test -n "${MKSELINUX}"; then \
+ printf '#!/bin/sh\nexec ${2} --applet %s "$$@"\n' $$x >${3}/$$x; \
+ chmod ${BINMODE} ${3}/$$x; \
+ else \
+ ln -sf ${2} ${3}/$$x; \
+ fi; \
+ done;
+endef
${SRCS}: version.h
@@ -61,13 +77,13 @@ install: all
${INSTALL} -d ${DESTDIR}${SBINDIR}
${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${SBINDIR}
${INSTALL} -d ${DESTDIR}${BINDIR}
- for x in ${BINLINKS}; do ln -fs ${SBINDIR}/${PROG} ${DESTDIR}${BINDIR}/$$x; done
+ $(call make-links,${BINLINKS},${SBINDIR}/${PROG},${DESTDIR}${BINDIR})
${INSTALL} -d ${DESTDIR}${SBINDIR}
- for x in ${SBINLINKS}; do ln -fs ${PROG} ${DESTDIR}${SBINDIR}/$$x; done
+ $(call make-links,${SBINLINKS},${SBINDIR}/${PROG},${DESTDIR}${SBINDIR})
${INSTALL} -d ${DESTDIR}${LINKDIR}/bin
- for x in $(RC_BINLINKS); do ln -fs ${SBINDIR}/${PROG} ${DESTDIR}${LINKDIR}/bin/$$x; done
+ $(call make-links,${RC_BINLINKS},${SBINDIR}/${PROG},${DESTDIR}${LINKDIR}/bin)
${INSTALL} -d ${DESTDIR}${LINKDIR}/sbin
- for x in ${RC_SBINLINKS}; do ln -fs ${SBINDIR}/${PROG} ${DESTDIR}${LINKDIR}/sbin/$$x; done
+ $(call make-links, ${RC_SBINLINKS},${SBINDIR}/${PROG},${DESTDIR}${LINKDIR}/sbin)
if test "${MKPAM}" = pam; then \
${INSTALL} -d ${DESTDIR}${PAMDIR}; \
${INSTALL} -m ${PAMMODE} start-stop-daemon.pam ${DESTDIR}${PAMDIR}/start-stop-daemon; \
@@ -76,4 +92,4 @@ install: all
check test::
links: rc
- for l in ${ALL_LINKS}; do ln -sf rc $$l || exit $$? ; done
+ $(call make-links,${ALL_LINKS},rc,.)
diff --git a/src/rc/_usage.c b/src/rc/_usage.c
index ec1ce1d..175634a 100644
--- a/src/rc/_usage.c
+++ b/src/rc/_usage.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
* All rights reserved
-
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -24,6 +24,8 @@
* SUCH DAMAGE.
*/
+#include "version.h"
+
#if lint
# define _noreturn
#endif
@@ -34,6 +36,22 @@
#endif
_noreturn static void
+show_version(void)
+{
+ const char *bootlevel = NULL;
+
+ printf("%s (OpenRC", applet);
+ if ((bootlevel = rc_sys()))
+ printf(" [%s]", bootlevel);
+ printf(") %s", VERSION);
+#ifdef BRANDING
+ printf(" (%s)", BRANDING);
+#endif
+ printf("\n");
+ exit(EXIT_SUCCESS);
+}
+
+_noreturn static void
usage(int exit_status)
{
const char * const has_arg[] = { "", "<arg>", "[arg]" };
diff --git a/src/rc/_usage.h b/src/rc/_usage.h
index d65e05e..5e116c9 100644
--- a/src/rc/_usage.h
+++ b/src/rc/_usage.h
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
* All rights reserved
-
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -24,11 +24,12 @@
* SUCH DAMAGE.
*/
-#define getoptstring_COMMON "Chqv"
+#define getoptstring_COMMON "ChqVv"
#define longopts_COMMON \
{ "help", 0, NULL, 'h'}, \
{ "nocolor", 0, NULL, 'C'}, \
+ { "version", 0, NULL, 'V'}, \
{ "verbose", 0, NULL, 'v'}, \
{ "quiet", 0, NULL, 'q'}, \
{ NULL, 0, NULL, 0 }
@@ -36,11 +37,13 @@
#define longopts_help_COMMON \
"Display this help output", \
"Disable color output", \
+ "Display software version", \
"Run verbosely", \
"Run quietly"
#define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1);
#define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS);
+#define case_RC_COMMON_getopt_case_V if (argc == 2) show_version();
#define case_RC_COMMON_getopt_case_v setenv ("EINFO_VERBOSE", "YES", 1);
#define case_RC_COMMON_getopt_case_q setenv ("EINFO_QUIET", "YES", 1);
#define case_RC_COMMON_getopt_default usage (EXIT_FAILURE);
@@ -48,6 +51,7 @@
#define case_RC_COMMON_GETOPT \
case 'C': case_RC_COMMON_getopt_case_C; break; \
case 'h': case_RC_COMMON_getopt_case_h; break; \
+ case 'V': case_RC_COMMON_getopt_case_V; break; \
case 'v': case_RC_COMMON_getopt_case_v; break; \
case 'q': case_RC_COMMON_getopt_case_q; break; \
default: case_RC_COMMON_getopt_default; break;
diff --git a/src/rc/fstabinfo.c b/src/rc/fstabinfo.c
index a05bfae..69b5bbd 100644
--- a/src/rc/fstabinfo.c
+++ b/src/rc/fstabinfo.c
@@ -109,7 +109,7 @@ do_mount(struct ENT *ent)
argv[6] = ENT_FILE(*ent);
argv[7] = NULL;
switch (pid = vfork()) {
- case -1:
+ case -1:
eerrorx("%s: vfork: %s", applet, strerror(errno));
/* NOTREACHED */
case 0:
diff --git a/src/rc/rc-applets.c b/src/rc/rc-applets.c
index 11bc2d5..6068cb6 100644
--- a/src/rc/rc-applets.c
+++ b/src/rc/rc-applets.c
@@ -152,7 +152,7 @@ do_e(int argc, char **argv)
ts.tv_nsec = WAIT_INTERVAL;
for (i = 0; i < argc; i++) {
ebeginv("Waiting for %s", argv[i]);
- for (;;){
+ for (;;) {
if (exists(argv[i]))
break;
if (nanosleep(&ts, NULL) == -1)
@@ -298,7 +298,7 @@ do_service(int argc, char **argv)
}
}
ok = rc_service_started_daemon(service, exec, NULL, idx);
-
+
} else if (strcmp(applet, "service_crashed") == 0) {
ok = (_rc_can_find_pids() &&
rc_service_daemons_crashed(service) &&
@@ -429,6 +429,17 @@ run_applets(int argc, char **argv)
char *p;
pid_t pid = 0;
+ /* Bug 351712: We need an extra way to explicitly select an applet OTHER
+ * than trusting argv[0], as argv[0] is not going to be the applet value if
+ * we are doing SELinux context switching. For this, we allow calls such as
+ * 'rc --applet APPLET', and shift ALL of argv down by two array items. */
+ if (strcmp(applet, "rc") == 0 && argc >= 3 &&
+ (strcmp(argv[1],"--applet") == 0 || strcmp(argv[1], "-a") == 0)) {
+ applet = argv[2];
+ argv += 2;
+ argc -= 2;
+ }
+
/* These are designed to be applications in their own right */
if (strcmp(applet, "fstabinfo") == 0)
exit(fstabinfo(argc, argv));
@@ -476,7 +487,7 @@ run_applets(int argc, char **argv)
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
- };
+ };
if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e'))
exit(do_e(argc, argv));
diff --git a/src/rc/rc-depend.c b/src/rc/rc-depend.c
index 29f23d2..3d00d1a 100644
--- a/src/rc/rc-depend.c
+++ b/src/rc/rc-depend.c
@@ -106,7 +106,7 @@ _rc_deptree_load(int force, int *regen) {
}
#include "_usage.h"
-#define getoptstring "aot:suT" getoptstring_COMMON
+#define getoptstring "aot:suTF:" getoptstring_COMMON
static const struct option longopts[] = {
{ "starting", 0, NULL, 'a'},
{ "stopping", 0, NULL, 'o'},
@@ -114,6 +114,7 @@ static const struct option longopts[] = {
{ "notrace", 0, NULL, 'T'},
{ "strict", 0, NULL, 's'},
{ "update", 0, NULL, 'u'},
+ { "deptree-file", 1, NULL, 'F'},
longopts_COMMON
};
static const char * const longopts_help[] = {
@@ -123,6 +124,7 @@ static const char * const longopts_help[] = {
"Don't trace service dependencies",
"Only use what is in the runlevels",
"Force an update of the dependency tree",
+ "File to load cached deptree from",
longopts_help_COMMON
};
#include "_usage.c"
@@ -141,6 +143,7 @@ rc_depend(int argc, char **argv)
char *runlevel = xstrdup(getenv("RC_RUNLEVEL"));
int opt;
char *token;
+ char *deptree_file = NULL;
types = rc_stringlist_new();
while ((opt = getopt_long(argc, argv, getoptstring,
@@ -166,13 +169,21 @@ rc_depend(int argc, char **argv)
case 'T':
options &= RC_DEP_TRACE;
break;
+ case 'F':
+ deptree_file = xstrdup(optarg);
+ break;
- case_RC_COMMON_GETOPT
+ case_RC_COMMON_GETOPT
}
}
- if (!(deptree = _rc_deptree_load(update, NULL)))
- eerrorx("failed to load deptree");
+ if (deptree_file) {
+ if (!(deptree = rc_deptree_load_file(deptree_file)))
+ eerrorx("failed to load deptree");
+ } else {
+ if (!(deptree = _rc_deptree_load(update, NULL)))
+ eerrorx("failed to load deptree");
+ }
if (!runlevel)
runlevel = rc_runlevel_get();
diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index 4734989..e45c327 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -172,7 +172,7 @@ rc_logger_open(const char *level)
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
if (openpty(&rc_logger_tty, &slave_tty, NULL, &tt, &ws))
return;
- } else
+ } else
if (openpty(&rc_logger_tty, &slave_tty, NULL, NULL, NULL))
return;
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index 0239f9d..64edf68 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -52,61 +52,7 @@
#include "rc-misc.h"
#include "version.h"
-#define PROFILE_ENV RC_SYSCONFDIR "/profile.env"
-#define SYS_WHITELIST RC_LIBEXECDIR "/conf.d/env_whitelist"
-#define USR_WHITELIST RC_SYSCONFDIR "/conf.d/env_whitelist"
-#define RC_CONF RC_SYSCONFDIR "/rc.conf"
-#define RC_CONF_OLD RC_SYSCONFDIR "/conf.d/rc"
-
-#define PATH_PREFIX RC_LIBEXECDIR "/bin:/bin:/sbin:/usr/bin:/usr/sbin"
-
-static RC_STRINGLIST *rc_conf = NULL;
-
-extern char** environ;
-
-#ifdef DEBUG_MEMORY
-static void
-_free_rc_conf(void)
-{
- rc_stringlist_free(rc_conf);
-}
-#endif
-
-char *
-rc_conf_value(const char *setting)
-{
- RC_STRINGLIST *old;
- RC_STRING *s;
- char *p;
-
- if (! rc_conf) {
- rc_conf = rc_config_load(RC_CONF);
-#ifdef DEBUG_MEMORY
- atexit(_free_rc_conf);
-#endif
-
- /* Support old configs */
- if (exists(RC_CONF_OLD)) {
- old = rc_config_load(RC_CONF_OLD);
- TAILQ_CONCAT(rc_conf, old, entries);
-#ifdef DEBUG_MEMORY
- free(old);
-#endif
- }
-
- /* Convert old uppercase to lowercase */
- TAILQ_FOREACH(s, rc_conf, entries) {
- p = s->value;
- while (p && *p && *p != '=') {
- if (isupper((unsigned char)*p))
- *p = tolower((unsigned char)*p);
- p++;
- }
- }
- }
-
- return rc_config_value(rc_conf, setting);
-}
+extern char **environ;
bool
rc_conf_yesno(const char *setting)
@@ -135,7 +81,7 @@ env_filter(void)
/* Add the user defined list of vars */
env_allow = rc_stringlist_split(rc_conf_value("rc_env_allow"), " ");
- profile = rc_config_load(PROFILE_ENV);
+ profile = rc_config_load(RC_PROFILE_ENV);
/* Copy the env and work from this so we can manipulate it safely */
env_list = rc_stringlist_new();
@@ -181,7 +127,7 @@ env_filter(void)
void
env_config(void)
{
- size_t pplen = strlen(PATH_PREFIX);
+ size_t pplen = strlen(RC_PATH_PREFIX);
char *path;
char *p;
char *e;
@@ -199,16 +145,16 @@ env_config(void)
for a little extra security */
path = getenv("PATH");
if (! path)
- setenv("PATH", PATH_PREFIX, 1);
- else if (strncmp (PATH_PREFIX, path, pplen) != 0) {
+ setenv("PATH", RC_PATH_PREFIX, 1);
+ else if (strncmp (RC_PATH_PREFIX, path, pplen) != 0) {
l = strlen(path) + pplen + 3;
e = p = xmalloc(sizeof(char) * l);
- p += snprintf(p, l, "%s", PATH_PREFIX);
+ p += snprintf(p, l, "%s", RC_PATH_PREFIX);
/* Now go through the env var and only add bits not in our
* PREFIX */
while ((token = strsep(&path, ":"))) {
- np = npp = xstrdup(PATH_PREFIX);
+ np = npp = xstrdup(RC_PATH_PREFIX);
while ((tok = strsep(&npp, ":")))
if (strcmp(tok, token) == 0)
break;
@@ -316,7 +262,7 @@ exec_service(const char *service, const char *arg)
fd = svc_lock(basename_c(service));
if (fd == -1)
return -1;
-
+
file = rc_service_resolve(service);
if (!exists(file)) {
rc_service_mark(service, RC_SERVICE_STOPPED);
diff --git a/src/rc/rc-plugin.c b/src/rc/rc-plugin.c
index 592eb09..d82e9a9 100644
--- a/src/rc/rc-plugin.c
+++ b/src/rc/rc-plugin.c
@@ -105,7 +105,7 @@ rc_plugin_load(void)
continue;
}
- fptr = (int (*)(RC_HOOK, const char*))
+ fptr = (int (*)(RC_HOOK, const char *))
dlfunc(h, RC_PLUGIN_HOOK);
if (fptr == NULL) {
eerror("%s: cannot find symbol `%s'",
@@ -200,7 +200,7 @@ rc_plugin_run(RC_HOOK hook, const char *value)
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGWINCH, &sa, NULL);
sigprocmask(SIG_SETMASK, &old, NULL);
-
+
rc_in_plugin = true;
close(pfd[0]);
rc_environ_fd = fdopen(pfd[1], "w");
diff --git a/src/rc/rc.c b/src/rc/rc.c
index b062349..140667a 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -153,7 +153,7 @@ cleanup(void)
#ifdef DEBUG_MEMORY
while (p1) {
- p2 = LIST_NEXT(p1, entries);
+ p2 = LIST_NEXT(p1, entries);
free(p1);
p1 = p2;
}
@@ -315,7 +315,7 @@ open_shell(void)
{
const char *shell;
struct passwd *pw;
-
+
#ifdef __linux__
const char *sys = rc_sys();
@@ -586,7 +586,7 @@ do_stop_services(const char *newlevel, bool parallel, bool going_down)
}
crashed = rc_conf_yesno("rc_crashed_stop");
-
+
nostop = rc_stringlist_split(rc_conf_value("rc_nostop"), " ");
TAILQ_FOREACH_REVERSE(service, stop_services, rc_stringlist, entries)
{
@@ -773,14 +773,16 @@ handle_bad_signal(int sig)
#endif
#include "_usage.h"
-#define getoptstring "o:s:S" getoptstring_COMMON
+#define getoptstring "a:o:s:S" getoptstring_COMMON
static const struct option longopts[] = {
+ { "applet", 1, NULL, 'a' },
{ "override", 1, NULL, 'o' },
{ "service", 1, NULL, 's' },
{ "sys", 0, NULL, 'S' },
longopts_COMMON
};
static const char * const longopts_help[] = {
+ "runs the applet specified by the next argument",
"override the next runlevel to change into\n"
"when leaving single user or boot runlevels",
"runs the service specified with the rest\nof the arguments",
@@ -804,6 +806,7 @@ main(int argc, char **argv)
int opt;
bool parallel;
int regen = 0;
+ int i;
#ifdef __linux__
char *proc;
char *p;
@@ -822,18 +825,6 @@ main(int argc, char **argv)
if (!applet)
eerrorx("arguments required");
- if (argc > 1 && (strcmp(argv[1], "--version") == 0)) {
- printf("%s (OpenRC", applet);
- if ((bootlevel = rc_sys()))
- printf(" [%s]", bootlevel);
- printf(") " VERSION
-#ifdef BRANDING
- " (" BRANDING ")"
-#endif
- "\n");
- exit(EXIT_SUCCESS);
- }
-
/* Run our built in applets. If we ran one, we don't return. */
run_applets(argc, argv);
@@ -855,6 +846,10 @@ main(int argc, char **argv)
longopts, (int *) 0)) != -1)
{
switch (opt) {
+ case 'a':
+ /* Do nothing, actual logic in run_applets, this
+ * is a placeholder */
+ break;
case 'o':
if (*optarg == '\0')
optarg = NULL;
@@ -880,18 +875,18 @@ main(int argc, char **argv)
case 'S':
if (rc_conf_value("rc_sys")) {
bootlevel = rc_sys_v2();
- if(bootlevel)
+ if (bootlevel)
printf("%s\n", bootlevel);
} else {
ewarn("WARNING: rc_sys not defined in rc.conf. Falling back to automatic detection");
bootlevel = rc_sys_v1();
- if(bootlevel)
+ if (bootlevel)
printf("%s\n", bootlevel);
}
exit(EXIT_SUCCESS);
/* NOTREACHED */
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
}
newlevel = argv[optind++];
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index 1c60c24..0eca487 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -451,7 +451,7 @@ svc_exec(const char *arg1, const char *arg2)
signal_pipe[0] = signal_pipe[1] = -1;
sigprocmask (SIG_SETMASK, &oldmask, NULL);
-
+
if (master_tty >= 0) {
/* Why did we do this? */
/* signal (SIGWINCH, SIG_IGN); */
@@ -572,7 +572,7 @@ svc_start_check(void)
RC_SERVICE state;
state = rc_service_state(service);
-
+
if (in_background) {
if (!(state & (RC_SERVICE_INACTIVE | RC_SERVICE_STOPPED)))
exit(EXIT_FAILURE);
@@ -583,7 +583,7 @@ svc_start_check(void)
" next runlevel", applet);
}
- if (exclusive_fd == -1)
+ if (exclusive_fd == -1)
exclusive_fd = svc_lock(applet);
if (exclusive_fd == -1) {
if (errno == EACCES)
@@ -603,7 +603,7 @@ svc_start_check(void)
else if (state & RC_SERVICE_INACTIVE && !in_background)
ewarnx("WARNING: %s has already started, but is inactive",
applet);
-
+
rc_service_mark(service, RC_SERVICE_STARTING);
hook_out = RC_HOOK_SERVICE_START_OUT;
rc_plugin_run(RC_HOOK_SERVICE_START_IN, applet);
@@ -619,7 +619,7 @@ svc_start_deps(void)
size_t len;
char *p, *tmp;
pid_t pid;
-
+
errno = 0;
if (rc_conf_yesno("rc_depend_strict") || errno == ENOENT)
depoptions |= RC_DEP_STRICT;
@@ -725,7 +725,7 @@ svc_start_deps(void)
n = 0;
TAILQ_FOREACH(svc, tmplist, entries) {
rc_service_schedule_start(svc->value, service);
- use_services = rc_deptree_depend(deptree,
+ use_services = rc_deptree_depend(deptree,
"iprovide", svc->value);
TAILQ_FOREACH(svc2, use_services, entries)
rc_service_schedule_start(svc2->value, service);
@@ -760,7 +760,7 @@ static void svc_start_real()
{
bool started;
RC_STRING *svc, *svc2;
-
+
if (ibsave)
setenv("IN_BACKGROUND", ibsave, 1);
hook_out = RC_HOOK_SERVICE_START_DONE;
@@ -873,7 +873,7 @@ svc_stop_deps(RC_SERVICE state)
if (state & RC_SERVICE_WASINACTIVE)
return;
-
+
errno = 0;
if (rc_conf_yesno("rc_depend_strict") || errno == ENOENT)
depoptions |= RC_DEP_STRICT;
@@ -941,7 +941,7 @@ svc_stop_deps(RC_SERVICE state)
}
rc_stringlist_free(tmplist);
tmplist = NULL;
-
+
/* We now wait for other services that may use us and are
* stopping. This is important when a runlevel stops */
services = rc_deptree_depends(deptree, types_mua, applet_list,
@@ -959,7 +959,7 @@ static void
svc_stop_real(void)
{
bool stopped;
-
+
/* If we're stopping localmount, set LC_ALL=C so that
* bash doesn't load anything blocking the unmounting of /usr */
if (strcmp(applet, "localmount") == 0)
@@ -1138,7 +1138,7 @@ runscript(int argc, char **argv)
file = basename_c(argv[1]);
else
file = basename_c(lnk);
- dir = save;
+ dir = save;
} else
file = basename_c(argv[1]);
ll = strlen(dir) + strlen(file) + 2;
@@ -1206,7 +1206,7 @@ runscript(int argc, char **argv)
#endif
deps = true;
-
+
/* Punt the first arg as its our service name */
argc--;
argv++;
@@ -1363,7 +1363,7 @@ runscript(int argc, char **argv)
RC_SERVICE_INACTIVE)
{
TAILQ_FOREACH(svc,
- restart_services,
+ restart_services,
entries)
if (rc_service_state(svc->value) &
RC_SERVICE_STOPPED)
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index bd6c7bf..72b8aff 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -43,7 +43,7 @@
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
-#include <sys/termios.h>
+#include <termios.h>
#include <sys/time.h>
#include <sys/wait.h>
@@ -322,7 +322,7 @@ get_pid(const char *pidfile, bool quiet)
fclose(fp);
return -1;
}
-
+
fclose(fp);
return pid;
@@ -631,7 +631,7 @@ static const struct option longopts[] = {
longopts_COMMON
};
static const char * const longopts_help[] = {
- "Set an ionice class:data when starting",
+ "Set an ionice class:data when starting",
"Stop daemon",
"Set a nicelevel when starting",
"Retry schedule to use when stopping",
@@ -1210,7 +1210,7 @@ start_stop_daemon(int argc, char **argv)
/* Clean the environment of any RC_ variables */
env_list = rc_stringlist_new();
i = 0;
- while(environ[i])
+ while (environ[i])
rc_stringlist_add(env_list, environ[i++]);
#ifdef HAVE_PAM
@@ -1343,7 +1343,7 @@ start_stop_daemon(int argc, char **argv)
if (start_wait > 0) {
struct timespec ts;
bool alive = false;
-
+
ts.tv_sec = start_wait / 1000;
ts.tv_nsec = (start_wait % 1000) * ONE_MS;
if (nanosleep(&ts, NULL) == -1) {
diff --git a/src/test/.gitignore b/src/test/.gitignore
index c4816ef..1b79b9f 100644
--- a/src/test/.gitignore
+++ b/src/test/.gitignore
@@ -1,5 +1,6 @@
einfo.data.out
einfo.funcs.out
librc.funcs.hidden.out
+librc.funcs.hidden.list
rc.data.out
-rc.funcs.out
\ No newline at end of file
+rc.funcs.out
diff --git a/src/test/librc.funcs.hidden.list b/src/test/librc.funcs.hidden.list
deleted file mode 100644
index b661850..0000000
--- a/src/test/librc.funcs.hidden.list
+++ /dev/null
@@ -1,56 +0,0 @@
-rc_config_list
-rc_config_load
-rc_config_value
-rc_deptree_depend
-rc_deptree_depends
-rc_deptree_free
-rc_deptree_load
-rc_deptree_order
-rc_deptree_update
-rc_deptree_update_needed
-rc_find_pids
-rc_getline
-rc_newer_than
-rc_older_than
-rc_runlevel_exists
-rc_runlevel_get
-rc_runlevel_list
-rc_runlevel_set
-rc_runlevel_stack
-rc_runlevel_stacks
-rc_runlevel_starting
-rc_runlevel_stopping
-rc_runlevel_unstack
-rc_service_add
-rc_service_daemon_set
-rc_service_daemons_crashed
-rc_service_delete
-rc_service_description
-rc_service_exists
-rc_service_extra_commands
-rc_service_in_runlevel
-rc_service_mark
-rc_service_resolve
-rc_service_schedule_clear
-rc_service_schedule_start
-rc_service_started_daemon
-rc_service_state
-rc_service_value_get
-rc_service_value_set
-rc_services_in_runlevel
-rc_services_in_runlevel_stacked
-rc_services_in_state
-rc_services_scheduled
-rc_services_scheduled_by
-rc_stringlist_add
-rc_stringlist_addu
-rc_stringlist_delete
-rc_stringlist_find
-rc_stringlist_free
-rc_stringlist_new
-rc_stringlist_sort
-rc_stringlist_split
-rc_sys
-rc_sys_v1
-rc_sys_v2
-rc_yesno
diff --git a/src/test/rc.funcs.list b/src/test/rc.funcs.list
index 0aac8f9..a8b011f 100644
--- a/src/test/rc.funcs.list
+++ b/src/test/rc.funcs.list
@@ -1,3 +1,5 @@
+rc_conf_value
+rc_conf_value@@RC_1.0
rc_config_list
rc_config_list@@RC_1.0
rc_config_load
@@ -12,6 +14,8 @@ rc_deptree_free
rc_deptree_free@@RC_1.0
rc_deptree_load
rc_deptree_load@@RC_1.0
+rc_deptree_load_file
+rc_deptree_load_file@@RC_1.0
rc_deptree_order
rc_deptree_order@@RC_1.0
rc_deptree_update
diff --git a/src/test/runtests.sh b/src/test/runtests.sh
index 076bd75..4731bd7 100755
--- a/src/test/runtests.sh
+++ b/src/test/runtests.sh
@@ -57,6 +57,7 @@ sed -n '/^librc_hidden_proto/s:.*(\(.*\))$:\1:p' ${librc_srcdir}/librc.h \
| LC_ALL=C sort -u \
> librc.funcs.hidden.list
readelf -Wr $(grep -l '#include[[:space:]]"librc\.h"' ${librc_srcdir}/*.c | sed 's:\.c$:.o:') \
+ | egrep -v -e 'R_PARISC_(DP|SEG)REL' \
| awk '$5 ~ /^rc_/ {print $5}' \
| LC_ALL=C sort -u \
| egrep -v '^rc_environ_fd$' \
@@ -66,6 +67,50 @@ syms=$(diff -u librc.funcs.hidden.list librc.funcs.hidden.out | sed -n '/^+[^+]/
eend $? "Missing hidden defs:"$'\n'"${syms}"
ret=$(($ret + $?))
+ebegin "Checking trailing whitespace in code"
+# XXX: Should we check man pages too ?
+out=$(cd ${top_srcdir}; find */ \
+ '(' -name '*.[ch]' -o -name '*.in' -o -name '*.sh' ')' \
+ -exec grep -n -E '[[:space:]]+$' {} +)
+[ -z "${out}" ]
+eend $? "Trailing whitespace needs to be deleted:"$'\n'"${out}"
+
+ebegin "Checking trailing newlines in code"
+out=$(cd ${top_srcdir};
+ for f in `find */ -name '*.[ch]'` ; do
+ sed -n -e :a -e '/^\n*$/{$q1;N;ba' -e '}' $f || echo $f
+ done)
+[ -z "${out}" ]
+eend $? "Trailing newlines need to be deleted:"$'\n'"${out}"
+
+ebegin "Checking for obsolete functions"
+out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
+ -exec grep -n -E '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' {} +)
+[ -z "${out}" ]
+eend $? "Avoid these obsolete functions:"$'\n'"${out}"
+
+ebegin "Checking for x* func usage"
+out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
+ -exec grep -n -E '\<(malloc|strdup)[[:space:]]*\(' {} + \
+ | grep -v \
+ -e src/includes/rc-misc.h \
+ -e src/libeinfo/libeinfo.c)
+[ -z "${out}" ]
+eend $? "These need to be using the x* variant:"$'\n'"${out}"
+
+ebegin "Checking spacing style"
+out=$(cd ${top_srcdir}; find src -name '*.[ch]' \
+ -exec grep -n -E \
+ -e '\<(for|if|switch|while)\(' \
+ -e '\<(for|if|switch|while) \( ' \
+ -e ' ;' \
+ -e '[[:space:]]$' \
+ -e '\){' \
+ -e '(^|[^:])//' \
+ {} +)
+[ -z "${out}" ]
+eend $? "These lines violate style rules:"$'\n'"${out}"
+
einfo "Running unit tests"
eindent
for u in units/*; do
diff --git a/test/setup_env.sh b/test/setup_env.sh
index 6794913..9f3a3fd 100755
--- a/test/setup_env.sh
+++ b/test/setup_env.sh
@@ -9,14 +9,18 @@ srcdir=${srcdir:-.}
top_builddir=${top_builddir:-${top_srcdir}}
builddir=${builddir:-${srcdir}}
-if ! . ${top_srcdir}/sh/functions.sh; then
+export LD_LIBRARY_PATH=${top_builddir}/src/libeinfo:${top_builddir}/src/librc:${LD_LIBRARY_PATH}
+export PATH=${top_builddir}/src/rc:${PATH}
+
+
+if [ ! -f ${top_srcdir}/sh/functions.sh ] ; then
+ echo "functions.sh not yet created !?" 1>&2
+ exit 1
+elif ! . ${top_srcdir}/sh/functions.sh; then
echo "Sourcing functions.sh failed !?" 1>&2
exit 1
fi
-export LD_LIBRARY_PATH=${top_builddir}/src/libeinfo:${top_builddir}/src/librc:${LD_LIBRARY_PATH}
-export PATH=${top_builddir}/src/rc:${PATH}
-
cd ${top_srcdir}/src/rc
${MAKE:-make} links >/dev/null
cd -
|