1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
|
2007-06-22 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_run_process): Replace the arguments from the event
with a list of event names.
* init/tests/test_job.c (test_run_process): Update test case to
supply arguments from the list of events.
* init/process.c (process_setup_environment): Drop the UPSTART_EVENT
environment variable; it doesn't make sense when you can have multiple
events.
(process_setup_environment): Put all variables from the job's start
events into the job's environment; replacing the UPSTART_EVENT variable
* init/job.c (job_change_cause): Don't notify the job event
subscribers when changing the cause.
* init/notify.c (notify_job_finished): Instead notify them when
the job reaches a rest state.
* init/notify.c (notify_job): Call notify_job_event regardless,
since this now looks over the start_on and stop_on fields.
(notify_job_event): Rewrite to iterate over start_on and stop_on,
and notifying for each cause event found.
(notify_job_event_caused): Static function that is the guts of the
above function.
* init/tests/test_notify.c (test_job, test_job_event): Modify tests
to refer exclusively to the start_on/stop_on expressions rather than
the cause.
* init/job.c (job_change_cause): Only notify the job event and
update the cause member, we don't need to ref or block it anymore
since that's handled by start_on and stop_on.
* init/tests/test_job.c (test_change_goal): Drop checks on cause
being referenced and blocked.
(test_change_state, test_child_reaper, test_handle_event): Update
test cases to not reference ->cause, and not count any references
or blockers towards it.
* init/tests/test_event.c (test_poll): Update expected reference
and block counts for events handled by jobs.
* init/tests/test_process.c (test_kill): Make sure that all processes
in the process group are killed, rather than just the lone one.
* init/process.c (process_kill): Send the signal to all processes
in the same process group as the pid.
* init/tests/test_job.c (test_change_state, test_kill_process):
After spawning a child, call setpgid() to put it in its own process
group otherwise we could end up TERMing ourselves.
* init/tests/test_job.c (test_child_reaper): Update test cases to
include checking of the start_on and stop_on expression trees.
* init/job.c (job_child_reaper): Mark all blocked events in the
start_on and stop_on trees as failed; since these are copies of
the cause event, we can drop that setting already.
* TODO: Update again, still thinking about the atomicity of event
expressions.
2007-06-21 Scott James Remnant <scott@netsplit.com>
* init/tests/test_job.c (test_change_state): Include tests on a job's
start_on and stop_on event expression trees, and make sure that events
are unblocked and unreferenced at the appropriate moments.
* init/job.c (job_change_state): Unblock the events that started the
job in running (if a service), and reset when we reach waiting (leave
referenced otherwise so the environment is always present).
Unblock and unreference the events that stopped the job in
starting (for restarting), running (if coming from pre-stop) and
waiting.
* init/tests/test_job.c (test_handle_event): Rewrite tests using
event expressions, and make sure events are referenced and blocked
correctly matching how jobs are affected. Include tests for correct
instance behaviour.
(test_instance): Make sure that instances copy across the expression
state, and reset the parent.
* init/job.c (job_instance): After spawning a new instance, reset
the start_on expression of the master job.
* init/event.c (event_operator_copy): Change to making the parent
of copies nodes be the actual tree parent, rather than the top
parent; otherwise you can't free an entire tree in one go.
* init/tests/test_event.c (test_operator_copy): Check parents of
copied nodes.
* init/tests/test_job.c (test_copy): Update parent checks here too.
* init/tests/test_job.c (test_copy): Make sure that the job copy
references and blocks the event; and in the event of failure, doesn't
* init/job.c (job_copy): Reset the start_on and stop_on expressions
in the event of failure.
2007-06-20 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* init/parse_job.c (parse_on): New generic parsing function to deal
with event expressions, including operators, parentheses, etc.
(parse_on_operator): Function called by parse_on() to deal with an
operator or operand.
(parse_on_paren): Function called by parse_on() to deal with a
parenthesis.
(parse_on_operand): Function called by parse_on_operator() to deal
with a non-operator token.
(parse_on_collect): Function called by all of the above to collect
the operators on the stack and deposit them into the output box,
either for collection by a later operator or for returning from
parse_on().
(stanza_start, stanza_stop): Call the new parse_on() function to
deal with "start on" and "stop on", storing it in the appropriate
part of the job.
* init/tests/test_parse_job.c (test_parse_job): Replace list empty
checks for start_events/stop_events with NULL checks on the new
start_on/stop_on members.
(test_stanza_start, test_stanza_stop): Test new stanza code.
* init/errors.h (PARSE_EXPECTED_EVENT, PARSE_EXPECTED_OPERATOR)
(PARSE_MISMATCHED_PARENS): Add numerics and strings for the errors
that can be generated by parsing an event expression.
* init/conf.c (conf_reload_path): Handle the new errors properly,
including the line number where they occurred.
* logd/jobs.d/logd.in: Update "stop on" to work with the new parser.
* init/parse_job.c (stanza_emits): Each entry in the emits list
is now an NihListEntry with the event name as the string data
pointer, rather than an EventInfo structure (since that structure
is gone).
* init/tests/test_parse_job.c (test_stanza_emits): Update test
case to check for NihListEntry structures.
* init/parse_job.c: Where the stanza function parses an argument and
can possibly reject it, save the position and line number and do not
return that unless we're happy with the argument. This ensures errors
are raised pointing *at* the argument, rather than past it.
* init/tests/test_parse_job.c: Fix several test case errors where
the buffer was built incorrectly. Pedantically check pos and lineno
after successful parsing, and after errors, to make sure they are
where they should be.
2007-06-18 Scott James Remnant <scott@netsplit.com>
* init/job.h (Job): Replace the start_events and stop_events NihLists
with start_on and stop_on EventOperators.
* init/job.c (job_new): Drop list initialising, and instead just set
the new start_on/stop_on members to NULL.
(job_copy): Copy the entire event operator tree to the new job,
including references and blockers. emits has changed to a list of
NihListEntry with embedded strings, so copy them that way.
(job_run_process): Drop "->info."
(job_handle_event): Instead of iterating the events lists, call
event_operator_handle and check the return value and top node value.
(job_detect_stalled): Modify to iterate the start_on tree.
* init/tests/test_job.c (test_change_state, test_detect_stalled):
Drop references to "->info." since we can get the variables directly.
(test_new): Check that start_on and stop_on are NULL.
(test_copy): Adjust tests of copying start_on and stop_on trees as
well as the emits list.
(test_handle_event, test_handle_event_finished)
(test_detect_stalled): Change references from start_events to start_on,
stop_events to stop_on and construct using EventOperators instead.
(test_handle_event): Update number of blockers now that the event
expressions themselves will block the event.
* init/tests/test_event.c (test_poll): Update number of blockers since
both the events and cause will block it for now; also change
start_events and stop_events to start_on and stop_on respectively.
* init/event.c (event_operator_copy): Copy the children nodes as well.
* init/tests/test_event.c (test_operator_copy): Test copying
with children nodes.
* init/tests/test_control.c (test_event_emit): Drop "->info."
* init/notify.c (notify_event, notify_event_finished): Drop
"->info." from event references.
* init/process.c (process_setup_environment): Drop "->info." from
cause references
* init/tests/test_process.c (test_spawn): Likewise.
* init/event.h (Event): Directly include the name, args and env
fields rather than using an interim structure; this makes more sense
since we use them differently than a match does.
(EventOperatorType, EventOperator): New structure to build event
expression trees that combine a match with "or" and "and" boolean
operators; solve some problems by holding the reference and blocker
on the matched event inside this structure directly and provide
methods to unblock and reset them.
(EventInfo): Drop this structure completely now that it is unused.
* init/event.c (event_info_new): Rename this structure to
event_operator_new() and initialise the new fields properly.
(event_info_copy): Likewise rename to event_operator_copy and deal
with copying event references and blockers over to the new structure,
since the state is useful to copy.
(event_match): Rename to event_operator_match and switch the arguments
around since it makes slightly more sense that way.
(event_operator_update): Function to update the value of an EVENT_OR
or EVENT_AND operator based on the value of the two children.
(event_operator_handle): Function to iterate an entire expression
tree looking for a given event, and update the values of other
operators if matched.
(event_operator_unblock): Function to iterate an expression tree
and release any events we're blocking.
(event_operator_reset): Function to iterate an expression tree,
unreferencing any events and resetting all values back to FALSE.
(event_new, event_pending, event_finished): Update references to
the Event structure to discard the intermediate "->info."
* init/tests/test_event.c (test_info_new): Rename to
test_operator_new() and test various features of the function added
in the converstion.
(test_info_copy): Likewise rename to test_operator_copy() and add a
few more tests, especially that blockers and references are copied.
(test_match): Rename to test_operator_match() and adjust argument
order to match the change.
(test_new) Call event_init() to avoid a valgrind error and update
references to drop "->info."
(test_poll): Use EventOperators in the job to test event polling,
rather than the old structures.
(test_operator_update, test_operator_handle, test_operator_unblock)
(test_operator_reset): Test behaviour of the new functions.
2007-06-13 Scott James Remnant <scott@netsplit.com>
* TODO: Update utmp/wtmp thoughts.
2007-06-12 Scott James Remnant <scott@netsplit.com>
* init/paths.h: Remove extra /, oops.
* init/Makefile.am (install-data-local): Make destination
configuration directories as part of "make install".
(AM_CPPFLAGS): Define LEGACY_CONFDIR to be $(sysconfdir)/event.d
* logd/Makefile.am (jobs.d/logd): Replace mkdir_p with MKDIR_P
* init/main.c: Use macro to pick up /etc/event.d so it can be moved
by configure
* TODO: Update.
* init/Makefile.am (AM_CPPFLAGS): Define CONFDIR to be
$(sysconfdir)/init, replacing the old CFG_DIR definition.
* init/paths.h (CFG_DIR): Replace with CONFDIR definition,
and set the default to /etc/init
* init/main.c: Load configuration from /etc/init/init.conf,
/etc/init/conf.d and /etc/init/jobs.d; retain loading from /etc/event.d
for the time being.
* init/man/init.8: Change reference to directory.
* logd/Makefile.am: Replace references of eventdir with jobsdir,
and event.d with jobs.d
* logd/event.d: Rename to logd/jobs.d
* init/conf.c (conf_reload): Ignore ENOENT, it's not interesting
in the general case.
* init/tests/test_conf.c (test_source_reload): Test the general
reload function.
* init/tests/test_conf.c (test_source_free): s/unlink/rmdir/
(test_source_reload_file): Test that configuration files work, and
are parsed with anything alongside ignored automatically.
* init/conf.c (conf_file_filter): As well as not filtering out the
source path itself, we also need to not filter out the path we're
watching which is different in the case of files; we need to know
about it because we handle its removal.
(conf_delete_handler): Compare the path deleted against the path
we're watching, rather than the source path, since this means the
watch needs to be freed.
* compat/sysv/shutdown.c: Use nih pidfile functions since they're
more reliable than doing it ourselves.
2007-06-11 Scott James Remnant <scott@netsplit.com>
* init/conf.c (conf_reload_path): Call parse_conf for mixed files
and directories. Make a correction to the old_items code, was
passing the wrong arguments to nih_list_add; the effect we wanted
was that we add the old items head into the list, and remove the
existing head (what we did was add the first item to the old_items
list and then cut the rest out).
* init/tests/test_conf.c (test_source_reload_dir): Rename to
test_source_reload_job_dir, since that's what this does.
(test_source_reload_conf_dir): Add another function that tests
directories of mixed configuration.
* init/parse_conf.c (parse_conf): Parse a configuration file that
defines jobs by name.
(stanza_job): Job stanza, slightly trickier than it would appear to
need to be, to parse the block in-place and keep pos/lineno
consistent.
* init/parse_conf.h: Prototype for external function.
* init/tests/test_parse_conf.c: Test suite for mixed configuration
parsing.
* init/Makefile.am (init_SOURCES): Build and link parse_conf.c and
parse_conf.h
(TESTS): Build and run parse_conf tests
(test_parse_conf_SOURCES, test_parse_conf_LDFLAGS)
(test_parse_conf_LDADD): Details for parse_conf test suite.
(test_conf_LDADD): Add parse_conf.o and conf.o since this calls
them now.
* init/conf.c (conf_source_reload, conf_source_reload)
(conf_reload_path): Add some debugging messages.
* init/conf.c (conf_source_new): Add missing call to conf_init()
* init/conf.c (conf_item_new): Drop source parameter, since it's
unused in the function and makes it harder to call this when we
only have one data pointer.
(conf_reload_path): Drop source from conf_item_new() call.
* init/conf.h: Update prototype.
* init/tests/test_conf.c (test_item_new, test_item_free)
(test_file_free): Drop source parameter from calls.
2007-06-10 Scott James Remnant <scott@netsplit.com>
* init/main.c (main): Add a handler for the SIGHUP signal
(hup_handler): Handler for SIGHUP, just calls conf_reload().
* init/main.c (main): Read the configuration again.
* TODO: Update.
* init/tests/test_conf.c (test_source_reload_dir): Reset the priority
and clean up consumed inotify instances.
(test_source_free, test_file_free, test_item_free): Test the free
functions on their own, paying special attention to conf_item_free()
even though this really duplicates other tests.
* init/conf.c (conf_reload_path): In the case where we fail to map
the file into memory, we still need to purge all the items that
previously existed.
* init/tests/test_conf.c (test_source_reload): Rename to
test_source_reload_dir, so that we can keep this and the file
tests separate to make it easier to deal with.
(test_source_reload_dir): Add tests for physical and parse errors
when re-loading jobs with and without inotify, and for inotify-based
modification handling of jobs.
* init/tests/test_conf.c (test_source_reload): Add test for walk
of non-existant directory with and without inotify; also test for
what happens when the top-level directory is deleted, again with
and without inotify.
* init/conf.c (conf_delete_handler): Handle the case of the top-level
directory being deleted by freeing the watch (so next time we asked
to reload, we can restore it).
* init/tests/test_conf.c (test_source_reload): Add a test for
deletion of a running job.
* init/conf.c (conf_item_free): Fix this up; when deleting an item
from a source, we first mark it for deletion unless it's already
marked for replacement. Then if it's the replacement for something
else, we mark that to be replaced by whatever we're being replaced
by (so there are no references to us) and change that state if
necessary. Finally we replace our own item and free the record
before returning.
* init/tests/test_conf.c (test_source_reload): Check that we handle
the cases of modiciation of a running job, modification of a
replacement of a running job and deletion of a replacement for a
running job.
* init/parse_job.c (parse_job): Instead of freeing the previous
replacement, which could leave invalid references to it, mark it
for deletion and change the state.
* init/tests/test_parse_job.c (test_parse_job): Adjust the test so
that we hold a reference to the replacement job and make sure that
the state is changed to deleted, rather than checking for a destructor
being called on it.
* init/init.supp (conf-init): Add valgrind suppression for the
configuration sources hash table.
* init/conf.c (conf_item_free): Don't overwrite any previous
replacement, only mark us for deletion if we wouldn't otherwise
be replaced. Add some commented possible code for testing.
* init/tests/test_conf.c (test_source_reload): Test replacement of
jobs works properly; test modification with direct write and with
atomic rename replace; test deletion.
* init/conf.c (conf_reload_path): It turns out that the flag trick
doesn't work for items since we often reparse them within the same
file tag (it works with files because they're atomic and reparsed).
Store the old items in a different list instead.
(conf_source_free): We need to be careful about freeing sources,
so have a function to do it properly.
(conf_item_new): Since the flag member isn't useful, don't bother
setting it.
* init/conf.h: Add conf_source_free prototype.
(ConfFile): Remove flag member.
* init/tests/test_conf.c (test_source_reload): Add test for inotify
create detection.
* init/conf.c (conf_file_delete): Rename to conf_file_free and match
the pattern of those kinds of functions.
(conf_item_delete): Likewise rename to conf_item_free and match the
pattern of these kinds of functions.
* init/conf.h: Add prototypes.
* init/conf.c (conf_reload_path): Fix bug with job name generation.
Allow non-parsing errors to be returned from the function.
(conf_item_delete): Drop all replacement management code, we'll put
this back through testing.
* init/tests/test_conf.c (test_source_reload): Test reloading adds
the right inotify watch and parses the files, also check that loading
without inotify and mandatory reloading work.
* init/conf.c (conf_source_reload): Move the item deletion detection
code from this function, where it would only happen on a mandatory
reload
(conf_reload_path): to this function, where it will happen every time
the file is parsed; which is actually what we want.
2007-06-08 Scott James Remnant <scott@netsplit.com>
* init/conf.h (ConfItem): Drop the name and replace it with a type.
(ConfItemType): Enum for different types of configuration items
(ConfFile): Change items from a hash table to a list.
* init/conf.c (conf_file_get): Initialise the items member as a list.
(conf_item_set): Rename to conf_item_new again.
(conf_item_new): Allocates a new ConfItem and adds it to the file's
list, we won't reuse items anymore since it doesn't really make sense.
(conf_source_reload): Adjust clean-up code now that items is a list.
(conf_reload_path): Work out the name of jobs found by filename,
allocate a new item for them and parse the job into it. Perform
handling of errors by outputting a warning.
(conf_item_delete): Takes both source and file so we can make
intelligent decisions.
(conf_file_delete): Takes a source and passes it to conf_item_delete
(conf_delete_handler): Pass both source and file to conf_file_delet
* init/tests/test_conf.c (test_file_get): Check that the items
list is empty; rather than the hash being unallocated.
(test_item_set): Rename back to test_item_new and only allocate a
single item which should get added to the list.
2007-06-06 Scott James Remnant <scott@netsplit.com>
* init/parse_job.c (stanza_respawn): Permit the word "unlimited",
raise a specific error for illegal limit and illegal interval.
(stanza_pid, stanza_kill, stanza_normal, stanza_umask)
(stanza_nice, stanza_limit): Raise specific errors rather than
a generic "illegal value" error.
* init/tests/test_parse_job.c (test_stanza_respawn): Check that
we can use "unlimited", also check for new error return.
(test_stanza_pid, test_stanza_kill, test_stanza_normal)
(test_stanza_umask, test_stanza_nice, test_stanza_limit): Check
for new specific errors.
* init/errors.h: Replace CFG_ILLEGAL_VALUE with a series of parse
errors.
* init/conf.c: Comments.
* init/conf.c (conf_item_set): Call out to conf_item_delete() to
handle unsetting of an item's data.
(conf_source_reload): Add code to deal with mandatory reloading,
calls conf_file_delete() and/or conf_item_delete() as appropriate.
(conf_delete_handler): Call conf_file_delete() on the ConfFile that
we find.
(conf_file_delete): Function to delete all items in a file.
(conf_item_delete): Placeholder function to delete an item.
* init/conf.c (conf_file_new): Rename to conf_file_get; in practice
we never just want to allocate one of these, we always want to
return the existing entry if it exists.
(conf_item_new): Rename to conf_item_set; again in practice we always
want to update an existing item. This function will grow the "deal
with replacement" stuff.
(conf_reload): Start putting in place the code that will allow
mandatory reloads, as well as initial setup. This function iterates
over the sources and deals with errors.
(conf_source_reload): Function to reload an individual source, calls
out to one of the following two functions and will eventually perform
the deleted items scan.
(conf_source_reload_file): Set up a watch on a file, and reload it.
(conf_source_reload_dir): Set up a watch on a directory and reload it.
(conf_file_filter): Filter for watching parent directory of files.
(conf_create_modify_handler): File creation and modification handler.
(conf_delete_handler): File deletion handler.
(conf_file_visitor): Tree walk handler.
(conf_reload_path): Function that deals with files themselves,
currently just sorts out the ConfFile structure and maps the file
into memory.
* init/conf.h: Add new prototypes, update existing ones.
* init/tests/test_conf.c (test_file_new): Rename to test_file_get,
also test repeated calls when already in the table.
(test_item_new): Rename to test_item_set, also test repeated calls
when already in the table.
(test_source_reload): Start of test for reloading sources.
2007-06-05 Scott James Remnant <scott@netsplit.com>
* init/conf.c: Make a start on the new configuration management
routines, which will allow finer-grained tracking of configuration
and support mandatory reloading.
(conf_source_new, conf_file_new, conf_item_new): Start off with the
functions to allocate the tracking structures we need to use.
* init/conf.h: Structures and prototypes
* init/tests/test_conf.c: Test suite for allocation functions.
* init/Makefile.am (init_SOURCES): Build and link conf.c and conf.h
(TESTS): Run the conf test suite.
(test_conf_SOURCES, test_conf_LDFLAGS, test_conf_LDADD): Details for
the conf test suite.
2007-06-04 Scott James Remnant <scott@netsplit.com>
* init/parse_job.c (stanza_description, stanza_author, stanza_version)
(stanza_chroot, stanza_chdir, stanza_pid): Instead of erroring when
the string has already been allocated, free it and replace it with the
new one. Attempting to forbid duplicates is just too inconsistent,
especially for the integer ones which we compare against the default;
using the last one allows us to be entirely consistent.
(stanza_daemon, stanza_respawn, stanza_service, stanza_instance):
Don't error if the flag is already set, just ignore it.
(stanza_respawn, stanza_pid, stanza_kill, stanza_console)
(stanza_umask, stanza_nice): Don't compare the current value against
the default, just overwrite it!
(parse_exec, parse_script): Free existing process command string
before setting a new one over the top.
(parse_process, stanza_exec, stanza_script, stanza_limit): Instead of
erroring if the structure is already set and allocated, just don't
allocate a new one and allow its members to be overwritten.
* init/tests/test_parse_job.c (test_stanza_exec)
(test_stanza_script, test_stanza_pre_start)
(test_stanza_post_start, test_stanza_pre_stop)
(test_stanza_post_stop, test_stanza_description)
(test_stanza_author, test_stanza_version, test_stanza_daemon)
(test_stanza_respawn, test_stanza_service, test_stanza_instance)
(test_stanza_pid, test_stanza_kill, test_stanza_console)
(test_stanza_umask, test_stanza_nice, test_stanza_limit)
(test_stanza_chroot, test_stanza_chdir): Replace tests that check
for an error in the case of duplicate stanzas with tests that make
sure the last of the duplicates is used.
* init/errors.h (CFG_DUPLICATE_VALUE, CFG_DUPLICATE_VALUE_STR): Drop
this error, since we don't consider this a problem anymore.
* upstart/Makefile.am (libupstart_la_LIBADD): Add $(LTLIBINTL)
* init/Makefile.am (init_LDADD): Reorder and add $(LTLIBINTL)
* util/Makefile.am (initctl_LDADD): Reorder and add $(LTLIBINTL)
* compat/sysv/Makefile.am (reboot_LDADD): Reorder and add $(LTLIBINTL)
(runlevel_LDADD): add $(LTLIBINTL)
(shutdown_LDADD): Reorder and add $(LTLIBINTL)
(telinit_LDADD): Reorder and add $(LTLIBINTL)
* logd/Makefile.am (logd_LDADD): Add $(LTLIBINTL)
2007-06-03 Scott James Remnant <scott@netsplit.com>
* init/tests/test_job.c (test_run_process): Add a test case for a
crasher when the event has no arguments.
* init/job.c (job_run_process): Fix the bug, we need to check the
arguments before trying to append them.
* init/cfgfile.c, init/cfgfile.h, init/tests/test_cfgfile.c: Rename
to parse_job and strip out all functions except the parsing and stanza
ones.
* init/Makefile.am (init_SOURCES): Build and link parse_job.c and h
(TESTS): Run the parse job test suite
(test_cfgfile_SOURCES, test_cfgfile_LDFLAGS, test_cfgfile_LDADD):
Rename and update.
* init/parse_job.c: Rename all cfg_stanza_*() functions to just
stanza_*(), rename all cfg_parse_*() functions to just parse_*().
(parse_job, parse_process, stanza_exec, stanza_script, stanza_start)
(stanza_stop, stanza_emits, stanza_normal, stanza_env, stanza_limit):
Don't use NIH_MUST, it's fine to be out of memory and we should fail
in that case with a useful error. The user can always reload the
config file.
(cfg_read_job, cfg_watch_dir, cfg_job_name, cfg_create_modify_handler)
(cfg_delete_handler, cfg_visitor): Drop these functions for now.
* init/parse_job.h: Update so it just contains the one prototype.
* init/tests/test_parse_job.c: Update all tests to pass a string
to parse_job(), and check errors raised; rather than mucking around
with file descriptors all of the time. Spend the effort while we're
in here to run TEST_ALLOC_FAIL where we can.
* init/main.c: Drop config file loading for now since it's missing.
2007-05-27 Scott James Remnant <scott@netsplit.com>
* init/cfgfile.h (CFG_DIR): Drop this define, since it's in paths.h
(CfgDirectory):
* init/cfgfile.c (cfg_read_job): Separate out the job-handling code
into a new function that we could call from a stanza if we want
later; this one now just maps the file into memory and deals with
exceptions from the parsing.
(cfg_parse_job): Function containing the seperated out code; parses
a new job, marking it as a replacement for any existing job with the
same name. Drop the warnings for using pid options without a daemon,
since these are actually useful for other things later.
* init/tests/test_cfgfile.c (test_read_job): Drop the check on
unexpected daemon options, since we don't issue these warnings
anymore.
2007-05-20 Scott James Remnant <scott@netsplit.com>
* init/event.c (event_match): Change to accept Event as the first
argument and EventInfo as the second, making it obvious that this
matches a received Event against known EventInfo rather than just
comparing two info structs (since the order matters).
* init/event.h: Update prototype.
* init/tests/test_event.c (test_match): Update test accordingly.
(test_poll): Fix typo.
* init/job.c (job_handle_event): Pass in the event as the first
argument to event_match, rather than its info.
* TODO: Update.
* init/job.c (job_emit_event): Return the event that we emit; don't
bother tracking block status or setting blocked, leave that to the
state loop so things are more obvious.
(job_change_state): Set the blocked flag here for starting and stopping
to the return value of job_emit_event().
* init/event.c (event_ref, event_unref): Reference counting of events
so we don't free those we still need.
(event_block, event_unblock): Blocker counting that replaces the
previous jobs member.
(event_new): Initialise refs and blockers fields.
(event_emit_finished): Remove this function.
(event_poll): Handle the new done state, and deal with the blockers
and references counts; turns out that we can fall all the way through
this switch if these are zero without needing to check again.
(event_pending): Remove call to event_emit_finished, the event_poll()
loop handles this case now.
(event_finished): Set progress to done on the way out.
* init/event.h (EventProgress): Add new done state
(Event): Add refs and blockers members, replacing jobs
* init/tests/test_event.c (test_new): Check refs and blockers are
initialised to zero.
(test_ref, test_unref, test_block, test_unblock): Check the ref
counting function behaviours.
(test_emit_finished): Drop this function since it's not used
* init/job.c (job_change_cause): Reference and block the event,
and unblock and unreference before changing.
(job_emit_event): Reference the event that blocks the job from
continuing.
(job_handle_event_finished): Unreference the blocking event again.
(job_change_state): Make sure that blocked has been cleared before
allowing a state change.
* init/tests/test_job.c: Change tests to use refs/blockers on the
cause event when counting, and also to follow the status of blocked
since that is now ref-counted as well.
2007-05-18 Scott James Remnant <scott@netsplit.com>
* init/main.c (main, cad_handler, kbd_handler, pwr_handler): Use
event_new rather than event_emit.
* init/job.h (Job): Change type of cause and blocked to Event
* init/job.c (job_change_goal, job_change_cause, job_emit_event)
(job_handle_event, job_handle_event_finished): Update all references
to EventEmission to use Event instead.
(job_detect_stalled): Call event_new instead of event_emit
(job_run_process): Use the info member of cause, not event member
* init/tests/test_job.c (test_change_goal, test_change_state)
(test_run_process, test_child_reaper, test_handle_event)
(test_handle_event_finished): Update all references to EventEmission
to use Event instead.
(test_detect_stalled): Correct to use right structure types.
* init/process.c (process_setup_environment): Use cause's info member,
rather than event member.
* init/tests/test_process.c (test_spawn): Update to use Event.
* init/notify.h (NotifySubscription): Change member to event
* init/notify.c (notify_subscribe_event)
(notify_subscription_find, notify_job_event, notify_event)
(notify_event_finished): Update functions to use event member and
Event structures.
* init/tests/test_notify.c (test_subscribe_event)
(test_subscription_find, test_job, test_job_event, test_event)
(test_event_finished): Update to use Event instead of EventEmission
* init/control.c (control_event_emit): Update to use event_new.
* init/tests/test_control.c (test_event_emit)
(test_subscribe_events, test_unsubscribe_events): Update to use
Event rather than EventEmission.
* init/event.h: Fix up a few references.
* init/tests/test_event.c (test_new): Remove reference to emission.
* init/event.h (EventEmission): Rename to Event, and rename event
member to info.
* init/event.c (event_emit_next_id): Rename to event_next_id
(event_emit): Rename to event_new, and add standard parent argument.
(event_emit_find_by_id): Rename to event_find_by_id
(event_poll): Iterate over Events in the list
(event_pending, event_finished): Operate on Event
* init/tests/test_event.c (test_emit): Rename to test_new and
adjust for names and arguments.
(test_emit_find_by_id): Rename to test_find_by_id and adjust for
names.
(test_emit_finished, test_poll): Adjust names.
* init/cfgfile.c (cfg_stanza_start, cfg_stanza_stop)
(cfg_stanza_emits): Convert to use EventInfo and event_info_*.
* init/job.c (job_copy): Use EventInfo and event_info_copy.
(job_handle_event, job_detect_stalled): Iterate EventInfo structures
* init/tests/test_cfgfile.c (test_stanza_start, test_stanza_stop)
(test_stanza_emits): Update to use EventInfo
* init/tests/test_job.c (test_copy, test_handle_event)
(test_handle_event_finished, test_detect_stalled): Update to use
EventInfo and event_info_new
* init/event.c (event_copy): Use nih_str_array_copy here, to make the
code somewhat simpler.
(event_finished): Copy the arguments and environment from the old
event, rather than stealing and reparenting.
* init/job.c (job_copy): Use nih_str_array_copy here too.
(job_run_process): Use nih_str_array_append to add the arguments from
the emission onto the command run.
* init/event.h (Event): Rename to EventInfo, since this structure
representations information about an event, rather than an actual
event in progress.
* init/event.c (event_new): Rename to event_info_new, also now can
take arguments and environment like event_emit() can.
(event_copy): Rename to event_info_copy.
* init/tests/test_event.c (test_new): Rename to test_info_new,
update names in test and test being given args or env.
(test_copy): Rename to test_info_copy and update names in test.
(test_match, test_poll): Use EventInfo.
* TODO: Update.
2007-04-24 Scott James Remnant <scott@netsplit.com>
* configure.ac: Add AM_PROG_CC_C_O since we use per-target flags
for one of the test cases.
2007-03-16 Scott James Remnant <scott@netsplit.com>
* upstart/message.c (upstart_message_newv): Add va_end to match
va_copy because the standard says so.
* upstart/wire.c (upstart_push_packv, upstart_pop_packv): Add
va_end here as well.
2007-03-13 Scott James Remnant <scott@netsplit.com>
* init/main.c: Wait until we've closed inherited standard file
descriptors and opened the console instead before trying to open the
control socket; otherwise we end up closing it by accident if we
weren't opened with sufficient descriptors in the first place.
Also wait until we've set up the logger before trying to parse the
configuration. In fact both of these things need to be pretty low
down the main() function.
* init/tests/test_job.c (test_run_process): Skip /dev/fd test cases
if that's not available.
* init/tests/test_control.c (test_log_priority): Make sure we know
that the message has been sent before calling the watcher.
* init/cfgfile.c (cfg_watch_dir): We get ENOSYS for missing inotify
support, not EOPNOTSUPP.
* init/tests/test_cfgfile.c (test_watch_dir): Actually make the
directory tree before testing for inotify, since we use the same
tree there too.
* util/initctl.c (job_info_output): Restructure so gcc doesn't think
name can be used uninitialised.
* init/tests/test_cfgfile.c (test_watch_dir): Correct an error where
i wouldn't be initialised if we skipped the inotify tests.
* util/initctl.c (job_info_output): Restructure so gcc doesn't think
* init/process.c (process_setup_environment): job id fits inside
a %u now
* upstart/message.h: Style; always refer to "unsigned int" as
"unsigned int", and never "unsigned.
* upstart/tests/test_message.c (my_handler): Catch a stray couple
of "unsigned"s
* init/control.c (control_job_query, control_job_start)
(control_job_stop): Change type of id argument to unsigned int,
and call printf with %u to output it.
* init/tests/test_control.c (check_job, check_job_instance)
(check_job_instance_end, check_job_status__waiting)
(check_job_status_end__waiting, check_job_status__starting)
(check_job_status_end__starting, check_job_status__running)
(check_job_status_end__running, check_job_status__pre_stop)
(check_job_status_end__pre_stop, check_job_status__stopping)
(check_job_status_end__stopping, check_job_status__deleted)
(check_job_status_end__deleted, check_job_unknown)
(check_job_invalid, check_job_unchanged, check_event): Change
type of id arguments to unsigned int.
(check_list): Change type of id to unsigned int.
* init/tests/test_notify.c (check_job_status)
(check_job_status_end, check_job_finished, check_event)
(check_event_caused, check_event_finished): Change type of id
arguments to unsigned int.
* init/job.h (Job): Change the type of the id to unsigned int.
* init/job.c (job_next_id): Change ids to be unsigned ints, and now
we can just use %u in the nih_error call.
(job_find_by_id): Change argument to be unsigned int
* init/tests/test_job.c (test_find_by_id): Change id type to unsigned
int.
* init/event.h (Event): Change the type of the id to unsigned int.
* init/event.c (event_emit_next_id): Change ids to be unsigned ints,
and now we can just use %u in the nih_error call.
(event_emit_find_by_id): Change argument to be unsigned int
* init/tests/test_event.c (test_emit, test_emit_find_by_id)
(check_event, check_event_finished): Change id type to unsigned int.
* util/initctl.c (output_name): Use an unsigned int for the job id,
which means we can use ordinary %u for the printf argument.
(handle_job, handle_job_finished, handle_job_instance)
(handle_job_instance_end, handle_job_status)
(handle_job_status_end, handle_job_unknown, handle_job_invalid)
(handle_job_unchanged, handle_event, handle_event_caused)
(handle_event_finished): Change argument type of id from uint32_t
to unsigned int.
(job_info_output): Change output type of id from %zu to %u
* upstart/message.c (upstart_message_handle): Use unsigned int for
ids, rather than a fixed-width type.
* upstart/tests/test_message.c (my_handler): Use unsigned int for
the ids, and give "unsigned int" instead of "unsigned" to va_arg as
a matter of style.
* upstart/wire.c (upstart_push_int, upstart_pop_int): Send over the
wire using a plain old integer type, instead of a fixed width type;
there's no advantage to using the fixed-width type and we could hurt
ourselves if we tried running on ILP64.
(upstart_push_unsigned, upstart_pop_unsigned): Likewise use a plain
unsigned int over the wire.
(upstart_push_string, upstart_pop_string): Use an unsigned int for
the length of the string, technically this means that we silently
truncate any string that's greater than 4GB on 64-bit platforms;
it's either that or make the test cases harder (we did this before
anyway).
(upstart_push_header, upstart_pop_header): Type is always an unsigned
int (best conversion from an enum)
2007-03-11 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.3.9
* NEWS: Update.
* util/man/initctl.8: Document the new commands.
* TODO: Update.
* init/job.c (job_handle_event): Correct the function so we don't
try and stop the master of an instance, and cause an assertion error.
* util/initctl.c: Oops, correct function pointers in command table
* util/tests/test_initctl.c (test_version_action):
* util/initctl.c (handle_version): Handle receipt of the version
reply.
(version_action): Send the version-query message to the server and
expect one response.
(log_priority_action): Parse the single argument into an NihLogLevel
and send it to the server.
* init/control.c (control_version_query, control_log_priority):
Functions to handle the new messages from the server pov
* init/tests/test_control.c (test_version_query)
(test_log_priority): Test the new messages are handled properly.
(check_version): Check the version string matches.
* upstart/message.h: Add messages for querying the version of the
init daemon and changing the log priority.
* upstart/message.c (upstart_message_newv)
(upstart_message_handle): Marshal the new messages.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Test the marshalling of the new messages,
* upstart/libupstart.ver: Add enum functions to the global list.
* util/initctl.c (start_action, stop_action): Imply --no-wait if
we take the job id or name from an environment variable, since we'd
end up waiting for ourselves otherwise
* util/tests/test_initctl.c (test_start_action, test_stop_action):
Update test cases to make sure no-wait is implied.
2007-03-09 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.3.8
* NEWS: Updated.
* configure.ac: Increase version to 0.3.7
* init/tests/test_job.c (test_change_state): Add a test case for
deleting the last instance of a replaced job.
* init/job.c (job_change_state): When moving a instance of a job into
the deleted state, check whether we should replace the job it's an
instance of, and if so, change that job's state too.
* TODO: Update.
* util/initctl.c (handle_job_list): Always allocate current_list,
since we need it to be the parent of pointers we attach to it.
(handle_job_list_end): Always free the current list, only suppress
output if there aren't any entries in it.
(initctl_recv): Check the current_list pointer, no need for in_list
(handle_job_instance, handle_job_instance_end, handle_job_status):
Check current_list not in_list.
* util/tests/test_initctl.c: Correct some memory leaks.
* init/process.c (process_setup_environment): Set the UPSTART_JOB_ID
environment variable to the job's unique id.
* init/tests/test_process.c (test_spawn): Make sure it's set.
* util/man/initctl.8: Update the initctl manpage.
* compat/sysv/man/reboot.8: Correct a minor grammar error.
* compat/sysv/man/shutdown.8: Fix reference from runlevel to telinit.
* README: Add a README that copies the text from the web page and
adds some notes about recommended operating system versions.
* util/initctl.c: Completely rewrite initctl, top to bottom; handling
of the new messages is done natively, meaning that the commands just
vary the requests send and number of responses expected.
* util/tests/test_initctl.c: Test all of the new code.
* init/main.c: Improve restarting and rescuing a little; store the
program path in a static variable so we can always access it, and
use the exported loglevel to pass the same to the new process.
* TODO: Update.
* compat/sysv/shutdown.c: More error/fatal adjustments.
* compat/sysv/telinit.c: More error/fatal adjustments.
2007-03-08 Scott James Remnant <scott@netsplit.com>
* init/main.c (main, crash_handler): Promote deadly errors to nih_fatal
* logd/main.c (main): Promote deadly errors to nih_fatal
* compat/sysv/reboot.c (main): Promote deadly errors to nih_fatal
* compat/sysv/shutdown.c (main, shutdown_now): Promote deadly errors
to nih_fatal
* compat/sysv/telinit.c (main): Promote deadly errors to nih_fatal
* init/event.c (event_pending): The message that we're handling an
event should be logged with --verbose.
* init/cfgfile.c (cfg_parse_script): Remove the unnecessary check for
a token inside a script block.
* TODO: Update.
* init/control.c (control_watch_jobs): Rename to control_subscribe_jobs
and update to handle new event name.
(control_unwatch_jobs): Rename to control_unsubscribe_jobs and update
to handle the new event name.
(control_watch_events): Rename to control_subscribe_events and update
to handle the new event name.
(control_unwatch_events): Rename to control_unsubscribe_events and
update to handle the new event name.
* init/tests/test_control.c (test_watch_jobs): Rename to
test_subscribe_jobs and update to new event name.
(test_unwatch_jobs): Rename to test_unsubscribe_jobs and update to
new event name.
(test_watch_events): Rename to test_subscribe_events and update to
new event name.
(test_unwatch_events): Rename to test_unsubscribe events and update
to new event name.
* upstart/message.h: Rename the watch commands to subscribe/unsubscribe
and regroup with new message numbers.
* upstart/message.c (upstart_message_newv)
(upstart_message_handle): Marshal the updated subscription messages.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Update tests to new names and numbers.
* TODO: Update.
* upstart/message.c (upstart_message_handle): Raise a the unknown
message error if the type is unknown, rather than the invalid message
error.
* upstart/tests/test_message.c (test_handle): Correct test case.
* init/job.c (job_change_state): Correct a problem here too, when
moving from pre-stop to running, we don't want to emit a started event
since we never emitted a stopping event and never killed the process
anyway. We do need to notify the job as finished, since the process
that tried to stop it will need to be told not to wait any longer.
* init/tests/test_job.c (test_change_state): Add a test for pre-stop
back to running.
* doc/states.dot: Fix an error in the state diagram; when moving from
starting back to waiting, due to a failed respawn, we need to emit
the stopped event otherwise it will never happen.
* doc/states.png: Update.
2007-03-05 Scott James Remnant <scott@netsplit.com>
* upstart/message.c (upstart_message_new): Make this a wrapper around
(upstart_message_newv): which has all the old code, but accepts a
va_list instead of making its own.
* upstart/message.h: Add prototype.
* init/main.c (crash_handler): Simply trying to leave a SEGV handler
doesn't work so well, we end up repeating the problem instruction.
We really can't resume from this point, and can't even jump elsewhere
since our state is probably buggered up. Only thing for it is to
re-exec ourselves with a clean state.
* init/cfgfile.c (cfg_read_job, cfg_delete_handler): Don't try and
free the magic (void *)-1 replacement (delete).
* util/events.c, util/events.c, util/jobs.c, util/jobs.h: With the
new message responses, that intermix event and job information freely,
it no longer makes sense to distinguish between them. So fold these
files back into the main initctl.c
* util/initctl.h: Drop unused header.
* util/Makefile.am (initctl_SOURCES): Update sources list.
(TESTS): Change which tests we build
(test_initctl_SOURCES, test_initctl_CFLAGS, test_initctl_LDFLAGS)
(test_initctl_LDADD): Build the new combined test case binary, use
an automake feature to rebuild initctl.c with -DTEST and a different
.o file, and thus be able to define out main()
* util/tests/test_events.c, util/tests/test_jobs.c: Collapse the two
test case files into one single
* util/tests/test_initctl.c
* init/control.c (control_job_find): And implement the find function
that returns a list of jobs matching an optional pattern.
* init/tests/test_control.c: Make sure we do send all messages.
(check_list): Complex function to check the responses to a job list
(test_job_find): Test a couple of job lists.
* init/tests/test_notify.c: Make sure we do send all messages.
* init/control.c (control_job_query): Implement the query message,
this just needs to return the status or instance set.
* init/tests/test_control.c (test_job_query): Test the query command.
(check_job_status__deleted, check_job_status_end__deleted): Pair of
functions to check we can query deleted jobs directly.
* init/control.c (control_send_instance): Function to send an instance
job, collating all of its instances together.
* init/control.h: Update.
* init/tests/test_control.c (test_send_instance): Check we receive
the right messages.
(check_job_instance, check_job_instance_end): Pair of functions to
check the instance messages.
* upstart/message.h: Add new UPSTART_JOB_INSTANCE and
UPSTART_JOB_INSTANCE_END messages which we'll use to communicate that
a job is an instance, and group the instances of it together.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Marshal the new instance messages.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Test the new message types.
* upstart/message.h: Restore arguments to JOB_LIST, but rename to
pattern since that's what it is.
* upstart/message.c (upstart_message_handle): Restore arguments
with updated name.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Restore tests for arguments, rename and make sure we
include a wildcard.
2007-03-04 Scott James Remnant <scott@netsplit.com>
* upstart/message.h: Drop arguments to JOB_LIST.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Drop arguments to JOB_LIST.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Drop the arguments from the test.
* init/control.c (control_job_start): Update to return INVALID for
instances and replacements; add the forgotten UPSTART_JOB message.
(control_job_stop): Update to return INVALID for replacements; add
the forgotten UPSTART_JOB message. Deal with instance masters
magically by iterating all instances and stopping those instead.
* init/tests/test_control.c (check_job_deleted): Rename to
check_job_invalid and check that message.
(check_job): Function to check the job we've acted upon.
(test_job_start): Check that we get the UPSTART_JOB message first,
restore the check on deleted jobs causing an error and add checks
that instance and replacement jobs also cause an error.
(test_job_stop): Check that we get the UPSTART_JOB message first,
restore the check on deleted jobs causing an error. Make sure
instances are handled.
* upstart/message.h: More message changes; add a JOB_FIND message
and replace UPSTART_JOB_DELETED with UPSTART_JOB_INVALID since there's
a few more problem conditions.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Marshal the new message and update names.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Update tests to check the new message and update the
values and names of the existing ones.
* init/job.h (Job): Remove the delete flag, add replacement and
replacement_for pointers instead.
* init/job.c (job_new): Initialise replacement and replacement_for
pointers to NULL.
(job_find_by_name): Update to return what job the one we found is
a replacement for, and to skip DELETED jobs.
(job_instance): Make it simply illegal to call this for deleted jobs,
instances or replacements.
(job_change_goal): Make it illegal to change the goal of a replacement
job.
(job_free_deleted): Remove the previous code to handle deleted instance
masters, because it's now bogus.
(job_should_replace): New function to determine whether a job is
replaceable.
* init/tests/test_job.c (test_new): Check pointers are set.
(test_copy): Check that replacement and replacement_for are not
copied, since their state of an individual job.
(test_find_by_name): Update tests to make sure we ignore deleted jobs,
instances and replacements.
(test_instance): Remove test that will now cause an assertion,
and no longer check delete is set.
(test_change_goal): Remove test that will now cause an assertion.
(test_free_deleted): Remove test cases for deleted masters.
(test_should_replace): Test the new check function.
(test_change_state): Make sure that we end up in deleted for instances
and replaced jobs, and that replacements become the real job.
* init/cfgfile.c (cfg_read_job): Update to handle replacement jobs;
the old job's previous replacement is discarded, and set to the
current job; and then if the job should be replaced, it's moved
to deleted (which should promote the new job).
(cfg_delete_handler): Handle deletion of a job in a similar manner,
except we sent the replacement pointer to the special -1 value since
we have no actual replacement.
* init/tests/test_cfgfile.c (test_watch_dir): Update tests to make
sure that deletion and modification are handled wrt replacement.
(test_read_job): Make sure that reparsing an existing file is handled.
* init/tests/test_control.c (test_job_start): Remove checks that
delete gets set to true for instances.
(test_job_stop, test_job_start): Temporarily comment out deleted
job behaviour, since that's been somewhat changed.
* upstart/message.h: We're not going to return JOB_LIST for JOB_STOP
since that's just awkward for the client; just act on the master,
and return JOB_UNCHANGED.
* init/notify.c (notify_job_status): Move this function to
* init/control.c (control_send_job_status): here, since we need it for
the new control responses.
(control_job_query): New single function to list all jobs or a
particular job.
* init/control.h: Add prototype.
* init/tests/test_control.c (test_error_handler): Simplify this a
little to just sending a NO_OP message, since we can send an entire
stream of messages and leave them in the queue.
(check_job_status__stopping, check_job_process)
(check_job_status_end__stopping): Trio of check functions for a job
status that's stopping, with an active main process.
(test_send_job_status): Test the now global status function.
(check_job_status__starting, check_job_status_end__starting): Pair
of check functions for a starting job with no process yet.
(test_watch_jobs, test_unwatch_jobs): Update to expect the full new
job status messages, with an optional process part as well.
(check_event): Function to check an event.
(test_watch_events): Minor update to use above function.
(check_job_status__waiting, check_job_status_end__waiting): Pair of
check functions for the first step in starting a job (goal change only)
(check_job_unknown, check_job_deleted, check_job_unchanged): Trio
of functions to check common error responses.
(test_job_start): Update tests to newer behaviour.
(check_job_status__running, check_job_status_end__running)
(check_job_status__pre_stop, check_job_status_end__pre_stop): Checks
for the states we go through when stopping a job.
(test_job_stop): Update tests to newer behaviour.
* init/notify.c (notify_job, notify_job_event, notify_job_finished):
Update to call the newly exported function.
* init/job.c: Make job_id and job_id_wrapped externally available.
* init/job.h: Update.
* init/event.c: Make emission_id and emission_id_wrapped externally
available.
* init/event.h: Update.
* upstart/message.h: Rename UPSTART_JOB_INVALID to
UPSTART_JOB_UNCHANGED, as it's not really invalid just a no-op
* upstart/message.c (upstart_message_new, upstart_message_handle):
Update the constant, fields are unchanged,
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Rename constants/messages.
* upstart/message.h: Turns out we need extra errors to indicate that
the job was deleted or already at that goal, otherwise the client
would sit there waiting for the finished event.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Marshal the new error messages.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Test the handling of the new messages.
* init/tests/test_job.c (test_free_deleted): Found a bug; because
master instances never change state, they never end up in the deleted
state so are never reaped. Add some test cases for cleaning them up,
but not while they have remaining instances.
* init/job.c (job_free_deleted): Implement the bug fix.
* init/job.c (job_instance): Split out the instance spawning code
into its own function, as we'll frequently need a pointer to the
instance before we try and change the goal.
(job_change_goal): Clean this function back up again, it no longer
needs to return values and can assert that it's never called for
deleted jobs or instance mastersr.
(job_handle_event): Spawn an instance when we get a start event.
* init/job.h: Update.
* init/tests/test_job.c (test_instance): Check instance creation.
(test_change_goal): Update tests now that it doesn't return a value
again, and doesn't spawn instances itself.
(test_handle_event): Make sure instances are spawned.
* init/tests/test_event.c (test_poll): Needs a slight fix now that
we generate more events than we check, and that subscriptions go
away automatically.
* init/notify.c (notify_job_status): Static function to handle
sending the more complicated job status message series
(notify_job): Call notify_job_status() to send the new-style message
(notify_job_event): Send the new UPSTART_EVENT_CAUSED message with
the emission id, then call notify_job_status() to send the new-style
common status message.
(notify_job_finished): New function to be called when we reach the
job rest state, notifies and unsubscribes directly subscribed
processes, and includes failed information.
(notify_event_finished): Unsubscribe processes after sending the
finished event, since the event has gone away. Also don't send
this to processes subscribed to all events, since it's not useful
for them.
* init/notify.h: Add prototype.
* init/tests/test_notify.c: Update all test cases and helper
functions to the new message types.
(test_job_finished): Check the new finished message is sent with
a status message preceeding it.
* init/job.c (job_change_state, job_change_state): Notify subscribed
processes with notify_job_finished() when in the running (for service)
or waiting states, just before we drop the cause.
* upstart/message.h: Add failed, failed_process and exit_status
arguments to UPSTART_JOB_FINISHED.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Marshal the new arguments.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Test the new arguments.
* upstart/message.h: Update the message types, introducing a more
structured job message set and replacing the UPSTART_EVENT_JOB_STATUS
message with UPSTART_EVENT_CAUSED which will be immediately followed
by an ordinary UPSTART_JOB_STATUS message.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Marshal the new messages.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Test the new message types.
* TODO: Update.
2007-03-03 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* init/cfgfile.c (cfg_parse_exec, cfg_parse_script): Separate out
the parsing of an exec or script stanza into separate functions,
seeing as this is quite a common operation. This also means we
just need to change them in one place now.
(cfg_parse_process): Function to call either of the above depending
on the next argument.
(cfg_stanza_exec): Call cfg_parse_exec instead.
(cfg_stanza_script): Call cfg_parse_script instead.
(cfg_stanza_pre_start, cfg_stanza_post_start)
(cfg_stanza_pre_stop, cfg_stanza_post_stop): Call cfg_parse_process
with the right arguments instead of doing by hand in each function.
* init/event.c (event_emit_next_id): Split the id assigning code into
a static inline function for easier modification.
* init/job.c (job_next_id): Use the same style function here too.
2007-03-02 Scott James Remnant <scott@netsplit.com>
* init/event.c (event_emit): Port the slightly more efficient in the
early case code from job_new.
* init/job.h (Job): Add a unique id to the job structure.
* init/job.c (job_new): Assign an incrementing id to each new job
allocated.
(job_find_by_id): Locate a job by its unique id, sadly not very
efficient in a hash table ;-)
(job_name): New hash key function since name isn't the first entry
anymore.
(job_init): Change hash key function.
* init/tests/test_job.c (test_find_by_id): Make sure we can find a
job by its id.
* init/job.c (job_change_goal): Return the new instance in that
circumstance, and clean up a little bit.
* init/job.h: Update prototype.
* init/tests/test_job.c (test_change_goal): Update tests.
* init/job.c (job_find_by_name): Skip jobs marked for deletion too.
* init/tests/test_job.c (test_find_by_name): Update test case.
* init/event.h, init/notify.h, upstart/message.h: Provide C-level names
for enums, this makes the compiler generate things that gdb can get.
* init/job.c (job_run_process, job_kill_process, job_kill_timer):
Change process argument to be a plain ProcessType, this means we
know exactly which process we're trying to run or kill.
(job_change_state): Update calls to job_run_process
and job_kill_process
* init/tests/test_job.c (test_run_process, test_kill_process): Update
function calls to just pass a ProcessType in.
* upstart/enum.h: Rename JobAction to ProcessType.
* upstart/enum.c (job_action_name): Rename to process_name.
(job_action_from_name): Rename to process_from_name.
* upstart/tests/test_enum.c (test_action_name, test_action_from_name):
Rename and update to match.
* init/job.c (job_new, job_copy, job_change_state)
(job_next_state): Change JOB_*_ACTION constants to PROCESS_*.
(job_find_by_pid): Change JobAction argument to ProcessType.
(job_emit_event): Call process_name on the failed process.
(job_child_reaper): Update to use ProcessType instead of JobAction.
* init/job.h (Job): Change type of failed_process to ProcessType.
* init/tests/test_job.c (test_find_by_pid): Update to use ProcessType
instead of JobAction in tests.
(test_new, test_copy, test_change_goal, test_change_state)
(test_next_state, test_run_process, test_kill_process)
(test_child_reaper, test_handle_event_finished): Change JOB_*_ACTION
constants to PROCESS_*
* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_script)
(cfg_stanza_pre_start, cfg_stanza_post_start)
(cfg_stanza_pre_stop, cfg_stanza_post_stop): Change JOB_*_ACTION
constants to PROCESS_*
* init/tests/test_cfgfile.c (test_stanza_exec)
(test_stanza_script, test_stanza_pre_start)
(test_stanza_post_start, test_stanza_pre_stop)
(test_stanza_post_stop, test_read_job, test_watch_dir): Change
JOB_*_ACTION constants to PROCESS_*
* init/tests/test_event.c (test_poll): Change JOB_*_ACTION constants
to PROCESS_*
* init/tests/test_control.c (test_job_start, test_job_stop): Change
JOB_*_ACTION constants to PROCESS_*
* init/cfgfile.c (cfg_watch_dir): Restore the prefix argument; pass
as the data pointer to the inotify callbacks and visitor function.
Change the return value to be the watch structure.
(cfg_job_name): Add prefix argument and prepend to relative path.
(cfg_create_modify_handler, cfg_delete_handler, cfg_visitor): Get
the prefix for the job names from the data pointer and pass to
cfg_job_name().
* init/cfgfile.h: Update prototypes.
* init/tests/test_cfgfile.c (test_watch_dir): Actually test the
watch functions.
* init/main.c (main): Pass NULL for the prefix for the global job
directory, compare the return value against (void *)-1.
* TODO: Update.
* init/cfgfile.c (cfg_stanza_on): Drop the simple on stanza.
* init/tests/test_cfgfile.c (test_stanza_on): Remove test case.
* TODO: Update.
2007-03-01 Scott James Remnant <scott@netsplit.com>
* util/jobs.c (handle_job_status): Drop the process field from the
output for now.
* util/events.c (handle_event_job_status): Likewise
* util/tests/test_jobs.c (test_start_action, test_list_action)
(test_jobs_action): Drop pid from messages we simulate.
* util/tests/test_events.c (test_emit_action): Likewise.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Remove the pid field from the job status and event job status
messages.
* upstart/message.h: Update description of job status and event
job status message to remove the pid field.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Remove checks using the pid field.
* init/control.c (control_job_start, control_job_stop)
(control_job_query, control_job_list): Remove the pid field from
the messages, it'll come back later when we get better message
formats.
* init/tests/test_control.c (check_job_status, check_job_waiting)
(check_job_started, check_job_stopped): Remove checks on the process
id, since that field is gone from the message.
(test_job_stop): Use the pid field of the main process.
(test_job_start): Initialise the main action process.
* init/notify.c (notify_job, notify_job_event): Remove the pid field
from the message, it'll come back later when we get better message
formats.
* init/tests/test_notify.c (check_job_status)
(check_event_job_status): Remove checks on the pid, since that field
is no longer present.
* init/job.c (job_process_copy): Use job_process_new here, oops.
* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_script)
(cfg_stanza_pre_start, cfg_stanza_post_start)
(cfg_stanza_pre_stop, cfg_stanza_post_stop): Use job_process_new
to allocate process structures and store in the process array.
* init/tests/test_cfgfile.c (test_read_job, test_stanza_exec)
(test_stanza_script, test_stanza_pre_start)
(test_stanza_post_start, test_stanza_pre_stop)
(test_stanza_post_stop): Update test cases to use process array
member information.
* init/tests/test_event.c (test_poll): Update to use newer job process
array and find the pid under there.
* init/job.h (Job): Remove the pid and aux_pid fields; replace the
individual JobProcess pointers with an array of them of a fixed
minimum size; replace failed_state with failed_process.
(JobProcess): add a pid field here, so now we can obtain the pid on
an individual process/action basis rather than global.
* init/job.c (job_process_new): Function to create a JobProcess
structure, setting the initial values to FALSE/NULL/0.
(job_process_copy): Function to copy a JobProcess.
(job_new): Don't initialise the pid or aux_pid members, initialise
the process array to a fixed initial size and set the members to NULL,
initialise the failed_process member to -1.
(job_copy): Update to use job_process_copy and copy the process array.
(job_find_by_pid): Look through the process structures in the job's
process array to find the pid, and optionally return which action it
was.
(job_change_state): Call job_kill_process in the JOB_KILLED state if
we have a main process and that has a pid, pass in the main process.
(job_next_state): Check the process id of the main process when
deciding what the next state is for running.
(job_run_process): Store the process id in the process structure
(job_kill_process): Accept a process structure and use that to obtain
the process id we need to send TERM too. Remove the code that forced
a state change if kill() failed, since we will get a child signal
anyway and should do it there.
(job_kill_timer): Likewise, accept a process structure and don't
forcibly change the state anymore.
(job_child_reaper): Rewrite to switch based on the action that died,
rather than the state we were in; assert that the state is what we
expected.
(job_emit_event): The argument to the failed event is now the action
name, rather than the state name; an action of -1 indicates that
respawn failed.
* init/tests/test_job.c (test_process_new, test_process_copy): Make
sure the structure is created and copied properly.
(test_new, test_copy): Drop checks on the pid and aux_pid members,
add checks for the process array and pid members of processes.
(test_find_by_pid): Update test case to make sure we can find the pid
of any process, returning the action index rather than the process
pointer.
(test_run_process, test_kill_process, test_change_goal)
(test_change_state, test_next_state, test_child_reaper): Update test
cases to use pid fields inside process structures rather than the
pid or aux_pid members.
(test_handle_event, test_handle_event_finished)
(test_free_deleted): Update to avoid pid field checks.
* upstart/enum.h (JobAction): Enumeration of different actions.
* upstart/enum.c (job_action_name, job_action_from_name): Enumeration
to string conversion functions.
* upstart/tests/test_enum.c (test_action_name)
(test_action_from_name): Tests for the new functions.
* init/cfgfile.c (cfg_read_job): Instead of trying to copy over an
old job's state and instances into the new one, mark the old job
as deleted. This ensures we never end up applying a new post-stop
script to a job started with an old pre-start script, etc. It also
makes life so much simpler.
* init/tests/test_cfgfile.c (test_read_job): Update tests to make
sure the old job is marked for deletion, instead of freed.
* TODO: Update.
* init/notify.c (notify_job): Split out notification to processes
subscribed to the cause event into a new function
(notify_job_event): We can call this when we change cause.
* init/job.c (job_change_state): Notify anyone subscribed to the
job after we've changed the state, rather than before, otherwise
we won't know the new pids or anything.
(job_change_cause): Call notify_job_event before changing the cause
so that subscribers get a final status update.
* init/tests/test_notify.c (test_job_event): Check the new function.
* TODO: Update.
* init/cfgfile.c (cfg_stanza_respawn): Remove the shortcut that
lets you specify "respawn COMMAND". It was confusing as it hid
the common "[when] exec"/"[when] script" syntax, made it non-obvious
that "exec" and "respawn" were the same flag, etc.
* init/tests/test_cfgfile.c (test_stanza_respawn): Update tests.
(test_stanza_service): Fix test case to not use shortcut.
* logd/event.d/logd.in: Update to not use respawn shortcut.
2007-02-25 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_child_reaper): Shift the signal value into the
higher byte to make it easier to detect, and not stamp over exit
statuses between 128 and 255.
(job_emit_event): Detect the signal stored in the new way.
* init/cfgfile.c (cfg_stanza_normal): Store signal in the higher bytes.
* init/tests/test_job.c (test_copy, test_change_state)
(test_child_reaper): Update test cases.
* init/tests/test_cfgfile.c (test_stanza_normal): Update test.
* TODO: Update.
* init/event.h (PWRSTATUS_EVENT): Add new power-status-changed event.
* init/main.c (pwd_handler): Handle the SIGPWR signal by generating
the new event, leave it up to a job to parse the file and do
whatever it likes.
* TODO: Update.
2007-02-13 Scott James Remnant <scott@netsplit.com>
* upstart/tests/test_message.c (test_reader, test_handle_using)
(test_handle); Usual fix for gcc optimiser thinking that fixed
for loops might not be.
* init/tests/test_job.c (test_run_process, test_kill_process):
Likewise.
* init/tests/test_notify.c (test_subscription_find): I still don't
know what a type-punned pointer is, nor why dereferencing such a
thing would break strict-aliasing rules.
* init/tests/test_cfgfile.c (test_read_job): More type-punning.
* util/tests/test_jobs.c (test_start_action): More for-loop action.
* util/tests/test_events.c (test_emit_action): And again.
2007-02-11 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_change_goal): We need to be able to stop a running
job without a process, because that's what a job-as-state is! The
check was added because job_child_reaper calls job_change_goal and
then job_change_state immediately after, we should fix that instead.
(job_child_reaper): If we call job_change_goal while in the running
state, it will call job_change_state for us; so check for that first
and don't change the state!
* init/tests/test_job.c (test_change_goal): Update the test to ensure
that we can stop a job with no running process.
* init/cfgfile.c (cfg_stanza_normalexit): normalexit is inconsistent,
change to "normal exit"
* init/tests/test_cfgfile.c (test_stanza_normalexit): Update.
* init/cfgfile.c (cfg_stanza_start, cfg_stanza_stop)
(cfg_stanza_pre_start, cfg_stanza_post_start)
(cfg_stanza_pre_stop, cfg_stanza_post_stop, cfg_stanza_respawn):
We're not going to allow stanza keywords to be quoted, since this
gives us an easy way to allow users to make something explicitly
not a keyword.
2007-02-10 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.3.6
* configure.ac: Increase version to 0.3.5
* NEWS: Update.
* TODO: Update.
* TODO: More notes.
* TODO: Note an issue with using JobProcess->pid
* init/cfgfile.c (cfg_stanza_pre_start, cfg_stanza_post_start)
(cfg_stanza_pre_stop, cfg_stanza_post_stop): Add a needed check
for a token when parsing "exec". Correct line number we expect
to see the duplicated value on. Correct expected error for missing
argument from "Unexpected token" to "Expected token".
* init/tests/test_cfgfile.c (main): Actually invoke the tests for
the scripts.
* init/cfgfile.c (cfg_read_job): Correct type of lineno in error.
* TOOD: Minor notify bug
* TODO: Big update.
* init/tests/test_job.c (test_child_reaper): Make sure that we can
reap post-start and pre-stop processes, and have only the aux_pid
changed. Also make sure that if the running process dies while
in these states, with or without an aux process, that we don't
transition badly.
* init/job.c (job_find_by_pid): Check aux_pid as well.
* init/tests/test_job.c (test_find_by_pid): Make sure we can find it.
* init/job.h (Job): Add an auxiliary pid member.
* init/job.c (job_new): Initialise the aux_pid member.
(job_change_state): Run the post-start and pre-stop scripts when we
enter the state with the same name (assuming they exist).
(job_run_process): Store the pid in aux_pid when starting the
post-start or pre-stop processes.
* init/tests/test_job.c (test_change_state): Add tests for running
the new post-start and pre-stop scripts; which get their process ids
stored in aux_pid instead of pid.
(test_new): Make sure the aux_pid member is initialised properly.
(test_copy): Make sure the aux_pid member is not copied.
* TODO: Update.
* init/tests/test_job.c (test_change_state): Add a check for the
daemon stanza holding the job in spawned; we snuck this in a while
back and never tested it (there's no support to get it out of
spawned yet).
* init/job.h (Job): Add new post_start and pre_stop scripts.
* init/job.c (job_new): Initialise new scripts to NULL.
(job_copy): Copy the information from the new scripts over as well.
* init/tests/test_job.c (test_new): Check they're initialised.
(test_copy): Check that the information is copied properly.
* init/cfgfile.c (cfg_stanza_post_start, cfg_stanza_pre_stop): Add
new script stanza functions for the additional two scripts that
we want.
* init/tests/test_cfgfile.c (test_stanza_post_start)
(test_stanza_pre_stop): Add tests for the new stanzas.
* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_script): Rewrite to
allocate a JobProcess and parse the command or script into it.
(cfg_read_job): Fix the long broken assumption that pid_file and
pid_binary are required for respawn, when they're actually required
for daemon.
(cfg_stanza_start, cfg_stanza_stop): Remove script second-level.
(cfg_stanza_respawn): Parse into the job's process.
(cfg_stanza_pre_start, cfg_stanza_post_stop): New stanzas for the
processes alone.
* init/tests/test_cfgfile.c (test_read_job): Update a few test
cases to match reality.
(test_stanza_start, test_stanza_stop): Remove script-related checks.
2007-02-09 Scott James Remnant <scott@netsplit.com>
* init/tests/test_job.c (test_kill_process): Poll the event queue
after each test to get rid of the allocated events and make valgrind
happy.
* init/tests/test_control.c (test_job_start, test_job_stop)
(test_event_emit): Poll the event queue after each test to get rid
of the allocated events, as they make valgrind complain.
(test_event_emit): Free args and env when done.
* init/job.h (JobName): Drop obsolete structure
(JobProcess): Add a new structure to represent a single process
within the job, instead of using two variables to pick either the
script or command.
(Job): Change command and script to a single JobProcess called process;
change start_script and stop_script to a JobProcess called pre_start
and post_stop respectively.
* init/job.c (job_new): Initialise new members to NULL.
(job_copy): Copy the process structures across, including contents.
(job_change_state): Call job_run_process passing in the structure;
rather than fiddling with if statements.
(job_run_script, job_run_command, job_run_process): Combine all of
these three functions into a single new job_run_process function.
* init/tests/test_job.c (test_new, test_copy, test_change_goal)
(test_change_state, test_child_reaper)
(test_handle_event_finished): Change to using JobProcess for when
we need to construct a command.
(test_run_script, test_run_command): Merge into single new
(test_run_process) function.
* init/tests/test_event.c (test_poll): Replace command with process.
* init/tests/test_control.c (test_job_start): Change to using
JobProcess to specify the command.
* init/main.c (main): Run job_free_deleted each time through the
main loop.
* init/job.c (job_change_goal): Minor tweak to the logic; we may
have just made the job an instance, that should still let us stop
the one underneath.
* TODO: Update.
* util/jobs.c (do_job): Always expect a list of replies.
* init/control.c (control_job_status, control_job_stop)
(control_job_query): Reply with information about all instances of
the job.
* init/tests/test_control.c (test_job_status, test_job_stop)
(test_job_query): Make sure we get the list end even for a single job;
and make sure we get details of all instances attached to the job.
* init/tests/test_job.c (test_change_goal): Check that starting
an instance job actually starts a new instance of it.
* init/cfgfile.c (cfg_stanza_limit): Support the word "unlimited" in
limit arguments for both the soft and hard values.
* init/tests/test_cfgfile.c (test_stanza_limit): Make sure that we
can make limits be unlimited.
* init/event.c (event_copy): Function to copy an event structure.
* init/event.h: Add prototype.
* init/tests/test_event.c (test_copy): Make sure we copy the event
correctly, with or without arguments and/or environment.
* init/job.c (job_copy): Function to copy a job structure, leaving
the state as it is.
* init/job.h: Add prototype.
* init/tests/test_job.c (test_copy): Make sure that we copy the
job details whether they are NULL or non-NULL, but don't copy the
state.
* init/init.supp: Update supression.
* init/job.c (job_find_by_name): If we get a job that's an instance,
return what it's an instance of.
* init/tests/test_job.c (test_find_by_name): Restore accidentally
deleted test function; test that we get the real job, not an instance.
* init/job.c (job_new): instance_of is initialised to NULL.
* init/job.h: Add a new instance_of pointer, pointing to the parent
that we're an instance of.
* init/tests/test_job.c (test_new): Check that.
* init/tests/test_cfgfile.c (test_read_job): Make sure instance_of
pointers are updated.
* init/job.c (jobs): Store jobs in a hash table.
(job_new): Add to hash table, not to a list.
(job_handle_event, job_handle_event_finished, job_detect_stalled)
(job_free_deleted): Iterate across the hash table, rather than list.
(job_find_by_name): Use nih_hash_lookup, we keep this function because
we'll add "is instance or not" smarts soon!
(job_find_by_pid): Iterate across the entire hash table.
* init/tests/test_job.c (test_find_by_name): Drop test since this
function is now gone.
(test_free_deleted): Can't assume things are in a line now.
* init/control.c (control_job_list): Iterate the hash table.
* init/event.c: Don't hide the events list anymore
* init/event.h: Publish it and the init function.
* init/job.c: Don't hide the jobs list anymore.
(job_list): Since we don't hide it, we can drop this.
* init/job.h: Publish it and the init function.
* init/notify.c: Don't hide the subscriptions list anymore.
* init/notify.h: Publish it and the init function.
* init/control.c (control_job_list): Iterate the job list directly
* init/tests/test_control.c (test_event_emit): Use the events list
available to us.
* init/tests/test_event.c (test_poll): Call job_init directly and
just use the events list available to us.
* init/tests/test_job.c (test_new): Call job_init directly.
(test_change_state): Use the events list available to us.
* init/tests/test_notify.c (test_unsubscribe): Use the subscriptions
list available to us.
* doc/states.dot: Add updated state graph.
* doc/Makefile.am (EXTRA_DIST): Ship the states diagram.
(states.png): Include rules to build the png, we'll put it in bzr
anyway, but this is useful.
* init/cfgfile.c (cfg_delete_handler): Handle deleted jobs; mark
the job as deleted, and if it's dormant, invoke a state change.
* upstart/enum.h: Add a new JOB_DELETED state.
* upstart/enum.c (job_state_name, job_state_from_name): Add the new
state to the string functions.
* upstart/tests/test_enum.c (test_state_name)
(test_state_from_name): Check the enum works.
* init/job.c (job_change_goal): New decision; we can start a waiting
job if it's marked delete (it might be a new instance) -- we'll use
the new deleted state to decide that we shouldn't.
(job_change_state): Once we reach waiting, if the job is to be deleted,
move to the next state.
(job_next_state): The next state for a waiting job if the goal is stop
is deleted. We should never call job_next_state () for a deleted job.
(job_free_deleted): Very simple function, just detects
deleted jobs and frees them.
* init/job.h: Add prototype for new function.
* init/tests/test_job.c (test_change_goal): Update test to use new
deleted state; and don't even change the goal.
(test_change_state): Add a check to make sure we end up in deleted.
(test_next_state): Make sure waiting goes to deleted.
(test_free_deleted): Check the function.
* init/job.c (job_change_goal): Don't try and start a job if it's
marked to be deleted and is just waiting for cleanup.
* init/tests/test_job.c (test_change_state): Make sure that the cause
is released when we reach waiting.
* init/tests/test_cfgfile.c (test_read_job): Make sure that a deleted
job gets resurrected.
* init/cfgfile.c (cfg_visitor): Correct number of arguments and call
to cfg_job_name.
* TODO: Update.
* init/cfgfile.c (cfg_stanza_daemon): Don't allow arguments anymore.
* init/tests/test_cfgfile.c (test_stanza_daemon): Update tests.
* init/job.c (job_handle_event_finished): Function to unblock all
jobs blocked on a given event emission.
(job_new, job_emit_event): Rename blocker to blocked; it's useful for
testing for truth.
* init/job.h: Add prototype, rename member.
* init/tests/test_job.c (test_handle_event_finished): Test it.
(test_new, test_change_state): Update name here too.
* init/event.c (event_finished): Call job_handle_event_finished
function to unblock jobs.
* init/tests/test_event.c (test_poll): Make sure the job gets
unblocked; a few other tests have to change since running event_poll
always unblocks the job if nothing listens to it.
* init/job.c (job_child_reaper): Set failed back to FALSE if
we're respawning, since we don't want to be failing.
* init/tests/test_job.c (test_child_reaper): cause will be NULL.
also free and poll events when done.
(test_handle_event): pid can never be -1
(test_change_state): poll events when done
* init/tests/test_job.c (test_child_reaper): Process will always
be zero on return from reaper.
* init/tests/test_job.c (test_child_reaper): Killed doesn't go past
stopping; it goes to waiting, which will clear the cause.
* init/tests/test_job.c (test_child_reaper): Fill in values before
we test against them.
* init/tests/test_job.c (test_kill_process): Fix violated assertion
* init/tests/test_job.c (test_change_state): This should be failed
because nothing cleared it.
* init/tests/test_job.c (test_change_state): Fix a couple of array
index problems.
* init/tests/test_job.c (test_change_state): Why set that which
does not change?
* init/tests/test_job.c (test_change_state): Add newline to test.
* init/job.c (job_emit_event): Add the job name as an argument;
oops.
* init/tests/test_control.c (test_job_stop): Need to kill the process
ourselves, as we're blocked on an event.
(test_job_query): Fix wrong value in test.
(check_job_stopped, test_job_stop, test_unwatch_jobs): Change job
name to match the test.
* init/job.c (job_change_state): Must only not enter some states
with no process now; others like killed actually usually want one!
* init/tests/test_cfgfile.c (test_read_job): Fix test case.
* init/tests/test_job.c (test_handle_event): Clean up tests.
(test_detect_stalled): Clean up.
* init/job.c (job_child_reaper): Update the reaping of the child
processes; there's a much larger state range for the main process
now, so that needs to be taken into account.
* init/tests/test_job.c (test_child_reaper): New test cases.
* init/job.c (job_next_state): Encapsulate the slightly odd three
exit states of running in this function, otherwise we'll end up
special-casing it in places I'd rather not think about.
(job_change_goal): Only change the state of a running job if it
has a process.
* init/tests/test_job.c (test_next_state): Add a test case for the
dead running job
(test_change_goal): Add test case for the dead running job
* init/tests/test_job.c (test_change_state): Add test cases for
the forgotten stopping to killed transition.
* init/job.c (job_kill_process, job_kill_timer): Just check the pid
and state, and no longer any need to notify jobs since we're just
called from one state amongst many.
(job_change_state): Skip over the killed state if there's no process.
* init/tests/test_job.c (test_kill_process): Update test cases.
* init/job.c (job_run_process): Simplify a little bit, no need to
do the state assertions here, just make sure there's no already
a process running.
* init/tests/test_job.c (test_run_command, test_run_script): Run
tests in the spawned state, since that's where we run the primary
command or script. Drop check for process state since that's no
longer set.
* init/job.c (job_change_state, job_next_state): Ok, here's the big
one ... rewrite this to use the new state transitions. This has
suddenly got a lot simpler and easier to read, this was definitely a
good idea.
(job_emit_event): Function to make emission of events easier.
(job_failed_event): replaces this one which wasn't so easy.
* init/tests/test_job.c (test_change_state): I can't say how much I
wasn't looking forwards to rewriting these test cases; anyway, it's
done now and I hope they're all right;
(test_next_state): Make sure the state transitions are correct too.
* init/job.h: Rename is_instance to delete and spawns_instance to
just instance.
* init/job.c (job_new): Update.
* init/tests/test_job.c (test_new): Update.
* init/cfgfile.c (cfg_stanza_instance): Update.
* init/tests/test_cfgfile.c (test_stanza_instance): Update.
* init/event.h: Correct the event names.
* init/job.h: Add blocker event member.
* init/job.c (job_new): Initialise it to NULL.
* init/tests/test_job.c (test_new): Check it.
* init/job.c (job_change_goal): Have a stab at this function with the
new state machine; it gets somewhat simpler (until we introduce the
second scripts), now we just induce things by a state change.
* init/tests/test_job.c (test_change_goal): Made easier (for now)
because we don't need to deal with processes and can just wait to
be blocked on an event.
2007-02-08 Scott James Remnant <scott@netsplit.com>
* init/cfgfile.c (cfg_read_job): Drop check for useless respawn script
(cfg_stanza_respawn): Drop handling of "respawn script"
* init/tests/test_cfgfile.c (test_stanza_respawn): Drop the checks
for "respawn script"
* init/job.h: Move things about a bit more; remove respawn_script
since that state is going away.
* init/job.c (job_new): Drop initialisation of process_state.
* init/tests/test_job.c (test_new): Improve the tests.
* init/main.c (STATE_FD): Remove this define, not used anymore.
* init/tests/test_event.c (test_poll): Update the event checking
to match what's likely to happen.
* init/event.h: Remove commented out bit.
* init/tests/test_notify.c (check_job_status, test_job): Correct
state usage to match a possible state.
* init/control.c (control_job_start, control_job_stop)
(control_job_query, control_job_list): Drop process state and
description from the job status messages we send back.
* init/tests/test_control.c (test_error_handler)
(check_job_started, test_job_start, check_job_stopped)
(check_job_stopping, test_job_query, check_job_starting)
(test_job_list, test_watch_jobs, test_unwatch_jobs): Remove
process_state and description, and update usage of job states.
* init/notify.c (notify_job): Don't include process state or
description in the job status message anymore.
* init/tests/test_notify.c (check_job_status, test_job): Update tests
* init/cfgfile.c (cfg_read_job): Drop the copying of the process_state
member, since it doesn't exist anymore.
* init/tests/test_cfgfile.c (test_read_job): Drop the check too.
* init/job.h (Job): Drop the process_state member.
* util/jobs.c (handle_job_status): Drop the process_state and
description arguments; output a process id only if it's greater
than zero.
* util/tests/test_jobs.c (test_start_action, test_list_action)
(test_jobs_action): Update tests to use newer states and arguments.
* util/events.c (handle_event_job_status): Simplify in the same way
* upstart/message.h: Remove process_state and description from the
job status event (we already had the foresight to not put them in
the event job status event).
* upstart/message.c (upstart_message_new, upstart_message_handle):
Update handling of the messages to reduce the arguments.
* upstart/tests/test_message.c (test_new, my_handler)
(test_handle): Update the tests for the new job status message.
* upstart/enum.h (JobState): Change the job states to the new set
of states that we've planned.
(ProcessState): Drop process state entirely; this information is now
contained in the single JobState field.
* upstart/enum.c (job_state_name, job_state_from_name): Update
strings to match the new state names.
(process_state_name, process_state_from_name): Drop these functions.
* upstart/tests/test_enum.c (test_state_name)
(test_state_from_name): Update test cases to match new names.
(test_process_state_name, test_process_state_from_name): Drop.
* init/main.c (main): Remove the logd hack for now.
* init/job.c (job_new): Change the default console to none for now.
* init/tests/test_job.c (test_new): Update test.
* init/cfgfile.c (cfg_stanza_console): Can't guard against duplicates
for a while.
* init/tests/test_cfgfile.c (test_stanza_console): Comment out dup test
* init/cfgfile.c (cfg_read_job): Remove the restriction that there
must be either an 'exec' or 'script' for a job; jobs without either
define states others can use.
* init/tests/test_cfgfile.c (test_read_job): Convert the test to
a "must work".
* init/job.c (job_change_state): Remove restriction that we must
have either a script or a command; having neither should just wedge
the job at the running rest state. Note that there's no way to get
it out yet, because we don't force that particular state change.
* init/tests/test_job.c (test_change_state): Make sure that works.
* init/job.c (job_change_cause): Put the knowledge about how to
change the cause into a separate function, since it's slightly
tricky.
(job_change_goal, job_change_state): Set the cause using the above
function.
* init/job.h (Job): Rename goal_event to cause, also shuffle things
around so that the state is mostly together.
* init/job.c, init/process.c, init/notify.c, init/cfgfile.c: Update
references (and comments) to match the new name.
* init/tests/test_job.c, init/tests/test_event.c,
init/tests/test_process.c, init/tests/test_cfgfile.c,
init/tests/test_notify.c: Likewise.
* init/job.c (job_child_reaper): Don't change the goal event; the
state changes will handle this.
(job_change_goal): Only dereference/reference the goal event if we're
actually changing it.
* init/tests/test_job.c (test_change_state, test_child_reaper):
Update tests to not assume that the goal event gets changed.
(test_kill_process): Eliminate race condition.
* init/job.c (job_child_reaper): Correct some problems with job and
event failure; we now don't overwrite an existing failure record,
and don't record failure if the main process failed and the goal was
stop; since we likely caused it.
* init/tests/test_job.c (test_child_reaper): More test cases.
* logd/event.d/logd.in: Stop on the new runlevel events, not the
shutdown event.
* compat/sysv/shutdown.c (shutdown_now): Emit an ordinary runlevel
change event now; including the INIT_HALT environment variable
* compat/sysv/man/shutdown.8: Update the manual
* compat/sysv/telinit.c: Now just sends out a runlevel event with
an argument giving the new runlevel.
* compat/sysv/man/telinit.8: Update description of the command.
* upstart/message.h: Remove the UPSTART_SHUTDOWN message.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Remove handling for the shutdown message.
* upstart/tests/test_message.c (test_new, test_handle): Remove
tests against the shutdown message.
* init/control.c (control_shutdown): Remove the shutdown command
from the server.
* init/tests/test_control.c (test_shutdown): Remove tests for it.
* init/event.h: Remove the shutdown event.
* util/initctl.c: Remove the shutdown command reference.
* util/events.c (shutdown_action): Remove the command.
* util/events.h: Update.
* util/tests/test_events.c (test_shutdown_action): Remove tests.
* init/job.c (job_detect_idle): Rename to job_detect_stalled
(job_detect_stalled): Remove the idle state detection
(job_set_idle_event): Idle event has been removed.
* init/job.h: Update.
* init/tests/test_job.c (test_detect_idle): Rename to
(test_detect_stalled): and remove idle detection tests.
* init/main.c (main): Replace job_detect_idle with job_detect_stalled
* init/control.c (control_shutdown): Don't set the idle event.
* init/tests/test_control.c (test_shutdown): Don't detect the idle
event (and thus the second event)
* init/cfgfile.c (cfg_stanza_service): Parser for service stanza.
* init/tests/test_cfgfile.c (test_stanza_service): Test the service
stanza.
(test_stanza_respawn): Check that respawn implies service.
* TODO: Update.
* init/job.h (Job): Add a new service member.
* init/job.c (job_new): Service starts off as false.
(job_change_state): Check service instead of respawn.
* init/tests/test_job.c (test_change_state): Check with service
instead of respawn, since that's what we really mean.
* init/cfgfile.c (cfg_read_job): Copy a whole bunch more state
into the newly parsed job.
* init/job.c (job_run_process): Only output the first error.
* init/tests/test_cfgfile.c (test_read_job): Make sure important
things are copied.
* TODO: Update.
* init/main.c: Restore a much simplified version of the term
handler that doesn't try and copy across any state.
* compat/sysv/telinit.c: Update call to event_emit; we'll revisit
this shortly when we get rid of the shutdown event.
* util/events.c (handle_event): Add new id field (but ignore it)
Functio
(handle_event_job_status): New function to handle the new event.
(handle_event_finished): Function to handle the end of the event.
(emit_action): Send the newer event, and loop over replies until
we get a finished one.
* util/tests/test_events.c (test_emit_action): Update tests cases.
* init/control.c (control_event_emit): New function to handle the
new-style emit message.
* init/tests/test_control.c (test_event_emit): Make sure the new
message function behaves.
* init/event.c, init/job.c, init/main.c, init/tests/test_event.c,
init/tests/test_job.c: Completely drop the serialisation code, it's
getting out of date and in the way.
* init/event.h: Remove compatibility macros.
(EventEmission): Drop the callback function; it was too error prone
to try and do it this way, and we only ever wanted to release a job
anyway as control requests are better handled through the notify
interface.
(EventEmissionCb): Drop unused typedef.
* init/event.c (event_emit): Drop callback argument.
(event_finished): Don't call the callback
* init/tests/test_event.c: Update to avoid callbacks.
* init/job.c (job_change_state): Convert to using event_emit and
EventEmission.
(job_detect_idle): Drop extra arguments to event_emit.
* init/main.c (main, cad_handler, kbd_handler): Drop extra arguments
to event_emit.
* init/control.c (control_shutdown): Use event_emit instead of
event_queue.
* init/tests/test_control.c (test_shutdown): Convert to using
EventEmission.
(test_watch_events, test_unwatch_events): Drop extra arguments to
event_emit.
* init/tests/test_notify.c (test_subscribe_event, test_job)
(test_event, test_event_finished): Drop extra arguments to event_emit
* init/tests/test_job.c (test_change_goal, test_change_state)
(test_run_script, test_child_reaper, test_detect_idle): Drop
extra arguments to event_emit.
* init/tests/test_process.c (test_spawn): Drop extra arguments to
event_emit.
* TODO: Update.
Rewrite the notification subsystem quite significantly; now we
have individual functions to subscribe to different types of
notification, and can even subscribe to individual jobs or events.
* init/notify.c (notify_subscribe_job, notify_subscribe_event)
(notify_unsubscribe): New subscription and unsubscription functions
that assume one record per subscription, not process.
(notify_subscription_find): Function to find a subscription.
(notify_job): Send a message to anything subscribed to the goal event
as well.
(notify_event): Use EventEmission and include the id in the event.
(notify_event_finished): New function, sends a finished message and
includes both the id and whether the event failed.
* init/notify.h (NotifySubscribe): New notify structure that is
once per subscription, rather than per-process; and allows
subscription to individual jobs or events.
* init/tests/test_notify.c (test_subscribe_job)
(test_subscribe_event, test_unsubscribe): Test the new subscription
functions, replacing the old
(test_subscribe): tests.
(test_subscription_find): Check finding works
(check_event, test_event): Update to use emissions, and check that the
id is correct.
(test_event_finished): Check this one works too
(check_event_job_status, test_job): Make sure processes subscribed
via the goal event are notified too.
* init/event.c (event_pending): Pass the emission directly.
(event_finished): Notify subscribers that the event has finished.
* init/control.c (control_error_handler): Call notify_unsubscribe
(control_watch_jobs, control_unwatch_jobs, control_watch_events)
(control_unwatch_events): Update to the new subscription API.
* init/tests/test_control.c (test_error_handler): Use new API
(test_watch_jobs, test_unwatch_jobs, test_watch_events)
(test_unwatch_events): Also update these to the new API; use a
destructor to make sure the subscription is freed.
* init/tests/test_process.c: Don't use printf, use TEST_FUNCTION
2007-02-07 Scott James Remnant <scott@netsplit.com>
* upstart/message.h: Allocate new grouped event messages.
* upstart/message.c (upstart_message_new, upstart_message_handle):
Add support for the new grouped event messages.
* upstart/tests/test_message.c (test_new, test_handle)
(my_handler): Make sure the new messages are passed correctly.
* init/job.c (job_change_state): Clear the goal event whenever we
reach the final rest state of a job (waiting for all jobs, running
for services).
* init/tests/test_job.c (test_change_state): Check that the goal
event goes away at the right times.
* TODO: Update.
* init/tests/test_job.c (test_child_reaper): Make sure that the
event is marked failed properly
* init/job.c (job_start_event, job_stop_event): There's no reason
for these to exist as seperate functions anymore, especially since
we want to eventually have some kind of match table.
(job_handle_event): Perform the iterations and match calls here
instead, since we just call job_change_goal now.
* init/job.h: Remove prototypes.
* init/tests/test_job.c (test_start_event, test_stop_event): Fold into
(test_handle_event): which now handles all the cases.
* init/job.c (job_detect_idle): Call event_emit
* init/main.c (main, cad_handler, kbd_handler): Call event_emit
instead of event_queue.
* init/tests/test_event.c (test_new): Call event_poll
* init/tests/test_job.c (test_change_state, test_child_reaper)
(test_detect_idle, test_change_state): Update to use newer event API.
* TODO: Update.
* init/job.c (job_start, job_stop): Drop these functions; call
job_change_goal instead (which is now public).
(job_change_state, job_child_reaper): Call job_change_goal instead.
* init/job.h: Update.
* init/tests/test_job.c (test_start, test_stop): Merge into new
(test_change_goal): function.
* init/main.c (main): Call job_change_goal instead of job_start.
* init/control.c (control_job_start, control_job_stop): Call
job_change_goal instead.
* init/tests/test_job.c (test_new, test_change_state)
(test_run_script, test_start, test_stop, test_start_event):
* init/job.h (Job): goal_event is now an EventEmission, and is
a direct pointer to the one in the events queue, rather than a copy.
* init/process.c (process_setup_environment): Reference the event
name and environment through the goal event, not directly.
* init/job.c (job_run_script): Reference the event name and
environment through the goal event, not directly.
(job_change_state, job_child_reaper): Replace direct setting of the
job goal with a call to job_stop; the process state is always
PROCESS_NONE in all three cases, so this is completely safe.
(_job_start, _job_stop): Merge these two functions together into
(job_change_goal): which behaves a lot more like job_change_state,
except that it doesn't loop. This handles the changing of the
emission.
(job_start, job_start_event, job_stop, job_stop_event): Simplify
these functions, now they just call job_change_goal passing in
the emission pointer (or NULL).
* init/main.c, init/job.c, init/job.h, init/event.c, init/event.h,
init/tests/test_job.c, init/tests/test_event.c: Remove state
serialisation code for the time being; maintaining it is getting
increasingly harder, and it introduces some major bugs. It will
get rewritten shortly.
* init/event.c (event_pending): Pass the emission directly to
job_handle_event now.
* init/job.c (job_handle_event, job_start_event, job_stop_event):
Deal with event emissions rather than just plain events, the change
so far doesn't do anything else other than take the structure change.
* init/job.h: Change prototypes.
* init/tests/test_job.c (test_start_event, test_stop_event)
(test_handle_event): Update tests to use emissions.
* init/tests/test_event.c (test_read_state, test_write_state): Check
the passing of the progress information.
* init/event.c (event_read_state, event_write_state): Add progress
field to the serialisation (oops).
* init/event.h: Add missing attribute for event_read_state.
* init/cfgfile.h: Add missing attributes.
* init/main.c (read_state): Don't discard return value.
* TODO: Update.
* init/main.c (read_state): Handle the Emission keyword; also handle
Event really being an EventEmission.
* init/event.c (event_emit): Make the next emission id a static global
(event_read_state, event_write_state): Serialise event emission
structures, not plain events; also send over the last id we used so
it appears seamless. This doesn't yet handle the callback/data bit
of the serialisation, which turns out to be a little tricky ... oops
* init/event.h: Update.
* init/tests/test_event.c (test_read_state, test_write_state): Check
that serialisation is done with EventEmissions instead, and all the
fields are passed (except callback and data which are ... tricky).
* init/main.c (main): Call event_poll instead of event_queue_run.
* init/event.c (event_poll): Add the new function that replaces
event_queue_run(); handles the new-style event emission structures
in the list and only returns when there are no non-handling events.
(event_pending, event_finished): Handling of particular event states
during poll; split out for readability.
(event_queue, event_queue_run): Drop these obsolete functions.
(event_read_state): Force type from event_queue.
* init/event.h: Add event_poll prototype; remove prototypes of old
functions, replacing with #defines for now so things still compile.
* init/tests/test_event.c (test_queue): Drop tests.
(test_read_state, test_write_state): Force type from event_queue
Change type we check size of.
(test_poll): Pretty thoroughly test the new poll function.
* init/job.c (job_change_state): Force type from event_queue
* init/control.c (control_event_queue): Force type from event queue
* init/tests/test_job.c (test_detect_idle): Force type from event_queue
* init/tests/test_control.c (test_event_queue, test_shutdown):
Force type from event_queue
* init/event.c: Revert to a single list of events with an enum
(event_emit): Set the progress to pending initially.
(event_emit_find_by_id): Simplify now it just checks one list
(event_emit_finished): Function for jobs to call once they've done
with an event; just sets the progress to finished for the event
queue to pick up.
* init/tests/test_event.c (test_emit_finished): Check it.
* init/event.h: Add prototype.
(EventProgress): Add new enum
(EventEmission): And add progress member to this structure
* init/tests/test_event.c (test_emit): Make sure the event is pending
* init/event.c (event_emit_find_by_id): Locate an event emission
by its id in either the pending or handling queue.
* init/event.h: Add prototype
* init/tests/test_event.c (test_emit): Make sure that the emission
id is unique each time.
(test_emit_find_by_id): Test the function.
* init/event.c (event_emit): New function to replace event_queue();
returns an EventEmission structure with the details filled in as
given.
* init/event.h: Add prototype.
* init/event.c (event_init): Rename the single events queue to
pending and add a new handling list.
* init/event.h (EventEmission, EventEmissionCb): Add a new emission
structure that wraps an event, for use in the queue.
* util/tests/test_events.c (test_events_action): Update test now
that nih_message is more sensible.
* util/tests/test_jobs.c (test_start_action, test_list_action)
(test_jobs_action): Update test
* util/events.c (emit_action): Actually pass the emit_env array
* util/tests/test_events.c (test_emit_action): Make sure it does.
* util/initctl.c (main): Catch nih_command_parser() returning a
negative value to indicate an internal error, and always exit 1.
* util/events.c (handle_event): Build up multiple lines to describe
the event, including its arguments and environment.
* util/tests/test_events.c (test_events_action): Check the new output
format is right.
* init/main.c (main): Take out inadvertantly leaked debugging code;
sorry about that.
* init/job.c (job_child_reaper): Rewrite this to make the logic a
little easier to follow, and support signals in normalexit. This
also now applies to deciding whether the job failed, if it did, we
store that information in the job so the stop and stopped events
can get it.
* init/tests/test_job.c (test_child_reaper): Add new test cases for
the setting of the failed flags.
* init/cfgfile.c (cfg_stanza_normalexit): Allow signal names in the
arguments, which are added to the normalexit array or'd with 0x80
* init/tests/test_cfgfile.c (test_stanza_normalexit): Check that we
can now parse signal names correctly.
* init/job.c (job_failed_event): Change add to addp to fix leak.
* init/job.c (job_failed_event): Function to turn an event into one
that includes all the necessary arguments and environment.
(job_change_state): Call job_failed_event for the stop and stopped
events (bit hacky at the moment, will improve later).
* init/tests/test_job.c (test_change_state): Check that the failed
events are generated properly.
2007-02-06 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_change_state): Reset the failed member when
we enter the starting state.
* init/tests/test_job.c (test_change_state): Make sure that the
failed member is reset when we enter the starting state.
* init/job.h (Job): Add failed, failed_state and exit_status members.
* init/job.c (job_new): Initialise new members.
* init/job.c (job_child_reaper): Convert signals to names when
outputting status messages.
* init/tests/test_job.c (test_child_reaper): Check that the signal
name gets converted over.
* init/event.h (CTRLALTDEL_EVENT): Now we've broken the shared
namespace of events and jobs, rename the control-alt-delete event
back to control-alt-delete.
* init/job.c (job_change_state): Replace the events generated as
part of the job state, named for the job and state, with new state
events that have the job name as an argument.
* init/event.h: Define new job event names.
* init/tests/test_job.c (test_change_state): Make sure the new
events are correct, with the job name as an argument.
* init/job.c (job_change_state): Remove the job event; this has
been repeatedly proved to be confusing.
* init/tests/test_job.c (test_change_state): Remove checks for the
job event.
* util/events.c (emit_action): Pass in extra arguments.
(env_option): Function to parse an option given an environment
variable.
* util/events.h: Add prototype.
* util/tests/test_events.c (test_emit_action): Make sure that the
emit action works with no arguments and with arguments.
(test_events_action): Send back events with the right number of args.
(test_env_option): Check the env option parser works.
* util/initctl.c: Give shutdown its own command and options, give
emit a new -e option.
* util/events.c (shutdown_action): Split out from emit, seeing as
these are going to be different from now on.
* util/events.h: Add prototype.
* util/tests/test_events.c (test_shutdown_action): Copy test cases.
* init/control.c (control_event_queue): Take the arguments and
environment from the event queue request; and reparent into the
event.
* init/tests/test_control.c (test_event_queue): Check that arguments
and environment are copied across properly.
* init/notify.c (notify_event): Pass in the arguments and environment
for the event.
* init/tests/test_notify.c (check_event): Check for event arguments
and environment from the notify process.
(test_event): Add arguments and environment to the event we test with
* upstart/tests/test_message.c (test_new, test_handle): Send
arguments and environment with the UPSTART_EVENT_QUEUE and
UPSTART_EVENT messages.
* upstart/wire.c (upstart_pop_int, upstart_pop_unsigned): Shrink
only once.
(upstart_pop_string): Check the length is at least one first, as
we may just have an 'S'.
* upstart/message.c (upstart_message_new, upstart_message_handle):
The UPSTART_EVENT and UPSTART_EVENT_QUEUE messages gain new array
arguments containing the arguments and environment for the event.
* upstart/message.h: Document the new arguments.
* util/tests/test_events.c, util/tests/test_jobs.c: Update the
message format checks here too.
* upstart/tests/test_wire.c (test_pop_pack): Free the array.
* upstart/tests/test_message.c (test_new, test_handle)
(test_handle_using, test_reader): Update tests to include and
expect new type markers between each field.
* upstart/wire.c (upstart_push_int, upstart_push_unsigned):
Take out silly asserts; it must have room!
* upstart/wire.c (upstart_push_string, upstart_pop_string): Rewrite
to use a type like the rest of the functions; this removes the strange
length restriction and allows us to make the pop function
non-destructive.
* upstart/tests/test_wire.c (test_push_string): Update.
(test_pop_string): Update, adding in non-destructive, wrong type
and insufficient space for type test cases.
(test_push_array, test_pop_array): These needed updated too,
changing the string format changed the array format.
(test_push_pack, test_pop_pack): And obviously the pack format changed.
* upstart/wire.c (upstart_pop_header): Make the function
non-destructive in the face of errors.
* upstart/tests/test_wire.c (test_pop_header): Make sure that
invalid headers are non-destructive on error.
* upstart/tests/test_wire.c (test_pop_int, test_pop_unsigned):
Make sure that insufficient space is non-destructive.
* upstart/wire.c (upstart_push_int, upstart_pop_int)
(upstart_push_unsigned, upstart_pop_unsigned): Convert to array-style
type first format.
(upstart_push_string, upstart_push_header): Write the length and
type fields out by hand so they don't get an 'i' prefix.
(upstart_pop_string, upstart_pop_header): Read the length and type
fields by hand so they don't get an 'i' prefix.
* upstart/tests/test_wire.c (test_push_int, test_pop_int)
(test_push_unsigned, test_pop_unsigned): Update test cases to match.
(test_push_pack, test_pop_pack): Pack format was changed too.
* upstart/wire.c (upstart_push_packv, upstart_pop_packv): Add calls
to push and pop array.
* upstart/tests/test_wire.c (test_push_pack, test_pop_pack): Test
support for arrays.
* upstart/wire.c (upstart_push_array, upstart_pop_array): Implement
new array functions; note that these use a newer format that allows
us to transmit NULL without needing to limit the size of the array.
* upstart/wire.h: Add prototypes.
* upstart/tests/test_wire.c (test_push_array, test_pop_array):
Test the new array functions.
* init/job.c (job_run_script): Build up the argument list, appending
those from the goal event if one is set.
(job_run_command): Use nih_str_array_add to build up the arguments,
but don't append those from the goal event (use script).
* init/tests/test_job.c (test_run_script): Make sure the arguments get
passed to the running shell scripts.
* init/job.c (job_run_script): Only use the /dev/fd trick if we can
actually stat /dev/fd; also don't hardcode that path ...
* init/paths.h (DEV_FD): Add here.
* init/process.c (process_setup_environment): Copy environment
variables from the goal event into the job's process.
* init/tests/test_process.c (test_spawn): Make sure the environment
reaches the job, but doesn't override that in the job already.
* init/tests/test_job.c (test_start_event):
* init/job.c (job_start_event, job_stop_event): Copy the arguments
and environment from the event into the goal event.
* init/job.c (job_read_state, job_write_state): Read and write
arguments and environment for goal event.
* init/tests/test_job.c (test_read_state, test_write_state): Test
with arguments and environment to the goal event.
* init/event.c (event_read_state, event_write_state): Read and write
the arguments and environment of the event.
* init/tests/test_event.c (test_read_state, test_write_state): Make
sure arguments and environment are correctly serialised.
* init/cfgfile.c (cfg_stanza_console): Fix a leak of the console
argument in the case of duplicated options.
(cfg_stanza_env): Drop the counting now nih_str_array_addp does it;
and be sure to use that function.
(cfg_stanza_umask): Fix leak of umask argument
(cfg_stanza_nice): Fix leak of nice argument
* init/tests/test_event.c (test_new): Call event_queue_run so init
is called outside of a TEST_ALLOC_FAIL block.
* init/event.c (event_new): Start off with NULL args and env, to
match job (saves a few bytes).
(event_match): Watch for NULL arguments!
* init/tests/test_event.c (test_new): Check for NULL not alloc'd
* init/cfgfile.c (cfg_stanza_on, cfg_stanza_start)
(cfg_stanza_stop): Parse arguments to the on stanza and store them
directly in the event.
* init/tests/test_cfgfile.c (test_stanza_on, test_stanza_start)
(test_stanza_stop): Make sure arguments are parsed into the event.
* init/event.c (event_new): Use nih_str_array_new.
* init/cfgfile.c (cfg_stanza_env): Rewrite to use nih_str_array.
* init/job.c (job_run_script): Check the error returned from
nih_io_reopen; don't just loop. We only ever expect ENOMEM (the
other error, EBADF, is impossible).
* init/job.c (job_change_state): Reset the goal_event to NULL when
we catch a run-away job (as it's not stopping for the same event
it started with).
(job_child_reaper): Reset the goal_event to NULL after setting the
goal to STOP.
* init/tests/test_job.c (test_change_state, test_child_reaper):
Check that the goal event gets reset whenever the goal gets changed.
* init/tests/test_event.c: Use TEST_ALLOC_FAIL
* init/event.c (event_match): Match arguments using fnmatch() and
allow more arguments in event1 than event2 (but not the other way
around).
* init/tests/test_event.c (test_match): Check the new permitted
combinations.
* init/event.h (Event): Add args and env members to Event.
* init/event.c (event_new): Initialise args and env members to
zero-length arrays.
* init/tests/test_event.c (test_new): Use TEST_ALLOC_FAIL and
make sure args and env are both initialised to a list containing
just NULL.
* util/jobs.c (start_action): Get the UPSTART_JOB environment variable
and use that if we don't have any arguments passed to us.
(do_job): Code split from the above function that handles a named job
* util/tests/test_jobs.c (test_start_action): Make sure UPSTART_JOB
is picked up.
* init/process.h: Add necessary attributes.
* init/process.c (process_setup_environment): Set the UPSTART_JOB
environment variable from the job, and the UPSTART_EVENT environment
variable from the job's goal_event member (if set).
* init/tests/test_process.c (test_spawn): Make sure we get the
environment in the job.
* init/job.h: Add attributes to job_new and job_read_state.
* init/tests/test_job.c: Use CHECK_ALLOC_FAIL on the functions we
didn't get around to touching while we were in here.
* init/job.c (job_start_event, job_stop_event): Set the goal_event
member to a copy of the event we found.
(job_read_state): Use event_new instead of trying to do it by hand.
* init/tests/test_job.c (test_start_event, test_stop_event): Use
CHECK_ALLOC_FAIL; and make sure the goal_event is set properly.
(test_start, test_stop, test_write_new): Use event_new here too
* init/job.c (job_write_state): Output a goal_event field containing
the event name or nothing for NULL.
(job_read_state): Parse the goal_event field
* init/tests/test_job.c (test_write_state): Make sure the state is
written out properly.
(test_read_state): Make sure that the state is parsed correctly too.
* init/job.c (job_start, job_stop): Split all of the code except
the goal_event setting into two new static functions that this calls
(_job_start, _job_stop): New static functions
(job_start_event, job_stop_event): Call _job_start and _job_stop
instead of job_start and job_stop
* init/job.c (job_catch_runaway): Move this function up a bit.
* init/job.c (job_start, job_stop): Clear the goal_event member,
these functions are called for a manual start.
* init/tests/test_job.c (test_start, test_stop): Make sure the
goal_event member is freed and set to NULL.
* init/job.h (Job): Add a new goal_event member
* init/job.c (job_new): Initialise the goal_event member to NULL.
* init/tests/test_job.c (test_new): Check with TEST_ALLOC_FAIL;
also make sure goal_event is initialised to NULL.
2007-02-05 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.3.3
* NEWS: Update.
* init/process.c (process_spawn): Exit with 255 so we don't clash
with anything that uses 1 as a normal exit code. Note why we only
close 0..2 (everything else is FD_CLOEXEC).
* init/cfgfile.c (cfg_watch_dir): Mark the inotify watch descriptor
as FD_CLOEXEC.
* init/control.c (control_open): nih_io_set_cloexec can only ever
return EINVAL, so no point checking it.
2007-02-04 Scott James Remnant <scott@netsplit.com>
* init/tests/test_control.c: Remove strange old code.
2007-02-03 Scott James Remnant <scott@netsplit.com>
* init/control.c (control_open_sock, control_reopen)
(control_close_handler): Drop these functions; unconnected datagram
sockets don't close -- so why try dealing with it?
(control_error_handler): Don't reopen the socket on error, just log
it -- the socket should be fine, there's no remote end to be lost,
after all.
* init/tests/test_control.c (test_close_handler): Drop.
(test_error_handler): Drop the reopen tests.
* init/tests/test_job.c (test_run_script): Control socket doesn't
get unexpectedly opened anymore; so no need to close it.
* init/control.c (control_open): Remove the strange behaviour that
this can be called to get the socket. Instead make control_io
global; we're all adults after all.
* init/tests/test_control.c (test_open): Remove the test for the
silly behaviour.
* init/notify.c (notify_job, notify_event): Use the control_io
pointer directly, and just do nothing if we lost it somehow.
* init/main.c (main): Being unable tp open the control socket, or
parse the configuration, should be a fatal error; stop being so
damned liberal! <g> Don't reset the signal state if we're
being restarted, as this loses any pending signals -- be happy
that our parent left them in a good state. Set SIGCHLD to the
standard handler, otherwise we might lose this before we start
the main loop (which does the same anyway).
(term_handler): Rework so we don't need to close and open the
control socket; instead we just close it in the child that's
going to send the state, and notify the parent that it's safe to
exec (which will cause it to be closed so the new init can open it).
* init/tests/test_control.c (test_open): Fix valgrind error
* init/tests/test_notify.c (test_subscribe): Fix valgrind error
* init/notify.c (notify_subscribe): Make safe against ENOMEM.
* init/tests/test_notify.c (test_subscribe): Use TEST_ALLOC_FAIL
* init/control.c: Add needed attributes; tidy up formatting.
(control_open): Don't let ENOMEM fail opening the control socket.
* init/control.h: Add needed attributes.
* init/tests/test_control.c (test_open): Test for failed allocation.
* init/main.c (term_handler): Make sure we catch failure to open
the control socket again.
* TODO: Update
* init/cfgfile.c (cfg_watch_dir): Clean this up a bit; now we only
output a warning if inotify failed for any reason other than not
being supported AND walking worked.
* init/cfgfile.c (cfg_watch_dir): Update to even newer watch API;
our create_handler is now always called if inotify is successful,
so we just need to fall back to walking the directory when it
isn't -- if inotify isn't supported, don't even bother complaining.
(cfg_create_modify_handler): Check the stat of the file visited to
make sure it's a regular file.
(cfg_visitor): Check the stat of the file visited to make sure it's
a regular file.
* init/cfgfile.c: Update include to upstart/enum.h
* init/job.c: Update include to upstart/enum.h
* init/job.h: Update include to upstart/enum.h
* logd/main.c: Add attribute to open_logging
* util/initctl.c: Split out the command functions into new files;
* util/jobs.c: This gets the job-related commands
* util/events.h: This gets the event-related commands
* util/initctl.h, util/jobs.h, util/events.h: Headers
* util/tests/test_jobs.c: Test suite for job-related commands.
* util/tests/test_events.c: Test suite for event-related commands.
* util/Makefile.am (initctl_SOURCES): Add new files.
(TESTS): Build new test suites.
(test_jobs_SOURCES, test_jobs_LDFLAGS, test_jobs_LDADD):
Details for job-related commands test suite binary.
(test_events_SOURCES, test_events_LDFLAGS, test_events_LDADD):
Details for event-related commands test suite binary.
* TODO: Remove item about splitting initctl now we've done it.
* TODO: Big update; strip anything we have a spec for.
* upstart/message.c (upstart_message_handle): Make sure that if we
fail to parse a message, we don't leave strings around in memory.
* upstart/tests/test_message.c (test_open): Check that we get a
raised EADDRINUSE if we try an open a socket twice.
(test_handle): Add lots of checks for things like NULL names and
incomplete messages; as well as the obvious unknown message.
(test_reader): Make sure that errors while handling messages are
dealt with by logging it.
* upstart/job.c, upstart/job.h, upstart/tests/test_job.c: Rename to
enum.c, enum.h and tests/test_enum.c; since this just includes enums
and convert functions really.
* upstart/Makefile.am: Update.
* upstart/libupstart.h: Update include.
* upstart/tests/test_message.c: Update include.
2007-02-01 Scott James Remnant <scott@netsplit.com>
* logd/main.c (main): Ensure we error if daemonise fails.
* compat/sysv/shutdown.c (main): Ensure that signals and timers
are added, even if we run out of memory.
* upstart/tests/test_message.c: Change from assert to assert0
* upstart/tests/test_wire.c: Change from assert to assert0
* init/tests/test_notify.c: Change from assert to assert0
* init/tests/test_control.c: nih_io_message_send should always return
a value greater than zero.
* upstart/tests/test_wire.c: Change to use assert instead of NIH_ZERO;
the rationale here is that in test cases we just want to fail, not
try again repeatedly.
* upstart/tests/test_message.c: Likewise.
* init/tests/test_control.c: Use assert to ensure we get the expected
return values of functions that raise errors.
* init/tests/test_notify.c: Use assert to ensure we get the expected
return values of functions that raise errors.
* init/cfgfile.c (cfg_watch_dir): Port to the new NihWatch API and
use nih_dir_walk(). This also fixes the long-standing bug where we
wouldn't watch the configuration directory if inotify was disabled.
Drop both the parent and prefix members for now, until we clean this
up later.
(cfg_create_modify_handler): Wrap cfg_read_job after figuring out
the job name.
(cfg_job_name): Function to figure out the job name from a path.
(cfg_visitor): Visitor function to handle initial parsing, figuring
out the job name; otherwise identical to the standard handler.
* init/cfgfile.h: Update prototype for cfg_watch_dir.
* init/main.c (main): Update call to cfg_watch_dir.
2007-01-31 Scott James Remnant <scott@netsplit.com>
* upstart/tests/test_message.c: Use TEST_ALLOC_FAIL to make sure
allocations are handled properly.
2007-01-30 Scott James Remnant <scott@netsplit.com>
* upstart/wire.c: Note that if any of the push functions fail, the
entire buffer should be discarded.
* upstart/tests/test_wire.c (test_push_int, test_push_unsigned)
(test_push_string, test_push_header, test_push_pack): Us
TEST_ALLOC_FAIL to ensure that failing to allocate memory is caught.
* upstart/tests/test_message.c (my_handler): Free the name and
description after checking; they aren't otherwise.
* upstart/wire.c (upstart_push_packv, upstart_pop_packv): Consume
a copy of the va_list, so these can be called multiple times on the
same list without ill effect.
* upstart/message.h: Add warn_unused_result attributes to
upstart_message_handle and upstart_message_handle_using as they raise
errors.
* upstart/wire.c: push functions return negative values to indicate
insufficient memory.
* upstart/wire.h: Add warn_unused_result attributes to push functions
* upstart/tests/test_message.c: Guard calls to nih_io_buffer_push and
nih_io_message_add_control with NIH_ZERO to ensure they succeed.
* upstart/tests/test_wire.c: Guard calls to nih_io_buffer_push
* HACKING: Update from libnih with new Documentation,
Function Attributes and Test Cases sections.
2007-01-10 Scott James Remnant <scott@netsplit.com>
* init/main.c (crash_handler): s/SEGV/SIGSEGV/
* init/main.c (main): Rename variable
* TODO: Update.
* init/main.c (main): Change the way we clear the arguments; by
deleting just the final NULL terminator, we fool the kernel into
only returning one argument in cmdline.
* init/main.c (segv_handler): Rename to crash_handler and handle
SIGABRT as well, so we can catch assertion errors. Of course, in
theory, with our high test converage this should never happen in
practice <chortle>
2007-01-09 Scott James Remnant <scott@netsplit.com>
* init/main.c (main): Clear arguments so that upstart only ever
appears as /sbin/init in ps, top, etc.
* TODO: Update.
* util/initctl.c: Add data pointer to functions and handle calls.
* init/control.c: Add data pointer to all functions.
* init/tests/test_control.c: Pass data pointer to
upstart_message_handle_using()
* init/tests/test_notify.c: Pass data pointer to
upstart_message_handle_using()
* upstart/message.c (upstart_message_handle)
(upstart_message_handle_using): Add a data pointer argument to these
functions and pass it to the handler.
(upstart_message_reader): Pass the io structure's data pointer.
* upstart/message.h (UpstartMessageHandler): Add a data pointer to
the message handler.
* upstart/tests/test_message.c (test_handle, test_handle_using):
Pass a data pointer to the function call and check it's passed
to the handler correctly.
(test_reader): Check that the io data pointer gets passed.
* init/tests/test_cfgfile.c (test_stanza_console, test_stanza_env)
(test_stanza_umask, test_stanza_nice, test_stanza_limit): Finish off
the newer style test cases.
* init/cfgfile.c (cfg_stanza_console, cfg_stanza_umask)
(cfg_stanza_nice, cfg_stanza_limit, cfg_stanza_chroot)
(cfg_stanza_chdir): Guard against duplicate uses of the stanzas.
* init/tests/test_cfgfile.c (test_stanza_daemon)
(test_stanza_respawn): Check that neither daemon or respawn override
exec if they have no arguments.
(test_stanza_script): Add missing function
(test_stanza_chroot, test_stanza_chdir): Add tests for these simple
stanzas.
* init/cfgfile.c: Change remaining uses of nih_error_raise and
return to just nih_return_error.
* init/cfgfile.c (cfg_stanza_exec, cfg_stanza_daemon)
(cfg_stanza_respawn, cfg_stanza_script): Disallow duplicates,
both of command strings, scripts, limits and of just the flags.
* init/tests/test_cfgfile.c (test_stanza_exec)
(test_stanza_daemon, test_stanza_respawn, test_stanza_instance):
Check the behaviour of these stanzas.
* init/cfgfile.c (cfg_stanza_start, cfg_stanza_stop): Disallow
duplicate values for the script.
* init/tests/test_cfgfile.c (test_stanza_start, test_stanza_stop):
Test cases for those two functions.
* init/cfgfile.c (cfg_stanza_description, cfg_stanza_author)
(cfg_stanza_version): Don't allow stanza to be duplicated anymore.
* init/tests/test_cfgfile.c (test_stanza_description)
(test_stanza_author, test_stanza_version): Test cases for these
simple stanza; making sure duplication is not permitted.
(test_stanza_on): Add a test case for this stanza too.
* init/cfgfile.c (cfg_stanza_kill): Guard against duplicate uses
of the kill timeout stanza.
* init/tests/test_cfgfile.c (test_stanza_kill): Test the complex
kill stanza.
(test_stanza_pid): Check duplicate usage results in an error.
* init/job.h (Job): Rename pidfile to pid_file and binary to pid_binary
* init/job.c (job_new): Update names here too.
* init/errors.h: Add a new "duplicate value" error.
* init/cfgfile.c (cfg_read_job): Change name of variables, and catch
the duplicate value error to add the line number.
(cfg_stanza_pid): Change variable names, and clean this function up
a little. Make it an error to use a stanza more than once.
* init/tests/test_cfgfile.c (test_stanza_pid): Write a newer test
case function for the pid stanza.
* init/cfgfile.c (cfg_stanza_normalexit): Use do/while instead of
while, that we don't have to test has_token first as next_arg does
that for us.
* init/cfgfile.c (cfg_stanza_normalexit): Change to peek at the next
token to see whether it's missing or not, and then just fetch each
next argument at a time. This is more efficient than parsing them
all in one go, and also means we can report the error in the right
place!
* init/tests/test_cfgfile.c (test_stanza_normalexit): Since we've
changed the function that parses the stanza, add a proper test case
function for it, covering all the behaviours.
* init/job.c (job_new): Initialise the emits member to an empty list.
* init/job.h (Job): Add the emits member as a list.
* init/tests/test_job.c (test_new): Check the emits list starts off
empty.
* init/tests/test_cfgfile.c (test_stanza_emits): Test the new emits
stanza; this function will also serve as a prototype for cleaning up
the config tests.
* init/cfgfile.c (cfg_stanza_emits): Add function to parse the new
emits stanza.
* init/cfgfile.c (cfg_stanza_depends): Remove the depends stanza
from the configuration file. Dependency support has never been used,
and is to be replaced by a more flexible event/state configuration
and blocking on the starting/stopping events.
* init/tests/test_cfgfile.c: Remove references and tests for the
depends stanza.
* init/job.h: Remove the depends list from the job structure.
* init/job.c (job_new): No depends list to initialise.
(job_change_state): No dependencies to release
(job_start): No dependencies to iterate; this removes a particularly
hairy and complex interaction between state changes. Remove the
dependency event.
(job_release_depends): Drop this function.
* init/tests/test_job.c (test_start, test_stop): Massively simplify
these tests cases now we don't have dependencies to worry about.
(test_release_depends): Drop tests
2007-01-08 Scott James Remnant <scott@netsplit.com>
* init/cfgfile.c: Rewrite using the nih_config API, rather than one
huge function we now just have seperate handler functions for each
stanza. We can also use more fine-grained parsing than slurping
all args in and counting them.
(cfg_read_job): Catch exceptions from the configuration parser and
add the line number where the problem occurred to an output message.
Parser errors are now fatal, and not ignored.
* init/errors.h: Add a file containing errors raised within the init
daemon codebase.
* init/Makefile.am (init_SOURCES): Build with errors.h
* init/tests/test_cfgfile.c: Update test cases now we don't expect
a job to be returned if there's a parser error.
* TODO: Update
2007-01-06 Scott James Remnant <scott@netsplit.com>
* logd/main.c (logging_reader): Fix inadvertent shadowing of the
len parameter.
* compat/sysv/telinit.c: Oops, nearly forgot to port this to send
the messages in the new way.
* compat/sysv/shutdown.c (shutdown_now): Likewise, port this too.
* TODO: Update.
* util/initctl.c (handle_job_status): Output the process argument,
not the pid argument which contains the origin of the message.
* upstart/message.c (upstart_message_handle): Raise a new unknown
message error if we don't have a handler and a new illegal message
error if the source is illegal.
* upstart/tests/test_message.c (test_handle): Adjust tests to check
for the new errors that we raise.
* upstart/errors.h: Define strings for new errors.
* util/initctl.c: Yet another makeover for this little program,
port it to the new message/control framework using handler functions
and NihIoMessage. This starts to make each action function look
very similar, so there's method to this madness.
2007-01-05 Scott James Remnant <scott@netsplit.com>
* logd/main.c (main): Make sure that we add the SIGTERM handler.
* init/tests/test_job.c (test_run_script): This test case relies
on there only being one file descriptor watch, which won't be true
if the control socket has been opened because there's a message to
go out. Make sure it's closed first.
* init/init.supp: Update supressions file now that control_init
has been renamed to notify_init
* init/Makefile.am: Include notify.o from all tests.
* init/job.c (job_change_state, job_kill_process, job_start)
(job_stop): Use the new notify_job function name.
* init/event.c (event_queue_run): Use the new notify_event function
name.
* init/control.c (control_error_handler): Handle ECONNREFUSED now
that the process id is available to us.
* init/tests/test_control.c (test_error_handler): Make sure children
going away is handled properly.
* upstart/message.c (upstart_message_new): Store the process id in
the int_data message field.
* upstart/tests/test_message.c (test_new): Check the int_data field
is filled in.
* init/main.c (main): Guard against various things returning an error
that we weren't catching.
* init/tests/test_notify.c: Whitespace fix.
* init/control.c (control_watch_jobs, control_unwatch_jobs)
(control_watch_events, control_unwatch_events): Restore functionality
to subscribe and unsubscribe from job and event notifications.
* init/tests/test_control.c (test_watch_jobs, test_unwatch_jobs)
(test_watch_events, test_unwatch_events): Check that the subscription
and unsubscription messages work.
* init/Makefile.am (test_control_LDADD): Link to notify.o
* init/control.c: Drop unused include of upstart/errors.h
* init/notify.c: Move functions that handle subscription and
notification from control.c. Other than changing the names, we're
keeping the API the same for now; expect it to change later when we
add the ability to subscribe to individual jobs or events.
(notify_init): initialise the subscriptions list; we don't have a
separate send queue now that the control I/O is always asynchronous.
* init/notify.h: Moved notification enum, structure and prototypes
from control.h, changing the names so they match notify_* in the
process.
* init/Makefile.am (init_SOURCES): Build and link notify.c using
notify.h
(TESTS): Build the notify test suite binary.
(test_notify_SOURCES, test_notify_LDFLAGS, test_notify_LDADD): Details
for notify test suite binary.
* init/tests/test_notify.c: Rewrite test cases in the manner of
test_control.c so that we have one function for notify_job and
one for notify_event, each of which contains the child process that
receives the notification,
* init/control.c (control_open): Allow this to be called to obtain
the control socket, which means we can make it static.
* init/tests/test_control.c (test_open): Check that it works.
* init/control.c, init/control.h, init/tests/test_control.c: Move
functions that handle subscription and notification to new notify.c
(control_init): Drop completely, no need to maintain a send queue now
(control_open): Change to return an NihIo that uses the default
control watcher, and our error handler. Split socket opening into
(control_open_sock): which can be called from other functions.
(control_close): Use nih_io_close() to close the socket and free the
structure in one go.
(control_reopen): Close the open control socket and open it again
without destroying the NihIo structure, its queues or state.
(control_close_handler): Handle the control socket going away
(control_error_handler): Handle errors on the control socket,
including the connection refused error that indicates a client went
away.
(control_handle): Split this into a miriad of small functions with
a table to link them to the message type; this will make expanding
each message handler much easier in future.
* init/control.h: Update.
* init/tests/test_control.c: Rewrite test cases to check the new
handler functions; as a side-effect, this gets rid of the evil giant
child/parent functions in favour of one test function per handler
function.
* upstart/message.c (upstart_message_handle_using): Wrapper function
around upstart_message_handle that ensures all messages as passed to
a single function.
* upstart/message.h: Update.
* upstart/tests/test_message.c (test_handle_using): Make sure it
calls the single function.
2007-01-04 Scott James Remnant <scott@netsplit.com>
* upstart/message.c (upstart_message_reader): Handle any errors
that occurred while handling the message.
2007-01-02 Scott James Remnant <scott@netsplit.com>
* upstart/message.c (upstart_message_handle): Check that the name
argument is never NULL.
(upstart_message_reader): Simple message reader function that can
be associated with an I/O watch and handles each message received.
* upstart/message.h: Add prototype.
* upstart/tests/test_message.c (test_reader): Test the reader function.
* upstart/control.c: Rename to upstart/message.c
* upstart/control.h: Rename to upstart/message.h
* upstart/tests/test_control.c: Rename to upstart/tests/test_message.c
* upstart/libupstart.h: Update includes.
* upstart/wire.c: Include message.h
* upstart/wire.h: Update includes.
* upstart/tests/test_wire.c: Update includes.
* upstart/errors.h: Rename UPSTART_INVALID_MESSAGE to
UPSTART_MESSAGE_INVALID so that it's prefixed.
* upstart/Makefile.am (libupstart_la_SOURCES)
(upstartinclude_HEADERS, TESTS): Update filenames.
* upstart/control.c (upstart_message_new): New function that
creates an NihIoMessage directly from its arguments, which are a type
followed by a variable number of args depending on that type.
(upstart_message_handler): Function to find a handler function for
a particular message type and origin process.
(upstart_message_handle): New function that takes an NihIoMessage
and invokes a handler function with a variable number of args
depending on the message type.
(upstart_send_msg, upstart_send_msg_to, upstart_recv_msg): Drop these
functions, leave it up to the caller to decide whether to send and
receive the messages synchronously or asynchronously; now that the
capability is in nih_io_*.
* upstart/control.h (UpstartMsgType): Rename to UpstartMessageType.
(UpstartMessageHandler): Function with variable number of arguments
that handles a message received.
(UpstartMsg): Drop this structure entirely, we'll encode or decode
the wire format directly from or into a function call, rather than
use an intermediate structure to marshal it.
(UpstartMessage): New structure to make a table that can be passed
to upstart_message_handle to determine which handler should be called.
* upstart/tests/test_control.c: Test new behaviour.
* upstart/wire.c (upstart_push_header, upstart_pop_header): Change
structure name for type parameter.
* upstart/wire.h: Update.
* upstart/tests/test_wire.c: Update.
* configure.ac (AC_COPYRIGHT): Update copyright to 2007.
2006-12-29 Scott James Remnant <scott@netsplit.com>
* upstart/wire.c (upstart_write_int, upstart_write_unsigned)
(upstart_write_string, upstart_write_header, upstart_write_packv)
(upstart_write_pack): Rename to *_push_*
(upstart_read_int, upstart_read_unsigned, upstart_read_string)
(upstart_read_header, upstart_read_packv, upstart_read_pack): Rename
to *_pop_*.
All of the above modified to modify an NihIoMessage structure,
instead of trying to carry around buffers ourself.
* upstart/wire.h: Update to match above.
* upstart/tests/test_wire.c: Update all tests to match the above
changes.
2006-12-21 Scott James Remnant <scott@netsplit.com>
* upstart/wire.c (upstart_read_packv, upstart_write_packv): Change
nih_assert_notreached to nih_assert_not_reached.
* init/job.c (job_run_script): Open the NihIo structure in stream mode.
* logd/main.c (logging_watcher): Open the NihIo structure in
stream mode.
(logging_reader): Need to pass the length of the size_t as a pointer
so that it can be modified if less is read.
2006-12-17 Scott James Remnant <scott@netsplit.com>
* upstart/wire.c (upstart_write_packv, upstart_write_pack)
(upstart_read_packv, upstart_read_pack): Functions to write a pack
of different variables to the stream, or read them from it
* upstart/wire.h: Add prototypes.
* upstart/tests/test_wire.c (test_write_pack, test_read_pack):
Check we can read and write a pack of variables at once.
* upstart/wire.c (upstart_write_header, upstart_read_header): Drop
the version from the header, we'll just keep the protocol always
backwards compatible.
* upstart/wire.h: Update.
* upstart/tests/test_wire.c (test_write_header, test_read_header):
Check that everything works.
* upstart/wire.c (upstart_write_string, upstart_read_string):
Transmit the length as an unsigned, and use 0xffffffff to mean NULL
instead of zero so we can still transmit the empty string.
* upstart/wire.h: Update.
* upstart/tests/test_wire.c (test_write_string, test_read_string):
Tests for the functions to make sure the wire is at it should be.
* upstart/wire.c (upstart_read_str, upstart_write_str): Rename to
upstart_read_string and upstart_write_string.
* upstart/wire.h: Update.
* upstart/wire.c (upstart_write_unsigned, upstart_read_unsigned):
Functions to send unsigned values over the wire, which we'll use
to get a bit extra for the string lengths.
* upstart/wire.h: Update.
* upstart/tests/test_wire.c (test_write_unsigned)
(test_read_unsigned): Test the new functions.
* upstart/wire.c (upstart_write_ints, upstart_read_ints): Drop
these functions, we'll go with something far more generic and
useful.
* upstart/wire.h: Remove prototypes.
* upstart/wire.c (upstart_write_int, upstart_read_int): Transmit
integers as signed 32-bit values in network byte order.
* upstart/tests/test_wire.c (test_write_int, test_read_int): Test
the functions to make sure the wire is at it should be,
* upstart/control.c (upstart_read_int, upstart_write_int)
(upstart_read_ints, upstart_write_ints, upstart_read_str)
(upstart_write_str, upstart_read_header, upstart_write_header): Move
functions to new wire.c file.
* upstart/wire.c: Source file to hold wire protocol functions.
* upstart/wire.h: Prototypes.
* upstart/tests/test_wire.c: (empty) test suite.
* upstart/libupstart.h: Include wire.h
* upstart/Makefile.am (libupstart_la_SOURCES): Build and link wire.c
(upstartinclude_HEADERS): Install wire.h
(TESTS): Build and run wire test suite.
(test_wire_SOURCES, test_wire_LDFLAGS, test_wire_LDADD): Details for
wire test suite binary.
* upstart/control.c (MAGIC): Change to "upstart\n", the final
character was originally \0 and then was a " " for the 0.2 series.
* upstart/tests/test_control.c (test_recv_msg): Change to match.
2006-12-15 Scott James Remnant <scott@netsplit.com>
* util/initctl.c, compat/sysv/telinit.c, compat/sysv/shutdown.c:
Update all uses of the UpstartMsg structure to avoid the
intermediate union that no longer exists.
* init/control.c, init/tests/test_control.c: Update all uses of
the UpstartMsg structure to avoid the intermediate union that no
longer exists.
* upstart/control.h: Combine all the previous message structures
into just one that has all of the fields anyway.
* upstart/control.c, upstart/tests/test_control.c: Update all uses of
the UpstartMsg structure to avoid the intermediate union that no
longer exists.
* upstart/control.h (UPSTART_API_VERSION): Define API version macro
to be public.
* upstart/control.c (MSG_VERSION, upstart_send_msg_to): Replacing the
previous MSG_VERSION macro here.
* upstart/control.c (upstart_read_int, upstart_write_int)
(upstart_read_ints, upstart_write_ints, upstart_read_str)
(upstart_write_str, upstart_read_header, upstart_write_header):
New functions to replace the old "write a struct" protocol with
something a little more regimented and supportable.
(IOVEC_ADD, IOVEC_READ, WireHdr, WireJobPayload, WireJobStatusPayload)
(WireEventPayload): Remove these structures, use the functions
instead.
(upstart_send_msg_to): Call write functions intead of using macros,
this makes the code somewhat neater.
(upstart_recv_msg): Call read functions instead of using macros,
again making the code somewhat neater.
* upstart/tests/test_control.c (test_recv_msg): Change wire
tests to match new protocol, and thus actually work properly,
previously these were endian sensitive.
2006-12-14 Scott James Remnant <scott@netsplit.com>
* compat/sysv/shutdown.c (wall): Construct the wall message so that
we don't put \r into a po file; for some reason, gettext hates that
and bitches about it. Someone's confusing internationalisation with
operating system portability, I expect.
* util/man/initctl.8: Drop reference to start(8), as that's just
a symlink to initctl now.
* init/man/init.8: Link to initctl.
* compat/sysv/reboot.c (main): Clear up help text a little.
* HACKING: Correct some typos.
* configure.ac (AC_INIT): Correct bug reporting address.
2006-12-13 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.3.2
* NEWS: Update.
* util/initctl.c (print_job_status): Drop the newline from the
output.
2006-12-13 Alex Smith <alex@alex-smith.me.uk>
* util/initctl.c (print_job_status): Clean up initctl job status
output, which was badly converted from printf to nih_message.
2006-12-13 Scott James Remnant <scott@netsplit.com>
* compat/sysv/man/shutdown.8: Add missing documentation on the
format of TIME by copying it from --help output.
2006-12-13 Alex Smith <alex@alex-smith.me.uk>
* init/process.c (process_setup_console): Actually send output to
/dev/null instead of /dev/console, when CONSOLE_NONE.
2006-12-13 Scott James Remnant <scott@netsplit.com>
* Makefile.am (EXTRA_DIST): Distribute the nih ChangeLog as well.
* init/tests/test_job.c: Port to the new test framework.
* init/job.c (job_set_idle_event): Fix a slight memory leak,
repeated setting of the idle event never freed the previous one set.
2006-12-12 Scott James Remnant <scott@netsplit.com>
* init/tests/test_cfgfile.c: Port to the new test framework.
* init/tests/test_control.c: Port to the new test framework.
* init/init.supp: Suppress the list head allocated within control_init.
* init/control.c (control_watcher): Need to save the pid when we
get ECONNREFUSED, otherwise we lose it when we free the message.
* init/tests/test_process.c: Port to the new test framework.
* init/init.supp: Suppress the list head allocated within job_init.
* init/init.supp: Include a valgrind suppressions file.
* init/Makefile.am (EXTRA_DIST): Distribute the suppressions file.
* init/tests/test_event.c: Port to the new test framework.
* logd/Makefile.am, util/Makefile.am, compat/sys/Makefile.am
(AM_CPPFLAGS): Add -I$(srcdir), necessary for testing "programs"
that don't have usual library path semantics.
* upstart/tests/test_control.c: Port to the new test framework.
* upstart/control.c (upstart_free): Drop this function, while not
exposing libnih is a valiant effort, it already slips out because
of the error handling.
* upstart/tests/test_job.c: Add missing include.
* upstart/tests/test_job.c: Port to the new test framework.
(test_process_state_name): Check that this returns NULL.
* HACKING: Update location of download directory. Document
requirement that all code have test cases.
* logd/main.c (open_logging): Likewise.
* init/control.c (control_open): No need to set ENOMEM, errno is
always set anyway.
* configure.ac (AM_INIT_AUTOMAKE): Include nostdinc so we don't get
Automake's broken default includes.
* upstart/Makefile.am (DEFAULT_INCLUDES): Drop override now that
we don't need it.
(DEFS, INCLUDES): Replace these variables with the combined
(AM_CPPFLAGS): variable that declares everything.
* init/Makefile.am (DEFAULT_INCLUDES): Drop override now that
we don't need it.
(DEFS, INCLUDES): Replace these variables with the combined
(AM_CPPFLAGS): variable that declares everything.
* util/Makefile.am (DEFAULT_INCLUDES): Drop override now that
we don't need it.
(DEFS, INCLUDES): Replace these variables with the combined
(AM_CPPFLAGS): variable that declares everything.
* compat/sysv/Makefile.am (DEFAULT_INCLUDES): Drop override now that
we don't need it.
(DEFS, INCLUDES): Replace these variables with the combined
(AM_CPPFLAGS): variable that declares everything.
* logd/Makefile.am (DEFAULT_INCLUDES): Drop override now that
we don't need it.
(DEFS, INCLUDES): Replace these variables with the combined
(AM_CPPFLAGS): variable that declares everything.
2006-11-02 Scott James Remnant <scott@netsplit.com>
* util/initctl.c (start_action): Remove break calls which shouldn't
be there.
2006-10-18 Sean E. Russell <ser@ser1.net>
* init/main.c: Include sys/time.h
* init/cfgfile.c: Include sys/time.h and sys/resource.h
* init/job.c: Include sys/time.h and sys/resource.h
2006-10-17 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.3.1
* NEWS: Update.
* TODO: Update.
* configure.ac (AM_GNU_GETTEXT_VERSION): Quote version number.
* logd/Makefile.am (event.d/logd): Make the event.d sub-directory
in case we're building outside of the source tree.
* compat/sysv/runlevel.c (store): Don't break strict-aliasing rules
by avoiding dereferencing type-punned pointer. Answers on a
postcard, please.
2006-10-13 Scott James Remnant <scott@netsplit.com>
* util/initctl.c (start_action, emit_action): Add missing \n
* util/initctl.c: Rewrite using nih_command_parser.
* util/man/initctl.8: Improve.
* util/start.c: Remove, replaced by initctl.
* util/man/start.8: Remove, replaced by initctl.
* util/Makefile.am (sbin_PROGRAMS): Drop start, now just a symlink
to initctl.
(dist_man_MANS): Drop start.8, now a symlink to initctl.8
(install-exec-hook): Make symlinks to initctl, add start
(install-data-hook): Make symlinks to initctl.8, add start.8
* initctl: Rename to util again, I don't want a separate directory
for every single little tool; and we'll be shipping more than just
initctl (e.g. a non-compat reboot).
* configure.ac (AC_CONFIG_FILES): Make util/Makefile instead of
initctl/Makefile.
* Makefile.am (SUBDIRS): Descend into util, not initctl.
* compat/sysv/reboot.c: Remove long options where they didn't exist
before. Write help text.
* compat/sysv/man/reboot.8: Update.
* init/main.c (main): Formatting.
* logd/main.c (main): Formatting.
* logd/man/logd.8: Formatting.
* compat/sysv/runlevel.c (main): Formatting.
* compat/sysv/telinit.c (main): Formatting.
* compat/sysv/man/shutdown.8: Remove long options.
* compat/sysv/shutdown.c: Remove -e/--event, it has no place in a
compatibility tool. Get rid of long options that never existed
before. Specify help text to describe the options.
* compat/sysv/man/shutdown.8: Spruce up a bit.
* compat/sysv/telinit.c (main): Set help text to list the valid
runlevels.
* compat/sysv/man/telinit.8: Refine the notes to mention runlevel(8).
* compat/sysv/runlevel.c (main): Make the help text describe the
options, rather than the behaviour.
* compat/sysv/man/runlevel.8: Flesh out a little more.
* configure.ac (AC_INIT): Change bug reporting address to the
mailing list, since Launchpad doesn't accept random bugs without
accounts and complicated control messages.
* init/main.c, logd/main.c: Add a period to the synopsis.
* init/main.c (main): Set the synopsis, and direct people to look
at telinit in the --help output.
* init/man/init.8: Flesh this out a little more, still a lot of
explaining to do about jobs and events, but we'll wait until we've
changed that code before documentating the behaviour.
* logd/main.c (main): Correct help text to describe the options,
rather than what the program does. As per standard style.
Don't become a daemon until the logging socket is open, and make
that exclusive with waiting for SIGCONT.
* logd/man/logd.8: Write some more extensive documentation,
including describing the startup interlock and the socket protocol.
* TODO: Plan to get rid of the signal interlock from logd.
2006-10-12 Scott James Remnant <scott@netsplit.com>
* configure.ac: Expand AC_GNU_SOURCE so we get _GNU_SOURCE and so
that gettext doesn't complain.
(AM_GNU_GETTEXT_VERSION): Increase to 0.15
(AC_PREREQ): Increase to 2.60
* HACKING: Update autoconf and gettext requirements.
2006-10-11 Scott James Remnant <scott@netsplit.com>
* init/control.c (control_init): Pass NULL to nih_list_new.
Clarify list item types.
* init/event.c (event_init): Pass NULL to nih_list_new.
* init/job.c (job_init): Pass NULL to nih_list_new.
* init/main.c: Change nih_signal_add_callback to nih_signal_add_handler
and NihSignalCb to NihSignalHandler.
* init/cfgfile.c, init/cfgfile.h, init/control.c, init/control.h,
init/event.c, init/event.h, init/job.c, init/job.h, init/main.c,
init/process.c: Clean up documentation strings and parent pointer
types.
* compat/sysv/shutdown.c: Change nih_signal_add_callback to
nih_signal_add_handler.
* compat/sysv/reboot.c: Set synopsis text depending on command
used (probably should use nih_command_parser?)
* compat/sysv/runlevel.c: Set synopsis and help text, and correct
usage.
* compat/sysv/shutdown.c: Set synopsis text.
* compat/sysv/telinit.c: Set synopsis text.
* compat/sysv/runlevel.c, compat/sysv/shutdown.c: Clean up
documentation strings.
* logd/main.c: Set synopsis and help text.
* logd/main.c: Clean up documentation strings.
Change nih_signal_add_callback to nih_signal_add_handler.
* upstart/control.c, upstart/control.h, upstart/job.c: Clean up
documentation strings and correct parent pointer type.
* HACKING: Detail function documentation requirement and format.
2006-10-10 Scott James Remnant <scott@netsplit.com>
* event.d/logd.in: Move to logd/event.d
* event.d/Makefile.am: Remove
* logd/Makefile.am: Create the logd job definition and install
* Makefile.am (SUBDIRS): event.d directory has been removed.
* configure.ac (AC_CONFIG_FILES): No longer make event.d/Makefile
* configure.ac: Check for --enable-compat, default to sysv if given
or no compat if not given.
* compat/sysv/Makefile.am: Don't build binaries or install manpages
unless COMPAT_SYSV is defined.
2006-10-06 Scott James Remnant <scott@netsplit.com>
* doc/upstart-logo.svg: Include the logo Alexandre designed.
* doc/Makefile.am (EXTRA_DIST): Ship the logo in the tarball.
* Makefile.am (SUBDIRS): Install under doc
* configure.ac: Generate doc/Makefile
* AUTHORS: Ensure he's credited fully.
2006-09-27 Scott James Remnant <scott@netsplit.com>
* event.d/Makefile.am (do_subst): Eliminate duplicate /s
* man/init.8: Move to init/man
* init/Makefile.am: Update to install man page.
* man/logd.8: Move to logd/man
* logd/Makefile.am: Update to install man page.
* man/initctl.8, man/start.8: Move to initctl/man
* initctl/Makefile.am: Update to install man pages.
* man/reboot.8, man/runlevel.8, man/shutdown.8, man/telinit.8:
Move to compat/sysv/man
* compat/sysv/Makefile.am: Update to install man pages.
* man/Makefile.am: Remove
* configure.ac (AC_CONFIG_FILES): Remove man/Makefile
* Makefile.am (SUBDIRS): Don't build in man
* util: Rename to initctl
* configure.ac (AC_CONFIG_FILES): Update.
* Makefile.am (SUBDIRS): Update.
* util/reboot.c: Move to compat/sysv
* util/shutdown.c: Move to compat/sysv
* util/Makefile.am: Update.
* compat/sysv/Makefile.am: Update.
* configure.ac: Replace macros with single call to NIH_INIT.
Bump version to 0.3.0 to begin new development cycle.
2006-09-21 Scott James Remnant <scott@netsplit.com>
* logd/main.c: Revert the change that logged to the console, in
practice this doesn't work so well. I want to get rid of logd
in the long term, or at least just have it as a simple logging
proxy, so giving it features seems wrong.
2006-09-20 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.2.8
* NEWS: Updated.
* logd/main.c (main): Check the kernel command-line for "quiet"
(line_reader): Write to console unless silent or a daemon
* man/Makefile.am (dist_man_MANS): Drop sulogin.8
* man/sulogin.8: Drop, we don't include an sulogin
2006-09-19 Michael Biebl <mbiebl@gmail.com>
* event.d/Makefile.am (logd): Drop $(srcdir)
* init/Makefile.am (init_SOURCES): Distribute paths.h
2006-09-18 Michael Biebl <mbiebl@gmail.com>
* configure.ac: Check for sys/inotify.h
2006-09-18 Scott James Remnant <scott@netsplit.com>
* util/shutdown.c (warning_message): Adjust method of constructing
the message to not confuse poor translators who think \r and \n are
the same thing!
2006-09-14 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_change_state): Catch runaway respawns when we
enter the running state, so we catch stop/start loops too.
* init/tests/test_job.c (test_change_state): Update test.
* event.d/logd: Rename to logd.in
* event.d/logd.in: Replace /sbin with @sbindir@ so we can transform
* event.d/Makefile.am: Generate logd from logd.in
* util/reboot.c: Don't hardcode the location of /sbin/shutdown
* util/Makefile.am (DEFS): Use autoconf to seed it
* util/shutdown.c (sysvinit_shutdown): Don't hardcode the location
of /dev/initctl
* init/paths.h: Create a new configuration file that can contain
all of the path definitions, and in particular, allow them to be
overidden elsewhere.
* init/Makefile.am (DEFS): Override definitions of CFG_DIR and
TELINIT using autoconf
* init/main.c: Include paths.h. Don't hardcode location of telinit
* init/job.c: Include paths.h
* init/process.c: Include paths.h
* init/process.h: Remove definitions from here.
* configure.ac: Bump version to 0.2.7
2006-09-13 Scott James Remnant <scott@netsplit.com>
* NEWS: Updated.
* TODO: More TODO.
2006-09-10 Scott James Remnant <scott@netsplit.com>
* util/reboot.c (main): Don't give -H with "halt".
2006-09-09 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.2.6
* NEWS: Update.
* TODO: Update.
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Change
the magic to be the package string.
* upstart/tests/test_control.c (test_recv_msg): Update tests.
* util/initctl.c (main): Set the usage string.
* util/shutdown.c (main): Set the usage string.
* util/start.c (main): Set the usage string.
* compat/sysv/runlevel.c (main): Set the usage string.
* compat/sysv/telinit.c (main): Set the usage string.
* man/Makefile.am: Use install-data-hook and $(man8dir)
* util/Makefile.am: Also use install-exec-hook
* Makefile.am (SUBDIRS): Install contents of the man directory
* configure.ac (AC_CONFIG_FILES): Generate man/Makefile
* man/Makefile.am: Install manpages in the appropriate places.
* man/init.8, man/logd.8, man/initctl.8, man/reboot.8,
* man/shutdown.8, man/start.8, man/sulogin.8, man/runlevel.8,
* man/telinit.8: Include some basic manpages so we at least have
some level of documentation.
* init/job.c (job_child_reaper): Don't check the exit status of
a respawning job if the goal is to stop it.
* compat/sysv/telinit.c (main): Generate events rather than
starting and stopping jobs directly, the events are named
"runlevel-X". 0, 1, 6 and s/S are shutdown events.
* logd/main.c (main): Raise SIGSTOP before entering the main loop.
* init/main.c (main): Interlock with logd.
* event.d/logd: Should not be a console owner, but should stop
on shutdown.
* init/process.c (process_setup_console): Revert part of the previous
change, should just output to /dev/null if we don't have logd.
* configure.ac: Bump version to 0.2.5
* init/main.c (main): Start the logd job if it exists.
* init/process.c (process_setup_console): Ignore ECONNREFUSED as
that just means that logd isn't around, handle errors by falling
back to opening the console.
* init/process.c (process_setup_console): Implement handling for
CONSOLE_LOGGED and generally clean up the other handling.
* init/process.h: Update.
* init/main.c (main): Pass NULL for the job to setup console.
* TODO: Update.
* logd/main.c: Implement the logging daemon, it accepts connections
on a unix stream socket with the abstract name
"/com/ubuntu/upstart/logd", expects the length of the name and the
name to follow; then sequences of lines which are logged to
/var/log/boot, or memory until that file can be opened.
2006-09-08 Scott James Remnant <scott@netsplit.com>
* util/shutdown.c (event_setter): Change the event names to
distinguish between "shutdown -h" and "shutdown -h -H".
* init/job.c (job_handle_event): Allow jobs to react to their own
events, this is how we'll do respawn eventually.
* init/tests/test_job.c (test_handle_event): Remove test.
* init/main.c (cad_handler, kbd_handler): Generate the new event
names.
* init/event.h (CTRLALTDEL_EVENT, KBDREQUEST_EVENT): Add definitions
of these event names, change the ctrlaltdel event to just that.
* logd/main.c (main): Add the code to daemonise, etc.
2006-09-07 Scott James Remnant <scott@netsplit.com>
* TODO: Long discussion today on #upstart, many improvements to the
job and event model that make it more elegant.
* AUTHORS: Include a list of thanks.
* util/shutdown.c (shutdown_now): If we get ECONNREFUSED when we
try and send the shutdown event to init, it probably means we're
still in sysvinit. So try that instead.
(sysvinit_shutdown): Function to send a hand-crafted runlevel
change message across /dev/initctl.
* util/initctl.c (main): Add a shutdown command that takes an
arbitrary event name to be issued after "shutdown". You'll
nearly always want the /sbin/shutdown tool instead.
* init/job.c (job_detect_idle): Only generate the stalled event
if at least one job handles it in its start_events list.
* init/tests/test_job.c (test_detect_idle): Make sure that works.
* init/event.h (STARTUP_EVENT, SHUTDOWN_EVENT, STALLED_EVENT):
Macros to define the standard event names.
* init/main.c (main): Use STARTUP_EVENT macro instead of "startup"
* init/control.c (control_handle): Use SHUTDOWN_EVENT macro
instead of "shutdown".
* init/job.c (job_detect_idle): Use STALLED_EVENT macro instead
of "stalled".
* init/job.c (job_detect_idle): Add some log messages for when we
detect the idle or stalled states.
(job_kill_process, job_kill_timer): Increase log verbosity.
* init/event.c (event_queue_run): Log which events we're handling
if --debug is given.
* compat/sysv/telinit.c (main): Send a shutdown command when
requesting to enter runlevel 0 or runlevel 6, likewise for
runlevel 1, s or S which all run "rc1" not "rcS".
* init/main.c (main): When called directory (pid != 1) try and
run telinit before complaining that we're not init. Make sure
errors aren't lost.
2006-09-04 Johan Kiviniemi <johan@kiviniemi.name>
* upstart/control.c (upstart_addr): Replace use of __builtin_offsetof
with offsetof.
* upstart/tests/test_control.c (test_recv_msg): Likewise.
2006-09-04 Scott James Remnant <scott@netsplit.com>
* util/shutdown.c (main): Exit normally after sending the warning
message if -k is given.
2006-09-01 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.2.2
* NEWS: Update.
* configure.ac: Bump version to 0.2.1
* init/process.c (process_setup_console): Ensure that the console
is always initialised to at least /dev/null
* init/job.c (job_change_state): Initialise event to NULL.
* init/event.c (event_read_state): Don't mask initialisation of
other variable.
* init/cfgfile.c (cfg_job_stanza, cfg_parse_script, cfg_next_token):
Print lineno using %zi not %d
* compat/sysv/runlevel.c (store): Cast pointer type of timeval.
* init/main.c: Move the kernel headers include beneath the C
library ones, so that compilation doesn't fail on !i386.
* util/reboot.c: Likewise.
* init/main.c (term_handler): Close the control connection if we
re-exec init, otherwise it won't be able to bind. Drop debugging.
* init/main.c (term_handler): It always helps if we dup2 the
right file descriptor.
* init/main.c: Use the TERM signal instead of USR1, as old init
used that for something else. Also rather than passing across
file descriptor numbers, use a fixed descriptor and just pass
"--restart". When we get that option we need to unmask signals
otherwise we sit there looking like a lemon.
* init/job.c (job_change_state): Don't free the event unless we
generate one.
* NEWS: Update.
* init/cfgfile.c (cfg_watcher): Ignore any file with '.' or '~'
* TODO: Update.
* init/main.c (main): Parse command-line arguments, specifically
look for --state-fd which we'll use for reexec. Don't do a couple
of things if we're passed this.
(read_state): Parse the line-buffered state.
* init/job.c (job_read_state, job_write_state): Job state
serialisation so that we can re-exec ourselves.
* init/job.h: Update.
* init/tests/test_job.c: Test the serialisation.
* init/event.c (event_read_state, event_write_state): And similar
functions for serialising the event queue.
* init/event.h: Update.
* init/tests/test_event.c: Test the serialisation.
* init/cfgfile.c (cfg_read_job): Fix a bug, need to subtract current
time to get due time.
* upstart/job.c (job_goal_from_name, job_state_from_name)
(process_state_from_name): Add opposite numbers that convert a
string back into an enumeration.
* upstart/job.h: Update.
* upstart/tests/test_job.c: Test the new functions.
2006-08-31 Scott James Remnant <scott@netsplit.com>
* init/job.h (Job): Add respawn_limit, respawn_interval,
respawn_count and respawn_time members so that we can keep track of
runaway processes.
* init/job.c (job_catch_runaway): Increment the respawn_count
within respawn_interval, or reset it if we go over.
(job_new): Initialise respawn_limit and respawn_interval to sensible
defaults.
* init/tests/test_job.c (test_new): Check the defaults are set.
(test_change_state): Check the respawning code works.
* init/cfgfile.c (cfg_job_stanza): Parse the "respawn limit" stanza.
* init/tests/test_cfgfile.c (test_read_job): Test the new stanza.
* init/process.c (process_setup_console): Remove the console reset
code, it tends to just crash X and seems to do nothing interesting.
* init/main.c (reset_console): Instead put it here and just do it
on startup.
* configure.ac: Bump version to 0.2.0
* util/Makefile.am (install-exec-local): Create symbolic links,
not hard links.
* init/main.c: Can't catch STOP.
* util/reboot.c: Pause init while shutting down or rebooting.
* init/main.c (stop_handler): Catch STOP/TSTP and CONT.
* init/event.c (event_queue_run): Don't run the event queue while
paused.
* init/job.c (job_detect_idle): Don't detect idle jobs while paused.
* util/reboot.c: if we get the -w argument ("only write to wtmp")
we need to exit, and not behave as halt normally would.
* compat/sysv/runlevel.c (main): Add missing newline.
* compat/sysv/telinit.c (main): And here too.
* init/main.c (main): Check for idle after the startup event queue
has been run, otherwise we may just sit there.
* compat/sysv/Makefile.am (sbin_PROGRAMS): Build and install telinit
(telinit_SOURCES, telinit_LDFLAGS, telinit_LDADD): Details for
telinit binary.
* compat/sysv/telinit.c: Trivial telinit program that just runs
the appropriate rcX job.
* compat/sysv/runlevel.c (main): Suggest help on illegal runlevel.
* util/Makefile.am: Tidy up.
* configure.ac (AC_CONFIG_FILES): Create compat/sysv/Makefile
* Makefile.am (SUBDIRS): Build things found in compat/sysv
* compat/sysv/Makefile.am (sbin_PROGRAMS): Build and install runlevel
(runlevel_SOURCES, runlevel_LDFLAGS, runlevel_LDADD): Details for
runlevel binary.
* compat/sysv/runlevel.c: Helper to store and retrieve the current
"runlevel" from utmp/wtmp; as well as the reboot time.
* init/main.c (main): Drop debugging set.
* init/job.c (job_change_state): As well as the job/state events,
send the job event when a service is running or a task is stopping.
* init/tests/test_job.c (test_change_state): Check the events get
sent properly.
* util/start.c: Write a simple utility to start, stop, or query
the status of the named jobs.
* util/Makefile.am (sbin_PROGRAMS): Build and install start
(start_SOURCES, start_LDFLAGS, start_LDADD): Details for start
(install-exec-local): Also install as stop and status.
* util/reboot.c (main): Drop the debugging set.
* init/cfgfile.c (cfg_job_stanza): Correct nih_alloc error.
* init/process.c (process_setup_environment): Guard memory alloc.
* init/job.c (job_set_idle_event): Likewise.
(job_change_state): And here too.
(job_run_command): Likewise.
* init/control.c (control_send): Likewise.
* init/cfgfile.c: And throughout this file.
* upstart/control.c (upstart_recv_msg): And once here too.
* upstart/control.h: Abolish the separate halt, reboot and poweroff
messages and replace with a single shutdown message that takes
an event name (for the idle event issued afterwards).
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Handle
the new shutdown event type by just treating it as an event.
* upstart/tests/test_control.c (test_messages): Update tests.
* init/job.c (job_set_idle_event): Store a copy of the idle event
name.
* init/control.c (control_send): Copy the shutdown event name.
(control_handle): Replace individual handling with the new
single event.
* init/tests/test_control.c (test_watcher): Update.
* util/initctl.c: Drop handling for things that shutdown does now.
* util/shutdown.c: Send the UPSTART_SHUTDOWN event and let the user
specify anything they want, just give defaults.
This is quite a big change and abolishes level events entirely,
along with the event history. We now just treat events as a
transient queue of strings that go past, may cause things to change,
but are otherwise forgotten. This turns out to be much easier to
understand and has no real loss of power.
* init/event.c: Vastly simplify; gone are the separate notions of
edge and level events, instead we just treat them as one-shot
things that go past and are forgotten about.
* init/event.h (Event): Remove value member.
Update prototypes.
* init/tests/test_event.c: Update.
* init/job.c (job_change_state): Change the event pattern to be
one that includes the job name and a description of the transition
instead of the new state.
(job_detect_idle): Call event_queue rather than event_queue_edge.
* init/tests/test_job.c: Update.
* init/cfgfile.c (cfg_job_stanza): Drop "when" and "while".
* init/tests/test_cfgfile.c (test_read_job): Drop mentions of
"when" and "while".
* init/control.c (control_send, control_handle): Drop cases for
level events.
(control_handle_event): Don't include a level in the event.
* init/tests/test_control.c: Update
* init/main.c: Call event_queue rather than event_queue_edge.
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Change
event handling so that only a name is read.
* upstart/control.h: Remove value/level event structures.
* upstart/tests/test_control.c (test_messages): Update.
* upstart/job.c (process_state_name): Not used for events, adjust
documentation so it doesn't lie.
* util/initctl.c (main): Drop the set function, simplify trigger.
* util/shutdown.c (shutdown_now): Call UPSTART_EVENT_QUEUE for
shutdown into maintenance mode.
* init/control.c (control_handle): Place a message in the syslog
before halting, powering off or rebooting.
* util/shutdown.c: Adjust so that the warning message is sent out
if shutdown is immediate, and when it actually happens. Include
the hostname as wall does.
2006-08-30 Scott James Remnant <scott@netsplit.com>
* TODO: Update.
* util/shutdown.c: Implement shutdown utility along the same lines
as the sysvinit one, but with rather different code.
* util/initctl.c (main): Call setuid on the effective user id so
that we can be made setuid root and executable by a special group.
* util/reboot.c (main): Likewise.
* util/initctl.c (main): Check the effective rather than the real
user id, if we're effectively root, that's good enough.
* util/reboot.c: Implement reboot/halt/poweroff utility.
* util/Makefile.am (sbin_PROGRAMS): Build and install reboot
(reboot_SOURCES, reboot_LDFLAGS, reboot_LDADD): Details for reboot
(install-exec-local): Create hardlinks to reboot for halt and poweroff.
2006-08-29 Scott James Remnant <scott@netsplit.com>
* init/main.c (main): Actually run the idle-detect function.
* init/job.c (job_detect_idle): Interrupt the main loop, otherwise
we may end up waiting for a signal before we process the event
we just issued.
2006-08-27 Scott James Remnant <scott@netsplit.com>
* util/shutdown.c: Template main function.
* util/Makefile.am (sbin_PROGRAMS): Build and install the
shutdown binary.
(shutdown_SOURCES, shutdown_LDFLAGS, shutdown_LDADD): Details for
the shutdown binary
* util/initctl.c (main): Add commands for halt, poweroff and reboot.
* init/event.c (event_queue_run): Remove the parameters.
* init/event.h: Update.
* init/main.c (main): Update.
* init/tests/test_control.c (test_watcher): Update.
* init/tests/test_job.c (test_detect_idle): Update.
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Deal
with halting, rebooting and powering off; or at least the appropriate
messages.
* upstart/control.h: Add control message structures for halting,
powering off and rebooting the machine.
* upstart/tests/test_control.c (test_messages): Run the tests.
* init/control.c (control_handle): Add handling for halt, power off
and reboot that issue the shutdown event and arrange for the halt,
poweroff or reboot to be issued the next time the system is idle.
* init/tests/test_control.c (test_watcher): Test the events.
* TODO: Update.
* init/job.c (job_detect_idle): Function to detect when the system is
stalled or idle.
* init/job.h: Update
* init/tests/test_job.c (test_detect_idle): Test the new function.
* util/initctl.c (main): Handle the list command.
* TODO: Update.
* upstart/control.c (WireJobStatusPayload): add description to the
job status payload.
(upstart_send_msg_to, upstart_recv_msg): Send and receieve the
description over the wire.
* upstart/control.h (UpstartJobStatusMsg): add a description field
* upstart/tests/test_control.c: Update test cases.
* init/control.c (control_handle): Include the job description in
the message.
(control_send): Copy the description when we put the message on
the queue.
(control_handle_job): Copy the description here too
* init/tests/test_control.c: Update test cases.
* init/job.c (job_list): Add a function to return the job list.
* init/job.h: Update.
* init/control.c (control_handle): Handle the JOB_LIST message
by sending back a list of job status messages followed by the
JOB_LIST_END message.
* init/tests/test_control.c (test_watcher_child): Check the
JOB_LIST message works properly.
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Handle
the JOB_LIST and JOB_LIST_END messages which have no payload.
* upstart/control.h: Add enums and structures for job list messages.
* upstart/tests/test_control.c (test_messages): Update tests.
* init/main.c (main): Check that we're both uid and process #1
* init/main.c (main): Stop handling SIGTERM, we never want people
to kill init. Handle SIGINT and SIGWINCH through the ordinary
handler and SIGSEGV through a direct handler.
(segv_handler): Write a sensible core dump handler, we use a child
to dump core while we carry on in the parent hopefully stepping over
the bad instruction.
(cad_handler): Generate the control-alt-delete event.
(kbd_handler): Generate the kbdrequest event.
2006-08-25 Scott James Remnant <scott@netsplit.com>
* configure.ac: Bump version to 0.1.2
* NEWS: Update.
* TODO: Update.
* init/process.c (process_setup_environment): Inherit the PATH
and TERM environment variables from the init process, so the
console works properly.
* init/process.h (PATH): Declare a default value for this variable
* init/main.c (main): Set the value of PATH to the default.
* init/tests/test_process.c (child): Update test case.
* NEWS: Update.
* configure.ac: Bump version to 0.1.1
2006-08-24 Scott James Remnant <scott@netsplit.com>
* init/cfgfile.h (CFG_DIR): Change configuration directory to
/etc/event.d -- it's not been used by anyone, but is similar to
other directories that have which is a good precedent.
* event.d/Makefile.am (eventdir, dist_event_DATA): Install files
into the new directory name.
* Makefile.am (SUBDIRS): Rename sub directory
* configure.ac (AC_CONFIG_FILES): Rename generated Makefile
* init/Makefile.am (DEFAULT_INCLUDES): Set to include the right
directories so out of tree builds work.
* logd/Makefile.am (DEFAULT_INCLUDES): Set to include the right
directories so out of tree builds work.
* upstart/Makefile.am (DEFAULT_INCLUDES): Set to include the right
directories so out of tree builds work.
(upstartinclude_HEADERS): Install errors.h
* util/Makefile.am (DEFAULT_INCLUDES): Set to include the right
directories so out of tree builds work.
* Makefile.am (SUBDIRS): Add m4 to the list
* configure.ac (AC_CONFIG_FILES): Generate m4/Makefile
* upstart/Makefile.am (upstartinclude_HEADERS): Add errors.h
* upstart/control.c (upstart_open):
* init/control.c (control_open): Raise the error before
performing other actions so errno is not lost.
* TODO: Update.o
* init/cfgfile.c (cfg_next_token): Don't count quote characters
unless we're actually planning to dequote the file, otherwise we
end up allocating short.
* init/control.c (control_close): Free the io_watch using list_free
in case a destructor has been set.
* init/tests/test_control.c: Initialise the type of the message, and
free job correctly.
* upstart/tests/test_control.c: Fix overwrite of buffer.
* init/tests/test_job.c: Clean up not-freed job.
2006-08-23 Scott James Remnant <scott@netsplit.com>
* init/tests/test_event.c: free the entry allocated and initialise
the return values.
* init/cfgfile.c (cfg_skip_token): Drop this function; we'll
make sure *pos is pointing at the start of the thing we want
to parse, not the first token. Update the other functions
accordingly.
(cfg_read_job): Implement function to look over a job file and
parse all of the stanzas that are found. Also sanity checks the
job afterwards and deals with reloading existing jobs.
(cfg_job_stanza): Function that parses an individual stanza,
calling out to the other parse functions; this is the main config
file parser!
(cfg_parse_args, cfg_parse_command): Drop requirement that filename
and lineno be passed, so we can be called to reparse arguments after
we've already done so.
(cfg_parse_script): Remove requirement that it be called at the
start of the entire stanza, and instead at the start of the script.
When hitting EOF, return the script so far, not NULL.
(cfg_parse_args): Correct bug where we didn't check sufficient
characters while skipping whitespace.
(cfg_next_token): Correct bug where we didn't copy the character
after a slash into the text, instead of just not copying the slash.
Adjust line numbers to match the fact that it's zero based now.
* init/cfgfile.h: Define prototype.
* init/tests/test_cfgfile.c (test_read_job): Pretty thoroughly
test the config file parser code.
2006-08-22 Scott James Remnant <scott@netsplit.com>
* init/cfgfile.c (cfg_tokenise): Rename to cfg_next_token.
(cfg_skip_token): Code to skip whitespace, token and whitespace.
(cfg_parse_args): Function to parse an argument list.
(cfg_next_token): Extend to support the removal of quotes and
slashes from the token.
* init/cfgfile.c (cfg_parse_script): Pass filename and lineno and
increment the latter as we go.
(cfg_script_end): Pass and increment lineno.
* init/cfgfile.c: Correct a missing semi-colon in prototypes.
(cfg_parse_command): Function to parse any stanza that requires
a command and arguments list, e.g. exec/respawn/daemon. We don't
want to require that the list be quoted, etc. and do want to allow
it to be folded over lines.
(cfg_tokenise): Function used by the above to tokenise the file,
handling things like \, quoted strings and newlines, etc. Can be
used both to determine the length of the token and to copy it.
* init/cfgfile.c (cfg_read_script): Rename to cfg_parse_script.
* init/cfgfile.c (cfg_read_script): Function to parse a script
fragment ("foo script\n....end script\n") from the job file, which
is the most complex form we can find. Write it assuming the file is
in a character array which may not be NULL terminated (ie. a mmap'd
file).
(cfg_script_end): Used by the above to detect the end of the
fragment.
* init/cfgfile.h: Empty header file.
* init/Makefile.am (init_SOURCES): Build and link cfgfile.c
using the cfgfile.h header
(TESTS): Build and run the config file test cases.
(test_cfgfile_SOURCES, test_cfgfile_LDFLAGS, test_cfgfile_LDADD):
Details for config file test case binary.
* init/main.c (main): Remove the calls to the unfinished config
file code.
2006-08-21 Scott James Remnant <scott@netsplit.com>
* init/main.c: Add missing include for unistd.h
* init/process.c (process_setup_console): Drop use of job.
* util/initctl.c (main): Check that we're run as root.
* init/main.c (main): Write the main function
* init/event.c (event_queue_cb): Rename to event_queue_run.
* init/event.h: Update.
* init/process.c (process_setup_console): Become an exported
function that includes the code to reset a console.
2006-08-19 Scott James Remnant <scott@netsplit.com>
* logd/main.c (main): Write the basic main function.
* util/initctl.c (main): Fill in the details to give us a basic
test client.
* TODO: Update.
* util/initctl.c (main): Provide the most basic main function.
* util/Makefile.am (sbin_PROGRAMS): Build the initctl binary
* Makefile.am (SUBDIRS): Build the utilities.
* configure.ac (AC_CONFIG_FILES): Generate the util Makefile.
2006-08-18 Scott James Remnant <scott@netsplit.com>
* init/Makefile.am (test_job_LDADD): Remove the duplicate link.
* TODO: Update.
* init/job.c (job_handle_child): Rename to job_child_reaper.
* init/job.h: Update.
* init/tests/test_job.c: Update function names.
* init/control.c (control_cb): Rename to control_watcher
* init/tests/test_control.c: Update function names.
* TODO: Update.
* Makefile.am (SUBDIRS): Install the rc.d files.
* configure.ac (AC_CONFIG_FILES): Generate the rc.d Makefile.
* rc.d/Makefile.am (rcdir): Define rcdir to be /etc/rc.d
(dist_rc_DATA): Install the logd file into that directory.
* rc.d/logd: Write a simple service definition for the log daemon,
this saves us hardcoding any information about it into init; it'll
just need to know the name.
* Makefile.am (SUBDIRS): Build the logd daemon
* configure.ac (AC_CONFIG_FILES): Generate the logd Makefile.
* logd/Makefile.am (sbin_PROGRAMS): Install the logd binary into
the sbin directory by default.
(logd_SOURCES): Build and link main.c
* logd/main.c (main): Add basic main function for testing purposes.
2006-08-16 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_start): Ignore self-dependencies; over-document
why the dependency event prodding has a surprise in its tail.
(job_change_state): Move the job_release_depends call to here.
* init/event.c (event_queue_cb): Add event consumer/dispatcher.
* init/event.h: Update.
* init/control.c (control_send): Make the event code clearer.
(control_handle): Handle the changed event semantics.
(control_handle_event): Issue the new event type.
* init/tests/test_control.c: Update tests.
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Adjust
marshal code to match.
* upstart/control.h: Update all structures appropriately to the
previous changes.
* upstart/tests/test_control.c: Update.
* init/job.c (job_change_state): Change call to event_trigger_level
to event_queue_level.
* init/event.c (event_trigger_edge, event_trigger_level): Place
the event on the event_queue rather than directly triggering it.
Rename to event_queue_edge and event_queue_level respectively.
* init/event.h: Update.
* init/tests/test_event.c: Update test cases.
* init/job.c (job_handle_event): Add another sanity check, jobs
should not be able to react to their own events; that's just silly.
* init/tests/test_job.c (test_handle_event): Check that the new
condition does the right thing.
* init/job.c (job_change_state): Make it illegal for a job to exist
without either a command or script or both. This is for sanity
reasons, allowing no primary process makes no sense and can lead
to event loops if someone is feeling nefarious.
* init/tests/test_job.c (test_change_state): Drop test on behaviour
we've just outlawed.
* init/job.c (job_start): Only announce the change if we're still
in the waiting state, we could have moved on to running already.
* init/job.c (job_start): If holding the job, at least announce
the goal change to subscribed clients.
* TODO: Update.
* init/job.c (job_start): Check for dependencies before starting
the process, if we have any that aren't running we stay in waiting
until they are. Any that aren't even starting get poked with a
dependency event to see whether that wakes them up.
* init/tests/test_job.c (test_start): Test paths through new
dependency code.
* init/job.c (job_run_process): Once we've got an active process
in the running state, release our dependencies.
* init/job.c (job_release_depends): Function to release any waiting
dependencies on the given job.
* init/job.h: Update.
* init/tests/test_job.c (test_release_depends): Test the behaviour
of the function on its own.
* init/job.h (Job): Add depends list field
(JobName): New structure to hold the name of a job.
* init/job.c (job_new): Initialise the depends list.
* init/tests/test_job.c (test_new): Make sure the depends list is
initialised properly.
* init/job.c (job_next_state): Return JOB_STARTING if we're in
JOB_WAITING and the goal is JOB_START. This is only called when
there's some change, and I don't want to hard-code the goal there.
(job_start): Don't hardcode JOB_STARTING, instead just use the next
state.
* init/tests/test_job.c (test_next_state): Adjust test case.
* init/control.c (control_subscribe): Allow the current
subscription to be found by passing NOTIFY_NONE.
(control_handle): Don't remove an existing subscription to jobs,
a GUI will probably want a permanent one to keep the status up to
date.
* init/job.c (job_kill_process, job_kill_timer): Don't hardcode
JOB_STOPPING here, instead move to the next logical state.
(job_kill_process): Notify subscribed processes that we killed
the job.
(job_start, job_stop): Notify subscribed processes of a change of
goal that doesn't result in an immediate state change.
* init/event.c (event_trigger_edge, event_trigger_level): Swap
order so that events are announced before processed.
* init/control.c (control_handle): Handle requests to watch and
unwatch jobs and events.
* init/tests/test_control.c (test_cb_child, test_cb): Check that
subscriptions work.
* init/tests/test_control.c (test_cb_child): Add a sleep to avoid
a race that upsets gdb, have tried this with a STOP/CONT interlock
but can't seem to find where the child should reach first.
* init/job.c (job_change_state): Notify the control handler.
* init/event.c (event_trigger_edge, event_trigger_level): Pass
event to the control handler.
* init/tests/test_control.c (test_cb_child): Expect to receive
job status events as well.
* init/Makefile.am (test_event_LDADD, test_process_LDADD)
(test_job_LDADD): Add control.o to the linkage.
* init/control.c (control_cb): Don't display an error for
ECONNREFUSED, just remove any subscriptions.
* init/tests/test_control.c (test_handle_job, test_handle_error):
Clean up our subscriptions properly.
* init/control.c (control_handle_job): Function to send out an
UPSTART_JOB_STATUS message to subscribed processes whenever a
job state changes.
(control_handle_event): Function to send out an
UPSTART_EVENT_TRIGGERED message to subscribed processes whenever
an event is triggered.
* init/control.h: Update.
* init/tests/test_control.c (test_handle_job, test_handle_event):
Check that the functions work properly.
* init/control.c (control_handle): Handle messages that trigger
edge and level events; subscribe the process to receive notification
of job changes during the event.
* init/tests/test_control.c (test_cb_child): Check that the messages
are handled properly (without subscription check).
* init/control.c (control_cb): Unsubscribe a process if it stops
listening.
* init/control.c (control_send): Copy the pointers in the new
event messages.
* init/tests/test_control.c (test_send): Check the pointers are
copied across correctly.
* init/control.c (control_subscribe): Add function to handle
processes that want to subscribe to changes.
(control_init): Initialise the subscriptions list.
* init/control.h: Add structures and prototypes.
* init/tests/test_control.c (test_subscribe): Test the function.
* upstart/control.h (UpstartMsgType): add messages for triggering
edge and level events, receiving the trigger for an event and for
watching jobs and events.
(UpstartEventTriggerEdgeMsg, UpstartEventTriggerLevelMsg)
(UpstartEventTriggeredMsg, UpstartWatchJobsMsg)
(UpstartUnwatchJobsMsg, UpstartWatchEventsMsg):
(UpstartUnwatchEventsMsg): Add structures for the new messages.
(UpstartMsg): And add them to the union.
* upstart/control.c (WireEventPayload): The event messages can all
share a wire payload type; the watch messages don't need any special
payload.
(upstart_send_msg_to): Add the payloads onto the wire.
(upstart_recv_msg): And take the payloads back off the wire.
* upstart/tests/test_control.c (test_messages): Test the new
message types.
* upstart/control.h (UpstartJobStatusMsg): add a process id.
* upstart/control.c (WireJobStatusPayload): and here too.
(upstart_send_msg_to): copy the process id onto the wire.
(upstart_recv_msg): copy the process id from the wire.
* init/control.c (control_handle): Fill in the pid from the job.
* upstart/tests/test_control.c (test_messages): Check the pid gets
passed across the wire properly.
* init/control.c (control_cb): Disable the poll for write once the
send queue becomes empty.
* upstart/Makefile.am (libupstart_la_SOURCES): Correct ordering.
* init/control.c (control_handle): Add missing break.
* upstart/job.c (job_goal_name, process_state_name): For completeness
add these two functions as well.
* upstart/job.h: Update.
* upstart/tests/test_job.c (test_goal_name)
(test_process_state_name): Test the new functions.
* init/job.c (job_state_name): Move this utility function from here
* upstart/job.c (job_state_name): to here so all clients can use
it.
* init/job.h: Update.
* upstart/job.h: Update.
* init/tests/test_job.c (test_state_name): Move the test case from here
* upstart/tests/test_job.c: to here as well.
* upstart/Makefile.am (libupstart_la_SOURCES): Build and link job.c
(TESTS): Run the job test cases
(test_job_SOURCES, test_job_LDFLAGS, test_job_LDADD): Details for
job test case binary.
* init/Makefile.am (test_job_LDADD, test_process_LDADD)
(test_event_LDADD): Link to libupstart.la
* init/control.c: Code to handle the server end of the control
socket, a bit more complex than a client as we want to avoid
blocking on malcious clients.
* init/control.h: Prototypes.
* init/tests/test_control.c: Test the control code.
* init/Makefile.am (init_SOURCES): Build and link control.c
using the control.h header
(init_LDADD): Link to libupstart as well
(TESTS): Build and run the control test suite.
(test_control_SOURCES, test_control_LDFLAGS, test_control_LDADD):
Details for control test suite binary.
* upstart/control.c: Add a way to disable the safety checks.
* upstart/tests/test_control.c (test_free): Fix bad test case.
* upstart/control.c (upstart_recv_msg): fixed bogus return type
for recvmsg from size_t to ssize_t so we don't infiniloop on error.
* upstart/control.c (upstart_send_msg_to, upstart_recv_msg): Avoid
job_start as the short-cut for assigning name, as that might become
a more complex message eventually. Use job_query instead.
* upstart/control.c (upstart_free): Add wrapper function around
nih_free so we're a proper library and don't expose libnih too much
(upstart_recv_msg): Stash the sender pid in an argument.
* upstart/control.h: Update.
* upstart/tests/test_control.c (test_recv_msg): Test pid is
returned properly.
(test_free): Test the nih_free wrapper.
* init/job.c (job_run_script): Document future FIXME.
* init/exent.h, init/job.h, init/process.h: Fix up headers.
* upstart/control.c, upstart/control.h, upstart/errors.h,
upstart/job.h, upstart/libupstart.h: Fix up headers.
* upstart/control.c: Write the code to handle the control socket
and communication over it; turns out this was possible to write so
that both ends are handled in the same code.
* upstart/control.h: Structures and prototypes.
* upstart/tests/test_control.c: Test the new code.
* upstart/Makefile.am (libupstart_la_LIBADD): Link to libnih
* upstart/errors.h: Header file containing errors raised by
libupstart.
* upstart/libupstart.h: Include errors.h
2006-08-15 Scott James Remnant <scott@netsplit.com>
* init/event.h: Add missing attribute for event_new()
* init/job.h (JobGoal, JobState, ProcessState, ConsoleType): Move
the enums from here
* upstart/job.h: into here so that we can use them across the
control socket.
* Makefile.am (SUBDIRS): Build the libupstart library
* configure.ac (AC_CONFIG_FILES): Generate upstart/Makefile
* upstart/Makefile.am: Makefile for sub-directory
* upstart/libupstart.ver: Linker version script.
* upstart/libupstart.h: "Include everything" header file.
* TODO: Update.
* init/job.c (job_handle_child): Warn when processes are killed
or exit with an abnormal status. Warn when respawning.
* init/job.c (job_handle_child): Respawn processes that were not
supposed to have died.
* init/tests/test_job.c (test_handle_child): Test the respawn code.
* TODO: Update.
* init/event.c (event_trigger_edge, event_trigger_level): Call
job_handle_event so that we actually do something useful.
* init/Makefile.am (test_event_LDADD): Link to process.o and job.o
now that event.c calls code from job.
* init/job.c (job_start_event): Function to start a job if an event
matches.
(job_stop_event): Function to stop a job if an event matches.
(job_handle_event): Iterate the job list and dispatch the given event,
causing jobs to be stopped or started using the above two functions.
* init/job.h: Update.
* init/tests/test_job.c: Test the new functions.
* init/job.c (job_new): Initialise start_events and stop_events to
an empty list.
* init/job.h (Job): Add start_events and stop_events list heads.
* init/tests/test_job.c (test_new): Check the lists are initialised
correctly to the empty list.
* init/event.c (event_match): Function to check events for equality.
* init/event.h: Update.
* init/tests/test_event.c (test_match): Test function.
* init/job.c (job_change_state): Trigger the level event with the
same name as the job, with the value taken from the state.
* init/tests/test_job.c (test_change_state): Check the event
gets set to the right values as we go.
* init/Makefile.am (test_job_LDADD, test_process_LDADD): Link to
event.o now that job.c uses code from there.
* init/event.c (event_change_value): Rename event_set_value to this
as we intended in the first place; makes it more consistent with job.
Always change the value.
(event_trigger_edge): Add a high-level function to trigger an edge
event.
(event_trigger_level): And another to trigger a level event with
a given value, this inherits the "don't change it" functionality
that was in event_set_value.
* init/event.h: Update.
* init/tests/test_event.c: Test new behaviours and functions.
* init/event.c: Add simple code to keep track of events, whether
they have been recorded or not and their current value if any.
* init/event.h: Structures and prototypes.
* init/tests/test_event.c: Test cases for event code.
* init/Makefile.am (init_SOURCES): Build and link event.c using event.h
(TESTS): Run the event test suite.
(test_event_SOURCES, test_event_LDFLAGS, test_event_LDADD): Details
for event test suite binary.
* init/job.c (job_run_process, job_kill_process, job_kill_timer):
Downgrade error messages to warning as they're not fatal.
(job_change_state): Change info message to be more regular.
* init/job.c (job_start): A very simple, but very necessary, function.
Set the goal of the given job to JOB_START and kick it off.
(job_stop): And its companion, cause a running job to be stopped.
* init/job.h: Update.
* init/tests/test_job.c: Test the functions.
* init/job.c (job_handle_child): Child handler to kick jobs into
the next state when their process dies.
* init/job.h: Update.
* init/tests/test_job.c (test_handle_child): Test the handler
directly by just invoking it with various job states.
2006-08-14 Scott James Remnant <scott@netsplit.com>
* init/tests/test_process.c (test_kill): Use select rather than
poll for consistency with other test cases.
* init/job.c (job_kill_process): Add function to send the active
process of a job the TERM signal, and then set a timer to follow
up with the KILL signal if the job doesn't get cleaned up in time.
(job_kill_timer): Timer callback to send the KILL signal; this
does the same job as the child handler and puts the job into the
next state as there's no point waiting around now.
* init/job.h: Update.
* init/tests/test_job.c (test_kill_process): Test both functions
in one test case (as one is just the bottom half of the other).
* init/tests/test_process.c (test_spawn): Use the right thing in
the test case filename and unlink it to make sure.
* init/job.c (job_change_state): Write the principal state gate
function, called once a state has been left to enter the given new
state (which one should determine with job_next_state). Spawns
the necessary processes or moves to the next appropriate state.
* init/job.h: Update.
* init/tests/test_job.c: Test the state changes.
* init/job.c (job_run_process): Internal function to call
process_spawn and update the job structure.
(job_run_command): Simple(ish) wrapper for the above to split
a command by whitespace, or use a shell if it needs more complex
argument processing.
(job_run_script): More complex wrapper that uses a shell to execute
verbatim script, either using -c or a /dev/fd/NN and feeding the
shell down a pipe to it.
* init/job.h: Update.
* init/tests/test_job.c: Test the new functions.
* init/Makefile.am (init_SOURCES, TESTS): Reorder so that process.c,
which is arguably lower level, comes first.
(test_job_LDADD): Link the process code.
(test_process_LDADD): Swap the order.
* TODO: Update.
* init/process.c (process_spawn): Correct typo (progress -> process),
thanks Johan.
2006-08-12 Scott James Remnant <scott@netsplit.com>
* init/process.c (process_spawn): Correct formatting of function.
* init/process.h (SHELL): Define the location of the shell, all in
the spirit of not hard-coding stuff like this.
* init/job.c (job_new): Initialise all structure members to zero
as this doesn't happen automatically.
2006-08-10 Scott James Remnant <scott@netsplit.com>
* init/job.h (job_state_name): Declare as a const function.
2006-08-09 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_next_state): State transition logic; this uses
our departure from the specification (the goal) so that the state
can always be currently accurate rather than suggestive.
(job_state_name): Cute function to convert enum into a name.
* init/job.h: Update.
* init/tests/test_job.c (test_next_state): Test the transitions.
(test_state_name): And the return values.
* TODO: Add file to keep track of things.
* init/job.c: Include nih/macros.h and nih/list.h
* init/process.c: Include order fixing, include nih/macros.h
* init/tests/test_job.c: Include nih/macros.h and nih/list.h
* init/tests/test_process.c: Include nih/list.h
* init/job.c: Include order fixing.
(job_find_by_name): Function to find a job by its (unique) name.
(job_find_by_pid): Function to find a job by the pid of its process.
* init/job.h: Update.
* init/tests/test_job.c (test_find_by_name, test_find_by_pid): Test
new functions.
* init/process.c (process_spawn): Spawn a process using the job
details to set up the environment, etc.
(process_setup_console): Set up the console according to the job.
(process_setup_limits): Set up the limits according to the job.
(process_setup_environment): Set up the environment according to
the job.
(process_kill): Simple function to send a kill signal or raise an
error; mostly just a wrapper without any particular logic.
* init/process.h: Prototypes and macros.
* init/tests/test_process.c: Test cases.
* init/Makefile.am (init_SOURCES): Build and link process.c and
its header file.
(TESTS): Run the process test suite.
(test_process_SOURCES, test_process_LDFLAGS, test_process_LDADD):
Details for process test sutie binary.
2006-08-08 Scott James Remnant <scott@netsplit.com>
* init/job.c (job_new): nih_list_free is necessary.
* init/tests/test_job.c (test_new): Free job when done.
* init/job.h: Header file to contain the definition of the Job
structure and associated typedefs, etc.
(JobGoal): In a divergence from the specification, we introduced a
"goal" for a job which tells us which way round the state machine
we're going (towards start, or towards stop).
(JobState): Which means this always holds the current state, even
if we're trying to get out of this state (ie. if we've sent the TERM
signal to the running process, we're still in the running state until
it's actually been reaped).
(ProcessState): And in another divergence, we keep the state of the
process so we know whether we need to force a state transition or
can just expect one because something transient is happening.
* init/job.c (job_new): Function to allocate a Job structure, set
the pointers to NULL and other important members to sensible
defaults.
(job_init): Initialise the list of jobs.
* init/tests/test_job.c: Test suite.
* init/Makefile.am (init_SOURCES): Compile and link job.c using
its header file.
(TESTS): Run the job test suite.
(test_job_SOURCES, test_job_LDFLAGS, test_job_LDADD): Details for the
job test suite binary.
2006-08-02 Scott James Remnant <scott@netsplit.com>
* configure.ac: Check for C99
* HACKING: Document dependency on libnih.
2006-07-27 Scott James Remnant <scott@netsplit.com>
* init/Makefile.am (DEFS): Append to the default DEFS list, rather
than overriding, otherwise we lose HAVE_CONFIG_H
2006-07-13 Scott James Remnant <scott@netsplit.com>
* HACKING: Correct incorrect Bazaar URL.
* AUTHORS: Change e-mail address to ubuntu.com.
* HACKING: Update Bazaar and Release URLS.
* configure.ac (AC_COPYRIGHT): Change copyright to Canonical Ltd.
(AC_INIT): Change bug submission address to Launchpad.
* init/main.c: Update header to use Canonical copyright and
credit me as author.
2006-05-16 Scott James Remnant <scott@netsplit.com>
* init/main.c: Add the simplest template main.c
* init/Makefile.am: Add template Makefile.am that builds init from
main.c and links to libnih statically
* configure.ac (AC_CONFIG_FILES): Configure nih and init subdirs.
* Makefile.am (SUBDIRS): Recurse into nih and init subdirs.
2006-05-14 Scott James Remnant <scott@netsplit.com>
* ChangeLog: Initial project infrastructure created.
|