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
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Hammerhead: amd64-only
SUBDIRS = $(MACH64)
include ../Makefile.subdirs
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
.KEEP_STATE:
.SUFFIXES:
SRCS += \
inj_cmds.c \
inj_decl.c \
inj_defn.c \
inj_err.c \
inj_hash.c \
inj_list.c \
inj_log.c \
inj_main.c \
inj_string.c \
inj_umem.c \
inj_util.c
PROG = fminject
ROOTPDIR = $(ROOT)/usr/lib/fm/fmd
ROOTPROG = $(ROOTPDIR)/$(PROG)
OBJS = $(SRCS:%.c=%.o) inj_grammar.o inj_lex.o
CLEANFILES += inj_grammar.c inj_grammar.h inj_lex.c y.tab.h y.tab.c
CPPFLAGS += -I. -I../common
CFLAGS += $(CCVERBOSE) $(CTF_FLAGS)
CFLAGS64 += $(CCVERBOSE) $(CTF_FLAGS_64)
CERRWARN += -Wno-switch
CERRWARN += $(CNOWARN_UNINIT)
CERRWARN += -Wno-type-limits
CERRWARN += -Wno-unused-variable
LDLIBS += -L$(ROOT)/usr/lib/fm -lfmd_log -lsysevent -lnvpair -lumem
LDFLAGS += -R/usr/lib/fm
STRIPFLAG =
# because of labels from yacc
inj_grammar.o inj_lex.o : CERRWARN += -Wno-unused-label
LFLAGS = -t -v
YFLAGS = -d
.PARALLEL: $(OBJS)
all: $(PROG)
$(PROG): $(OBJS)
$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
$(CTFMERGE) -L VERSION -o $@ $(OBJS)
$(POST_PROCESS)
inj_lex.c: ../common/inj_lex.l inj_grammar.c
$(LEX) $(LFLAGS) ../common/inj_lex.l > $@
inj_grammar.c: ../common/inj_grammar.y
$(YACC) $(YFLAGS) ../common/inj_grammar.y
$(MV) y.tab.c inj_grammar.c
$(MV) y.tab.h inj_grammar.h
%.o: %.c
$(COMPILE.c) $<
$(CTFCONVERT_O)
%.o: ../common/%.c
$(COMPILE.c) $<
$(CTFCONVERT_O)
clean:
$(RM) $(OBJS) $(LINTFILES) $(CLEANFILES)
clobber: clean
$(RM) $(PROG)
$(ROOT)/usr/lib/fm:
$(INS.dir)
$(ROOTPDIR): $(ROOT)/usr/lib/fm
$(INS.dir)
$(ROOTPDIR)/%: %
$(INS.file)
install_h:
install: all $(ROOTPDIR) $(ROOTPROG)
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# Copyright 2025 Hammerhead Project
#
# Hammerhead: Include Makefile.cmd first to load Makefile.master
# (defines COMPILE.c, COMPILE64.c needed by Makefile.com's pattern rules)
include $(SRC)/cmd/Makefile.cmd
include ../Makefile.com
include $(SRC)/cmd/Makefile.cmd.64
install: all $(ROOTPROG64)
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_H
#define _INJ_H
/*
* FMA Error injector
*/
#include <stdio.h>
#include <libnvpair.h>
#include <sys/types.h>
#include <inj_list.h>
#include <inj_hash.h>
#include <fm/fmd_log.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* The injector allows for the declaration, definition, and injection of four
* types of things - Events, FMRIs, Authorities, and lists. The first three
* are essentially lists with extra membership requirements (FMRIs, for
* example, must include a member called `scheme'). So while each has a
* different function within the FMA framework, we can use a single struct to
* store all three. The inj_itemtype_t enum is used to describe which of the
* four types is being represented by a given object.
*/
typedef enum inj_itemtype {
ITEMTYPE_EVENT,
ITEMTYPE_FMRI,
ITEMTYPE_AUTH,
ITEMTYPE_LIST
} inj_itemtype_t;
#define ITEMTYPE_NITEMS 4
/*
* The member name-value pairs of Events, FMRIs, and Authorities are typed.
*/
typedef enum inj_memtype {
MEMTYPE_UNKNOWN,
MEMTYPE_INT8,
MEMTYPE_INT16,
MEMTYPE_INT32,
MEMTYPE_INT64,
MEMTYPE_UINT8,
MEMTYPE_UINT16,
MEMTYPE_UINT32,
MEMTYPE_UINT64,
MEMTYPE_BOOL,
MEMTYPE_STRING,
MEMTYPE_ENUM,
MEMTYPE_EVENT,
MEMTYPE_FMRI,
MEMTYPE_AUTH,
MEMTYPE_LIST
} inj_memtype_t;
/*
* Declarations
*
* Each declared item, be it an event, an fmri, or an authority, consists of
* an inj_decl_t and a string of inj_declmem_t's, one of the latter for each
* declared member.
*/
#define DECL_F_AUTOENA 0x1 /* ENA member to be auto-generated for event */
typedef struct inj_decl {
inj_list_t decl_members; /* List of declared members */
inj_hash_t decl_memhash; /* Hash of said members */
const char *decl_name; /* Name of declared item */
inj_itemtype_t decl_type; /* Type of declared item */
uint_t decl_lineno; /* Line # of first member declared */
uint_t decl_flags; /* DECL_F_* */
} inj_decl_t;
#define DECLMEM_F_ARRAY 0x1 /* This member is an array of the given type */
typedef struct inj_declmem {
inj_list_t dlm_memlist; /* List of declared members */
const char *dlm_name; /* Name of this member */
inj_memtype_t dlm_type; /* Type of this member */
uint_t dlm_flags; /* DECLMEM_F_* */
uint_t dlm_arrdim; /* If arr flag set, dim of array */
union {
inj_hash_t *_dlm_enumvals; /* If enum, hash of poss. values */
inj_decl_t *_dlm_decl; /* If evt, etc., ptr to decl for same */
} _dlm_u;
} inj_declmem_t;
#define dlm_enumvals _dlm_u._dlm_enumvals
#define dlm_decl _dlm_u._dlm_decl
/*
* Definitions
*
* Each defined item consists of an inj_defn_t and a string of inj_defnmem_t's,
* one of the latter for each defined member. The inj_defn_t also contains a
* pointer to the corresponding declaration, thus allowing for correctness
* checking.
*/
typedef struct inj_defn {
inj_list_t defn_members; /* List of defined members */
const char *defn_name; /* Name of this definition */
inj_decl_t *defn_decl; /* Ptr to decl this defn instantiates */
uint_t defn_lineno; /* Line # of first member defined */
nvlist_t *defn_nvl; /* Built from validated members */
} inj_defn_t;
/*
* Embodiment of the information that we know about a given defined member at
* the time of definition. These values are assigned before the individual
* definition members are paired with their corresponding declarations, so we
* don't know whether a given IDENT is, for example, an enum or an fmri
* reference. Without these values, we wouldn't be able to distinguish between
* a quoted string and an identifier, for example, and thus would have a harder
* time with syntactic validation.
*/
typedef enum inj_defnmemtype {
DEFNMEM_IMM,
DEFNMEM_IDENT,
DEFNMEM_QSTRING,
DEFNMEM_EVENT,
DEFNMEM_FMRI,
DEFNMEM_AUTH,
DEFNMEM_ARRAY,
DEFNMEM_LIST
} inj_defnmemtype_t;
typedef struct inj_defnmem {
inj_list_t dfm_memlist; /* List of defined members */
inj_defnmemtype_t dfm_type; /* Type of this member, from parser */
uint_t dfm_lineno; /* Last line of this member's defn */
union {
const char *_dfm_str; /* String value of member */
inj_list_t _dfm_list; /* Enum, evt, auth, arr, list vals */
} _dfm_u;
} inj_defnmem_t;
#define dfm_str _dfm_u._dfm_str
#define dfm_list _dfm_u._dfm_list
/*
* Operations performed by the injector (aside from declarations and
* definitions)
*/
/* events and priorities list for the randomize command */
typedef struct inj_randelem {
struct inj_randelem *re_next;
inj_defn_t *re_event;
uint_t re_prob;
} inj_randelem_t;
/*
* Operations themselves are structured as a tree of inj_cmd_t's. Each one has
* a command type and type-specific command data. The "program" is run via
* iteration through the tree, with the injector performing the operation
* requested by a given node.
*/
typedef enum inj_cmd_type {
CMD_SEND_EVENT,
CMD_SLEEP,
CMD_REPEAT,
CMD_RANDOM
} inj_cmd_type_t;
typedef struct inj_cmd {
inj_list_t cmd_list; /* List of commands */
inj_cmd_type_t cmd_type; /* Type of this command */
union {
inj_defn_t *_cmd_event; /* If send_event, evt to send */
inj_randelem_t **_cmd_rand; /* List of evts & probs */
struct inj_cmd *_cmd_subcmd; /* If repeat, cmd to be rpt'd */
} _cmd_u;
uint_t cmd_num; /* If repeat, repeat count */
} inj_cmd_t;
#define cmd_event _cmd_u._cmd_event
#define cmd_rand _cmd_u._cmd_rand
#define cmd_subcmd _cmd_u._cmd_subcmd
/*
* We support retargetable event-delivery mechanisms. Each method implements
* a copy of the following ops vector, thus allowing us to switch mechanisms
* simply by switching the structure.
*/
typedef struct inj_mode_ops {
void *(*mo_open)(const char *); /* Init mechanism */
void (*mo_send)(void *, nvlist_t *); /* Send a single nvlist */
void (*mo_close)(void *); /* Shut down mechanism */
} inj_mode_ops_t;
extern int verbose;
extern int quiet;
extern inj_list_t *inj_logfile_read(fmd_log_t *);
extern inj_list_t *inj_program_read(const char *);
extern void inj_program_run(inj_list_t *, const inj_mode_ops_t *, void *);
extern void *inj_alloc(size_t);
extern void *inj_zalloc(size_t);
extern void inj_free(void *, size_t);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* The "program" executed by the injector consists of a tree of commands.
* Routines in this file build and execute said command tree.
*/
#include <sys/fm/protocol.h>
#include <unistd.h>
#include <inj.h>
#include <inj_event.h>
#include <inj_lex.h>
#include <inj_err.h>
/*
* Command tree construction
*/
static inj_list_t inj_cmds;
void
inj_cmds_add(inj_cmd_t *cmd)
{
inj_list_append(&inj_cmds, cmd);
}
inj_list_t *
inj_cmds_get(void)
{
return (&inj_cmds);
}
inj_randelem_t *
inj_rand_create(inj_defn_t *ev, uint_t prob)
{
inj_randelem_t *re = inj_zalloc(sizeof (inj_randelem_t));
re->re_event = ev;
re->re_prob = prob;
return (re);
}
inj_randelem_t *
inj_rand_add(inj_randelem_t *list, inj_randelem_t *new)
{
new->re_next = list;
return (new);
}
inj_cmd_t *
inj_cmd_rand(inj_randelem_t *rlist)
{
inj_randelem_t *r;
inj_cmd_t *cmd;
uint_t prob, tmpprob;
int nelems, i;
prob = 0;
for (i = 0, r = rlist; r != NULL; r = r->re_next, i++)
prob += r->re_prob;
if (prob != 100) {
yyerror("probabilities don't sum to 100\n");
return (NULL);
}
nelems = i;
cmd = inj_zalloc(sizeof (inj_cmd_t));
cmd->cmd_type = CMD_RANDOM;
cmd->cmd_num = nelems;
cmd->cmd_rand = inj_alloc(sizeof (inj_randelem_t *) * nelems);
prob = 0;
for (r = rlist, i = 0; i < nelems; i++, r = r->re_next) {
tmpprob = r->re_prob;
r->re_prob = prob;
prob += tmpprob;
cmd->cmd_rand[i] = r;
}
return (cmd);
}
inj_cmd_t *
inj_cmd_repeat(inj_cmd_t *repcmd, uint_t num)
{
inj_cmd_t *cmd = inj_zalloc(sizeof (inj_cmd_t));
cmd->cmd_type = CMD_REPEAT;
cmd->cmd_num = num;
cmd->cmd_subcmd = repcmd;
return (cmd);
}
inj_cmd_t *
inj_cmd_send(inj_defn_t *ev)
{
inj_cmd_t *cmd = inj_zalloc(sizeof (inj_cmd_t));
cmd->cmd_type = CMD_SEND_EVENT;
cmd->cmd_event = ev;
return (cmd);
}
inj_cmd_t *
inj_cmd_sleep(uint_t secs)
{
inj_cmd_t *cmd = inj_zalloc(sizeof (inj_cmd_t));
cmd->cmd_type = CMD_SLEEP;
cmd->cmd_num = secs;
return (cmd);
}
inj_cmd_t *
inj_cmd_addhrt(hrtime_t delta)
{
const char *class = "resource.fm.fmd.clock.addhrtime";
inj_cmd_t *cmd = inj_zalloc(sizeof (inj_cmd_t));
inj_defn_t *ev = inj_zalloc(sizeof (inj_defn_t));
ev->defn_name = class;
ev->defn_lineno = yylineno;
if ((errno = nvlist_alloc(&ev->defn_nvl, NV_UNIQUE_NAME, 0)) != 0)
die("failed to allocate nvl for %s event", class);
if ((errno = nvlist_add_string(ev->defn_nvl, FM_CLASS, class)) != 0 ||
(errno = nvlist_add_uint8(ev->defn_nvl, FM_VERSION, 1)) != 0 ||
(errno = nvlist_add_int64(ev->defn_nvl, "delta", delta)) != 0)
die("failed to build nvl for %s event", class);
cmd->cmd_type = CMD_SEND_EVENT;
cmd->cmd_event = ev;
return (cmd);
}
inj_cmd_t *
inj_cmd_endhrt(void)
{
return (inj_cmd_addhrt(-1LL)); /* clock underflow causes end of time */
}
static uint64_t
inj_ena(void)
{
return (((gethrtime() & ENA_FMT1_TIME_MASK) <<
ENA_FMT1_TIME_SHFT) | (FM_ENA_FMT1 & ENA_FORMAT_MASK));
}
static void
cmd_run_send(const inj_mode_ops_t *mode, void *hdl, inj_defn_t *ev)
{
if (!quiet) {
(void) printf("sending event %s ... ", ev->defn_name);
(void) fflush(stdout);
}
if ((errno = nvlist_add_boolean_value(ev->defn_nvl, "__injected",
1)) != 0)
warn("failed to add __injected to %s", ev->defn_name);
if (ev->defn_decl && (ev->defn_decl->decl_flags & DECL_F_AUTOENA) &&
(errno = nvlist_add_uint64(ev->defn_nvl, "ena", inj_ena())) != 0)
warn("failed to add ena to %s", ev->defn_name);
if (verbose) {
nvlist_print(stdout, ev->defn_nvl);
(void) printf("\n");
}
mode->mo_send(hdl, ev->defn_nvl);
if (!quiet)
(void) printf("done\n");
}
static void
cmd_run_random(const inj_mode_ops_t *mode, void *hdl, inj_cmd_t *cmd)
{
uint_t num = lrand48() % 100;
int i;
for (i = 1; i < cmd->cmd_num; i++) {
if (cmd->cmd_rand[i]->re_prob > num)
break;
}
cmd_run_send(mode, hdl, cmd->cmd_rand[i - 1]->re_event);
}
static void
cmd_run(const inj_mode_ops_t *mode, void *hdl, inj_cmd_t *cmd)
{
switch (cmd->cmd_type) {
case CMD_SEND_EVENT:
cmd_run_send(mode, hdl, cmd->cmd_event);
break;
case CMD_SLEEP:
(void) printf("sleeping for %d sec%s ... ",
cmd->cmd_num, cmd->cmd_num > 1 ? "s" : "");
(void) fflush(stdout);
(void) sleep(cmd->cmd_num);
(void) printf("done\n");
break;
case CMD_RANDOM:
cmd_run_random(mode, hdl, cmd);
break;
default:
warn("ignoring unknown command type: %d\n", cmd->cmd_type);
}
}
void
inj_program_run(inj_list_t *prog, const inj_mode_ops_t *mode, void *mode_arg)
{
void *hdl = mode->mo_open(mode_arg);
inj_cmd_t *cmd;
int i;
for (cmd = inj_list_next(prog); cmd != NULL; cmd = inj_list_next(cmd)) {
if (cmd->cmd_type == CMD_REPEAT) {
for (i = 1; i <= cmd->cmd_num; i++) {
if (verbose) {
(void) printf("(repeat %d of %d)\n",
i, cmd->cmd_num);
}
cmd_run(mode, hdl, cmd->cmd_subcmd);
}
} else
cmd_run(mode, hdl, cmd);
}
mode->mo_close(hdl);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Events, FMRIs and authorities must be declared before they can be used.
* Routines in this file, driven by the parser, create the data structures
* associated with the declarations.
*/
#include <assert.h>
#include <string.h>
#include <inj_event.h>
#include <inj_err.h>
#include <inj_lex.h>
#include <inj_list.h>
#include <inj.h>
static inj_hash_t inj_decls[ITEMTYPE_NITEMS];
static int inj_decls_initialized;
static inj_hash_t *
item2hash(inj_itemtype_t item)
{
int i;
assert(item >= 0 && item < sizeof (inj_decls) / sizeof (inj_hash_t));
if (!inj_decls_initialized) {
for (i = 0; i < sizeof (inj_decls) / sizeof (inj_hash_t); i++)
inj_strhash_create(&inj_decls[i]);
inj_decls_initialized = 1;
}
return (&inj_decls[item]);
}
inj_decl_t *
inj_decl_lookup(const char *name, inj_itemtype_t type)
{
inj_hash_t *hash = item2hash(type);
inj_var_t *v;
if ((v = inj_strhash_lookup(hash, name)) == NULL)
return (NULL);
return (inj_hash_get_cookie(v));
}
void
inj_decl_mem_destroy(inj_declmem_t *dlm)
{
inj_strfree(dlm->dlm_name);
if (dlm->dlm_type == MEMTYPE_ENUM)
inj_strhash_destroy(dlm->dlm_enumvals);
}
inj_declmem_t *
inj_decl_mem_create(const char *name, inj_memtype_t type)
{
inj_declmem_t *dlm = inj_zalloc(sizeof (inj_declmem_t));
dlm->dlm_name = name;
dlm->dlm_type = type;
return (dlm);
}
/* An embedded event, authority, or FMRI */
inj_declmem_t *
inj_decl_mem_create_defined(const char *name, const char *declnm,
inj_itemtype_t type)
{
inj_declmem_t *dlm = inj_zalloc(sizeof (inj_declmem_t));
dlm->dlm_name = name;
dlm->dlm_type = inj_item2mem(type);
if ((dlm->dlm_decl = inj_decl_lookup(declnm, type)) == NULL) {
yyerror("unknown %s %s", inj_item2str(type), declnm);
return (NULL);
}
return (dlm);
}
inj_declmem_t *
inj_decl_mem_create_enum(const char *name, inj_hash_t *vals)
{
inj_declmem_t *dlm = inj_zalloc(sizeof (inj_declmem_t));
dlm->dlm_name = name;
dlm->dlm_type = MEMTYPE_ENUM;
dlm->dlm_enumvals = vals;
return (dlm);
}
/* Turn a previously-declared member into an array */
void
inj_decl_mem_make_array(inj_declmem_t *dlm, uint_t dim)
{
dlm->dlm_flags |= DECLMEM_F_ARRAY;
dlm->dlm_arrdim = dim;
}
void
inj_decl_destroy(inj_decl_t *decl)
{
inj_declmem_t *m, *n;
inj_strfree(decl->decl_name);
inj_strhash_destroy(&decl->decl_memhash);
for (m = inj_list_next(&decl->decl_members); m != NULL; m = n) {
n = inj_list_next(m);
inj_decl_mem_destroy(m);
}
inj_free(decl, sizeof (inj_declmem_t));
}
inj_decl_t *
inj_decl_create(inj_declmem_t *dlm)
{
inj_decl_t *decl = inj_zalloc(sizeof (inj_decl_t));
decl->decl_lineno = yylineno;
inj_strhash_create(&decl->decl_memhash);
inj_list_append(&decl->decl_members, dlm);
(void) inj_strhash_insert(&decl->decl_memhash, dlm->dlm_name,
(uintptr_t)dlm);
return (decl);
}
void
inj_decl_addmem(inj_decl_t *decl, inj_declmem_t *dlm)
{
inj_var_t *v;
if ((v = inj_strhash_lookup(&decl->decl_memhash, dlm->dlm_name)) !=
NULL) {
inj_decl_t *other = inj_hash_get_cookie(v);
yyerror("duplicate member name %s (other on line %d)\n",
dlm->dlm_name, other->decl_lineno);
inj_decl_destroy(decl);
return;
}
inj_list_append(&decl->decl_members, dlm);
(void) inj_strhash_insert(&decl->decl_memhash, dlm->dlm_name,
(uintptr_t)dlm);
}
/*
* The various declaration types - events, FMRIs, and authorities - each have
* their own semantic validation requirements.
*/
/* No user-defined class member. If ena isn't present, we'll generate it */
static int
inj_decl_validate_event(inj_decl_t *decl)
{
if (inj_strhash_lookup(&decl->decl_memhash, "class") != NULL) {
yyerror("class may not be explicitly declared\n");
return (0);
}
if (inj_strhash_lookup(&decl->decl_memhash, "ena") == NULL)
decl->decl_flags |= DECL_F_AUTOENA;
return (1);
}
/* FMRIs must have a string scheme member */
static int
inj_decl_validate_fmri(inj_decl_t *decl)
{
inj_declmem_t *dlm;
inj_var_t *v;
if ((v = inj_strhash_lookup(&decl->decl_memhash, "scheme")) == NULL) {
yyerror("fmri declared without scheme member\n");
return (0);
}
dlm = inj_hash_get_cookie(v);
if (dlm->dlm_type != MEMTYPE_STRING) {
yyerror("scheme member must be a string\n");
return (0);
}
return (1);
}
/*ARGSUSED*/
static int
inj_decl_validate_nop(inj_decl_t *decl)
{
return (1);
}
void
inj_decl_finish(inj_decl_t *decl, const char *name, inj_itemtype_t type)
{
static int (*const validators[])(inj_decl_t *) = {
inj_decl_validate_event,
inj_decl_validate_fmri,
inj_decl_validate_nop, /* no validation for auth */
inj_decl_validate_nop /* no validation for lists */
};
inj_hash_t *hash = item2hash(type);
inj_var_t *v;
decl->decl_name = name;
decl->decl_type = type;
if (!validators[type](decl)) {
inj_decl_destroy(decl);
return;
}
if ((v = inj_strhash_lookup(hash, name)) != NULL) {
inj_decl_t *other = inj_hash_get_cookie(v);
yyerror("duplicate %s name %s (other on line %d)\n",
inj_item2str(type), name, other->decl_lineno);
inj_decl_destroy(decl);
return;
}
(void) inj_strhash_insert(hash, name, (uintptr_t)decl);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* After having been declared, events, FMRIs and authorities must be defined
* (instantiated) before they can be used as the subjects of commands.
*/
#include <sys/sysmacros.h>
#include <libnvpair.h>
#include <string.h>
#include <assert.h>
#include <inj_event.h>
#include <inj_err.h>
#include <inj_lex.h>
#include <inj_string.h>
#include <inj.h>
static inj_hash_t inj_defns[3];
static int inj_defns_initialized;
/* Intrinsics (signed and unsigned integer integer constants) */
typedef struct intr {
uchar_t ei_signed;
uchar_t ei_width;
} intr_t;
static inj_hash_t *
item2hash(inj_itemtype_t item)
{
int i;
assert(item >= 0 && item < sizeof (inj_defns) / sizeof (inj_hash_t));
if (!inj_defns_initialized) {
for (i = 0; i < sizeof (inj_defns) / sizeof (inj_hash_t); i++)
inj_strhash_create(&inj_defns[i]);
inj_defns_initialized = 1;
}
return (&inj_defns[item]);
}
inj_defn_t *
inj_defn_lookup(const char *name, inj_memtype_t type)
{
inj_hash_t *hash = item2hash(inj_mem2item(type));
inj_var_t *v;
if ((v = inj_strhash_lookup(hash, name)) == NULL)
return (NULL);
return (inj_hash_get_cookie(v));
}
static void
inj_defn_destroy_memlist(inj_defnmem_t *m)
{
inj_defnmem_t *n;
for (/* */; m != NULL; m = n) {
n = inj_list_next(m);
switch (m->dfm_type) {
case DEFNMEM_ARRAY:
case DEFNMEM_LIST:
inj_defn_destroy_memlist(inj_list_next(&m->dfm_list));
break;
default:
inj_strfree(m->dfm_str);
}
}
}
void
inj_defn_destroy(inj_defn_t *defn)
{
if (defn->defn_name != NULL)
inj_strfree(defn->defn_name);
nvlist_free(defn->defn_nvl);
inj_defn_destroy_memlist(inj_list_next(&defn->defn_members));
}
static inj_defnmem_t *
inj_defn_mem_create_common(inj_defnmemtype_t type)
{
inj_defnmem_t *dfm = inj_zalloc(sizeof (inj_defnmem_t));
dfm->dfm_type = type;
dfm->dfm_lineno = yylineno;
return (dfm);
}
inj_defnmem_t *
inj_defn_mem_create(const char *str, inj_defnmemtype_t type)
{
inj_defnmem_t *dfm = inj_defn_mem_create_common(type);
dfm->dfm_str = str;
return (dfm);
}
inj_defnmem_t *
inj_defn_mem_create_list(inj_defn_t *list, inj_defnmemtype_t type)
{
inj_defnmem_t *dfm = inj_defn_mem_create_common(type);
dfm->dfm_list = list->defn_members;
inj_free(list, sizeof (inj_defn_t));
return (dfm);
}
inj_defn_t *
inj_defn_create(inj_defnmem_t *dfm)
{
inj_defn_t *defn = inj_zalloc(sizeof (inj_defn_t));
defn->defn_lineno = yylineno;
inj_list_append(&defn->defn_members, dfm);
return (defn);
}
void
inj_defn_addmem(inj_defn_t *defn, inj_defnmem_t *dfm)
{
inj_list_append(&defn->defn_members, dfm);
}
/*
* Validate the dimensions of an array. If the declared array size was zero,
* accept (and return) whatever the definition used. If fewer cells were
* defined than were declared, return the declared size - the calling code will
* fill the remaining cells with zeros. The definition of more than the
* declared number of cells triggers an error. We print and error message in
* this case and return the declared number. This will allow processing to
* continue. The act of emitting the error will guarantee that we never
* pass from parsing to program execution.
*/
static size_t
array_dim_check(inj_declmem_t *dlm, inj_defnmem_t *dfm)
{
inj_list_t *l;
size_t dfnelems;
for (dfnelems = 0, l = inj_list_next(&dfm->dfm_list); l != NULL;
l = inj_list_next(l), dfnelems++);
if (dlm->dlm_arrdim != 0 && dlm->dlm_arrdim != dfnelems) {
yyerror(" %d: defined array has %d elements, expected %d\n",
dfm->dfm_lineno, dfnelems, dlm->dlm_arrdim);
dfnelems = dlm->dlm_arrdim;
}
return (MAX(dfnelems, dlm->dlm_arrdim));
}
/*
* The inj_defn_memcmp_* routines serve two purposes. First, they compare a
* given defined member with the corresponding declared member, signalling an
* error if the two are incompatible.
*
* Assuming that validation succeeds, an entry is added to the passed nvlist
* for the defined member.
*/
/* Used to ease signed and unsigned integer validation */
static const intr_t inj_intrinsics[] = {
{ 0, 0 }, /* MEMTYPE_UNKNOWN */
{ 1, 8 }, { 1, 16 }, { 1, 32 }, { 1, 64 },
{ 0, 8 }, { 0, 16 }, { 0, 32 }, { 0, 64 }
};
static int
inj_defn_memcmp_signed(const intr_t *intr, inj_declmem_t *dlm,
inj_defnmem_t *dfm, nvlist_t *nvl)
{
longlong_t val;
if (dfm->dfm_type != DEFNMEM_IMM && dfm->dfm_type != DEFNMEM_IDENT)
return (inj_set_errno(EINVAL));
if (inj_strtoll(dfm->dfm_str, intr->ei_width, &val) < 0)
return (-1); /* errno is set for us */
switch (dlm->dlm_type) {
case MEMTYPE_INT8:
errno = nvlist_add_int8(nvl, (char *)dlm->dlm_name,
(int8_t)val);
break;
case MEMTYPE_INT16:
errno = nvlist_add_int16(nvl, (char *)dlm->dlm_name,
(int16_t)val);
break;
case MEMTYPE_INT32:
errno = nvlist_add_int32(nvl, (char *)dlm->dlm_name,
(int32_t)val);
break;
case MEMTYPE_INT64:
errno = nvlist_add_int64(nvl, (char *)dlm->dlm_name,
(int64_t)val);
}
if (errno != 0)
die("failed to add member %s\n", dlm->dlm_name);
return (0);
}
static int
inj_defn_memcmp_unsigned(const intr_t *intr, inj_declmem_t *dlm,
inj_defnmem_t *dfm, nvlist_t *nvl)
{
u_longlong_t val;
if (dfm->dfm_type != DEFNMEM_IMM && dfm->dfm_type != DEFNMEM_IDENT)
return (inj_set_errno(EINVAL));
if (inj_strtoull(dfm->dfm_str, intr->ei_width, &val) < 0)
return (-1); /* errno is set for us */
switch (dlm->dlm_type) {
case MEMTYPE_UINT8:
errno = nvlist_add_uint8(nvl, (char *)dlm->dlm_name,
(uint8_t)val);
break;
case MEMTYPE_UINT16:
errno = nvlist_add_uint16(nvl, (char *)dlm->dlm_name,
(uint16_t)val);
break;
case MEMTYPE_UINT32:
errno = nvlist_add_uint32(nvl, (char *)dlm->dlm_name,
(uint32_t)val);
break;
case MEMTYPE_UINT64:
errno = nvlist_add_uint64(nvl, (char *)dlm->dlm_name,
(uint64_t)val);
}
if (errno != 0)
die("failed to add member %s\n", dlm->dlm_name);
return (0);
}
/* Validate an array of (un)signed integers. */
static int
inj_defn_memcmp_intr_array(const intr_t *cont, inj_declmem_t *dlm,
inj_defnmem_t *dfm, nvlist_t *nvl)
{
typedef int (*adder_t)();
static const adder_t signed_adders[] = {
NULL, nvlist_add_int8_array, nvlist_add_int16_array,
NULL, nvlist_add_int32_array, NULL, NULL, NULL,
nvlist_add_int64_array
};
static const adder_t unsigned_adders[] = {
NULL,
nvlist_add_uint8_array, nvlist_add_uint16_array,
NULL, nvlist_add_uint32_array, NULL, NULL, NULL,
nvlist_add_uint64_array
};
union {
char *a;
int8_t *a8; uint8_t *au8;
int16_t *a16; uint16_t *au16;
int32_t *a32; uint32_t *au32;
int64_t *a64; uint64_t *au64;
} a;
int (*adder)(nvlist_t *, const char *, char *, uint_t);
size_t nelems;
inj_defnmem_t *elem;
char *arrbase, *arr;
size_t arrsz;
int err = 0;
int i;
if (dfm->dfm_type != DEFNMEM_ARRAY)
return (inj_set_errno(EINVAL));
/*
* Each nvlist array adder wants an array of its own type as input,
* which is reasonable, but it complicates our general implementation.
* We fight back with casting magic.
*/
nelems = array_dim_check(dlm, dfm);
arrsz = (nelems + 1) * (cont->ei_width / NBBY);
arrbase = inj_zalloc(arrsz);
a.a = arr = (char *)P2ROUNDUP((uintptr_t)arrbase,
cont->ei_width / NBBY);
adder = (cont->ei_signed ? signed_adders :
unsigned_adders)[cont->ei_width / NBBY];
assert(adder != NULL);
for (i = 1, elem = inj_list_next(&dfm->dfm_list); elem != NULL;
elem = inj_list_next(elem), i++) {
if (elem->dfm_type != DEFNMEM_IMM &&
elem->dfm_type != DEFNMEM_IDENT) {
yyerror(" %d: array cell %d is invalid\n",
dfm->dfm_lineno, i);
err++;
continue;
}
if (cont->ei_signed) {
longlong_t val;
if (inj_strtoll(elem->dfm_str, cont->ei_width,
&val) < 0) {
yyerror(" %d: array cell %d %s\n",
dfm->dfm_lineno, i, (errno == ERANGE ?
"out of range for type" : "invalid"));
err++;
continue;
}
switch (cont->ei_width) {
case 8:
*a.a8++ = (int8_t)val;
break;
case 16:
*a.a16++ = (int16_t)val;
break;
case 32:
*a.a32++ = (int32_t)val;
break;
default:
*a.a64++ = (int64_t)val;
}
} else {
u_longlong_t val;
if (inj_strtoull(elem->dfm_str, cont->ei_width,
&val) < 0) {
yyerror(" %d: array cell %d %s\n",
dfm->dfm_lineno, i, (errno == ERANGE ?
"out of range for type" : "invalid"));
err++;
continue;
}
switch (cont->ei_width) {
case 8:
*a.au8++ = (uint8_t)val;
break;
case 16:
*a.au16++ = (uint16_t)val;
break;
case 32:
*a.au32++ = (uint32_t)val;
break;
default:
*a.au64++ = (uint64_t)val;
}
}
}
if (err == 0 && (errno = adder(nvl, dlm->dlm_name, arr, nelems)) != 0)
die("failed to add array member %s", dlm->dlm_name);
inj_free(arrbase, arrsz);
if (err != 0)
return (inj_set_errno(EINVAL));
return (0);
}
static int
bool2val(const char *str, boolean_t *valp)
{
if (strcasecmp(str, "true") == 0)
*valp = 1;
else if (strcasecmp(str, "false") == 0)
*valp = 0;
else
return (-1);
return (0);
}
static int
inj_defn_memcmp_bool(inj_declmem_t *dlm, inj_defnmem_t *dfm, nvlist_t *nvl)
{
boolean_t val;
if (dfm->dfm_type != DEFNMEM_IDENT)
return (inj_set_errno(EINVAL));
if (bool2val(dfm->dfm_str, &val) < 0)
return (inj_set_errno(EINVAL));
if ((errno = nvlist_add_boolean_value(nvl, (char *)dlm->dlm_name,
val)) != 0)
die("failed to add boolean member %s", dlm->dlm_name);
return (0);
}
static int
inj_defn_memcmp_bool_array(inj_declmem_t *dlm, inj_defnmem_t *dfm,
nvlist_t *nvl)
{
inj_defnmem_t *elem;
boolean_t *arr;
size_t nelems, arrsz;
int err = 0;
int i;
if (dfm->dfm_type != DEFNMEM_ARRAY)
return (inj_set_errno(EINVAL));
nelems = array_dim_check(dlm, dfm);
arrsz = nelems * sizeof (boolean_t);
arr = inj_zalloc(arrsz);
for (i = 0, elem = inj_list_next(&dfm->dfm_list); elem != NULL;
elem = inj_list_next(elem), i++) {
if (elem->dfm_type != DEFNMEM_IDENT) {
yyerror(" %d: array cell %d is invalid\n",
dfm->dfm_lineno, i + 1);
err++;
continue;
}
if (bool2val(elem->dfm_str, &arr[i]) < 0)
return (inj_set_errno(EINVAL));
}
if (err == 0 && (errno = nvlist_add_boolean_array(nvl,
(char *)dlm->dlm_name, arr, nelems)) != 0)
die("failed to add boolean array member %s", dlm->dlm_name);
inj_free(arr, arrsz);
return (0);
}
/* Used for both strings and enums */
static int
inj_defn_memcmp_strenum(inj_declmem_t *dlm, inj_defnmem_t *dfm, nvlist_t *nvl)
{
inj_defnmemtype_t defnmemtype = (dlm->dlm_type == MEMTYPE_ENUM ?
DEFNMEM_IDENT : DEFNMEM_QSTRING);
const char *strenum = (dlm->dlm_type == MEMTYPE_ENUM ? "enum" :
"string");
if (dfm->dfm_type != defnmemtype)
return (inj_set_errno(EINVAL));
if ((errno = nvlist_add_string(nvl, (char *)dlm->dlm_name,
(char *)dfm->dfm_str)) != 0)
die("failed to add %s member %s", strenum, dlm->dlm_name);
return (0);
}
static int
inj_defn_memcmp_strenum_array(inj_declmem_t *dlm, inj_defnmem_t *dfm,
nvlist_t *nvl)
{
inj_defnmemtype_t defnmemtype = (dlm->dlm_type == MEMTYPE_ENUM ?
DEFNMEM_IDENT : DEFNMEM_QSTRING);
const char *strenum = (dlm->dlm_type == MEMTYPE_ENUM ? "enum" :
"string");
inj_defnmem_t *elem;
size_t nelems, arrsz;
const char **arr;
int err = 0;
int i;
if (dfm->dfm_type != DEFNMEM_ARRAY)
return (inj_set_errno(EINVAL));
nelems = array_dim_check(dlm, dfm);
arrsz = nelems * sizeof (char *);
arr = inj_zalloc(arrsz);
for (i = 0, elem = inj_list_next(&dfm->dfm_list); elem != NULL;
elem = inj_list_next(elem), i++) {
if (elem->dfm_type != defnmemtype) {
yyerror(" %d: array cell %d is invalid\n",
dfm->dfm_lineno, i + 1);
err++;
continue;
}
if (dlm->dlm_type == MEMTYPE_ENUM &&
inj_strhash_lookup(dlm->dlm_enumvals, elem->dfm_str) ==
NULL) {
yyerror(" %d: invalid enum value %s\n",
dfm->dfm_lineno, elem->dfm_str);
err++;
continue;
}
arr[i] = elem->dfm_str;
}
if (err == 0 && (errno = nvlist_add_string_array(nvl,
dlm->dlm_name, (char **)arr, nelems)) != 0)
die("failed to add %s array member %s", strenum, dlm->dlm_name);
inj_free(arr, arrsz);
return (0);
}
/*
* Validator for embedded lists (events, fmris, authorities, lists, etc.).
* There are two cases to deal with here. The user could either have provided
* the name of a previously-defined list, in which case we just make a copy of
* said list for insertion into ours. Alternatively, the user could simply
* define a new list here. In that case, we recursively invoke the member
* comparator, but against the list type for the member being defined.
*/
static nvlist_t *inj_defn_validate_memlist(inj_declmem_t *, inj_defnmem_t *);
/* Embedded definition */
static nvlist_t *
inj_defn_memcmp_sub_list(inj_declmem_t *dlm, inj_defnmem_t *dfm)
{
inj_declmem_t *subdlm = inj_list_next(&dlm->dlm_decl->decl_members);
inj_defnmem_t *subdfm = inj_list_next(&dfm->dfm_list);
return (inj_defn_validate_memlist(subdlm, subdfm));
}
/* Reference to previously-defined thing */
static nvlist_t *
inj_defn_memcmp_sub_defined(inj_declmem_t *dlm, inj_defnmem_t *dfm)
{
inj_defn_t *subdefn;
nvlist_t *new;
if ((subdefn = inj_defn_lookup(dfm->dfm_str, dlm->dlm_type)) == NULL) {
yyerror(" %d: reference to undefined %s %s\n", dfm->dfm_lineno,
inj_mem2str(dlm->dlm_type), dfm->dfm_str);
(void) inj_set_errno(EINVAL);
return (NULL);
}
if (subdefn->defn_decl != dlm->dlm_decl) {
yyerror(" %d: %s %s is not a(n) %s\n", dfm->dfm_lineno,
inj_mem2str(dlm->dlm_type), dfm->dfm_str,
subdefn->defn_decl->decl_name);
(void) inj_set_errno(EINVAL);
return (NULL);
}
assert(subdefn->defn_nvl != NULL);
if ((errno = nvlist_dup(subdefn->defn_nvl, &new, 0)) != 0) {
die("failed to duplicate %s list %s",
inj_item2str(subdefn->defn_decl->decl_type), dfm->dfm_str);
}
return (new);
}
static nvlist_t *
inj_defn_memcmp_sub_makenvl(inj_declmem_t *dlm, inj_defnmem_t *dfm)
{
inj_defnmemtype_t dftype = dfm->dfm_type;
inj_memtype_t dltype = dlm->dlm_type;
nvlist_t *new = NULL;
if (dftype == DEFNMEM_LIST)
new = inj_defn_memcmp_sub_list(dlm, dfm);
else if (dftype == DEFNMEM_IDENT && (dltype == MEMTYPE_EVENT ||
dltype == MEMTYPE_FMRI || dltype == MEMTYPE_AUTH))
new = inj_defn_memcmp_sub_defined(dlm, dfm);
else
(void) inj_set_errno(EINVAL);
return (new);
}
/* A single sub-list */
static int
inj_defn_memcmp_sub(inj_declmem_t *dlm, inj_defnmem_t *dfm, nvlist_t *nvl)
{
nvlist_t *new;
if ((new = inj_defn_memcmp_sub_makenvl(dlm, dfm)) == NULL)
return (-1); /* errno is set for us */
if ((errno = nvlist_add_nvlist(nvl, (char *)dlm->dlm_name,
new)) != 0)
die("failed to add list member %s", dlm->dlm_name);
return (0);
}
/* An array of sub-lists (for example, an array of events of a given type) */
static int
inj_defn_memcmp_sub_array(inj_declmem_t *dlm, inj_defnmem_t *dfm, nvlist_t *nvl)
{
size_t nelems, arrsz;
inj_defnmem_t *elem;
nvlist_t **arr;
int err = 0;
int i;
if (dfm->dfm_type != DEFNMEM_ARRAY)
return (inj_set_errno(EINVAL));
nelems = array_dim_check(dlm, dfm);
arrsz = nelems * sizeof (char *);
arr = inj_zalloc(arrsz);
for (i = 0, elem = inj_list_next(&dfm->dfm_list); elem != NULL;
elem = inj_list_next(elem), i++) {
if ((arr[i] = inj_defn_memcmp_sub_makenvl(dlm, elem)) == NULL) {
yyerror(" %d: array cell %d is invalid\n",
elem->dfm_lineno, i + 1);
err++;
continue;
}
}
if (err == 0 && (errno = nvlist_add_nvlist_array(nvl,
(char *)dlm->dlm_name, arr, nelems)) != 0)
die("failed to add nvlist list member %s", dlm->dlm_name);
inj_free(arr, arrsz);
return (0);
}
/*
* The declaration-definition member comparator. Designed to recursive
* invocation to allow for the validation of embedded/referenced lists.
*/
nvlist_t *
inj_defn_validate_memlist(inj_declmem_t *dlm, inj_defnmem_t *dfm)
{
const intr_t *intr;
nvlist_t *nvl;
int rc, nmem, dlnmem, dfnmem;
int err = 0;
if ((errno = nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0)) != 0)
die("failed to allocate nvl for event");
for (nmem = 1; dlm != NULL && dfm != NULL;
dlm = inj_list_next(dlm), dfm = inj_list_next(dfm), nmem++) {
switch (dlm->dlm_type) {
case MEMTYPE_INT8:
case MEMTYPE_INT16:
case MEMTYPE_INT32:
case MEMTYPE_INT64:
intr = &inj_intrinsics[dlm->dlm_type];
if (dlm->dlm_flags & DECLMEM_F_ARRAY) {
rc = inj_defn_memcmp_intr_array(intr, dlm, dfm,
nvl);
} else {
rc = inj_defn_memcmp_signed(intr, dlm, dfm,
nvl);
}
break;
case MEMTYPE_UINT8:
case MEMTYPE_UINT16:
case MEMTYPE_UINT32:
case MEMTYPE_UINT64:
intr = &inj_intrinsics[dlm->dlm_type];
if (dlm->dlm_flags & DECLMEM_F_ARRAY) {
rc = inj_defn_memcmp_intr_array(intr, dlm, dfm,
nvl);
} else {
rc = inj_defn_memcmp_unsigned(intr, dlm, dfm,
nvl);
}
break;
case MEMTYPE_BOOL:
if (dlm->dlm_flags & DECLMEM_F_ARRAY)
rc = inj_defn_memcmp_bool_array(dlm, dfm, nvl);
else
rc = inj_defn_memcmp_bool(dlm, dfm, nvl);
break;
case MEMTYPE_STRING:
if (dlm->dlm_flags & DECLMEM_F_ARRAY) {
rc = inj_defn_memcmp_strenum_array(dlm, dfm,
nvl);
} else
rc = inj_defn_memcmp_strenum(dlm, dfm, nvl);
break;
case MEMTYPE_ENUM:
if (dlm->dlm_flags & DECLMEM_F_ARRAY) {
rc = inj_defn_memcmp_strenum_array(dlm, dfm,
nvl);
} else
rc = inj_defn_memcmp_strenum(dlm, dfm, nvl);
break;
case MEMTYPE_EVENT:
case MEMTYPE_FMRI:
case MEMTYPE_AUTH:
case MEMTYPE_LIST:
if (dlm->dlm_flags & DECLMEM_F_ARRAY)
rc = inj_defn_memcmp_sub_array(dlm, dfm, nvl);
else
rc = inj_defn_memcmp_sub(dlm, dfm, nvl);
break;
default:
die("unknown decl member type %d on member %s\n",
dlm->dlm_type, dlm->dlm_name);
}
if (rc < 0) {
yyerror(" %d: %s for member %s\n", dfm->dfm_lineno,
(errno == ERANGE ? "value out of range" :
"invalid value"), dlm->dlm_name);
err++;
}
}
dlnmem = dfnmem = nmem;
while (dlm != NULL) {
dlm = inj_list_next(dlm);
dlnmem++;
}
while (dfm != NULL) {
dfm = inj_list_next(dfm);
dfnmem++;
}
if (dlnmem != dfnmem) {
yyerror("%d members found, expected %d", dfnmem, dlnmem);
err++;
}
if (err > 0) {
nvlist_free(nvl);
return (NULL);
}
return (nvl);
}
/*
* The members have all been defined. Validate the members against the
* declaration, and add it to the appropriate "defined" list.
*/
void
inj_defn_finish(inj_defn_t *defn, const char *declnm, const char *name,
inj_itemtype_t type)
{
inj_decl_t *decl = inj_decl_lookup(declnm, type);
inj_hash_t *hash = item2hash(type);
inj_declmem_t *dlm;
inj_defnmem_t *dfm;
inj_var_t *v;
defn->defn_name = name;
defn->defn_decl = decl;
if (decl == NULL) {
yyerror("unknown %s type %s\n", inj_item2str(type), declnm);
inj_defn_destroy(defn);
return;
}
dlm = inj_list_next(&decl->decl_members);
dfm = inj_list_next(&defn->defn_members);
if ((defn->defn_nvl = inj_defn_validate_memlist(dlm, dfm)) == NULL) {
inj_defn_destroy(defn);
return;
}
if (type == ITEMTYPE_EVENT) {
if ((errno = nvlist_add_string(defn->defn_nvl, "class",
(char *)defn->defn_decl->decl_name)) != 0)
die("failed to add class to %s", name);
}
if ((v = inj_strhash_lookup(hash, name)) != NULL) {
inj_defn_t *other = inj_hash_get_cookie(v);
yyerror("duplicate %s name %s (other on line %d)\n",
inj_item2str(type), name, other->defn_lineno);
inj_defn_destroy(defn);
return;
}
(void) inj_strhash_insert(hash, name, (uintptr_t)defn);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Error-handling routines
*/
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <inj_err.h>
/*LINTLIBRARY*/
static const char *pname;
#pragma init(getpname)
const char *
getpname(void)
{
const char *p, *q;
if (pname != NULL)
return (pname);
if ((p = getexecname()) != NULL)
q = strrchr(p, '/');
else
q = NULL;
if (q == NULL)
pname = p;
else
pname = q + 1;
return (pname);
}
void
vwarn(const char *format, va_list alist)
{
int err = errno;
if (pname != NULL)
(void) fprintf(stderr, "%s: ", pname);
(void) vfprintf(stderr, format, alist);
if (strchr(format, '\n') == NULL)
(void) fprintf(stderr, ": %s\n", strerror(err));
}
/*PRINTFLIKE1*/
void
warn(const char *format, ...)
{
va_list alist;
va_start(alist, format);
vwarn(format, alist);
va_end(alist);
}
void
vdie(const char *format, va_list alist)
{
vwarn(format, alist);
exit(E_ERROR);
}
/*PRINTFLIKE1*/
void
die(const char *format, ...)
{
va_list alist;
va_start(alist, format);
vdie(format, alist);
va_end(alist);
}
int
inj_set_errno(int err)
{
errno = err;
return (-1);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_ERR_H
#define _INJ_ERR_H
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#ifdef __cplusplus
extern "C" {
#endif
#define E_SUCCESS 0 /* Exit status for success */
#define E_ERROR 1 /* Exit status for error */
#define E_USAGE 2 /* Exit status for usage error */
extern void vwarn(const char *, va_list);
extern void vdie(const char *, va_list);
/*PRINTFLIKE1*/
extern void warn(const char *, ...);
/*PRINTFLIKE1*/
extern void die(const char *, ...);
extern const char *getpname(void);
extern int inj_set_errno(int);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_ERR_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_EVENT_H
#define _INJ_EVENT_H
#include <inj.h>
#include <inj_string.h>
#ifdef __cplusplus
extern "C" {
#endif
extern inj_decl_t *inj_decl_create(inj_declmem_t *);
extern void inj_decl_addmem(inj_decl_t *, inj_declmem_t *);
extern void inj_decl_finish(inj_decl_t *, const char *, inj_itemtype_t);
extern void inj_decl_destroy(inj_decl_t *);
extern inj_decl_t *inj_decl_lookup(const char *, inj_itemtype_t);
extern inj_declmem_t *inj_decl_mem_create(const char *, inj_memtype_t);
extern inj_declmem_t *inj_decl_mem_create_defined(const char *, const char *,
inj_itemtype_t);
extern inj_declmem_t *inj_decl_mem_create_enum(const char *, inj_hash_t *);
extern void inj_decl_mem_destroy(inj_declmem_t *);
extern void inj_decl_mem_make_array(inj_declmem_t *, uint_t);
extern inj_defn_t *inj_defn_create(inj_defnmem_t *);
extern void inj_defn_addmem(inj_defn_t *, inj_defnmem_t *);
extern void inj_defn_finish(inj_defn_t *, const char *, const char *,
inj_itemtype_t);
extern inj_defn_t *inj_defn_lookup(const char *, inj_memtype_t);
extern inj_defnmem_t *inj_defn_mem_create(const char *, inj_defnmemtype_t);
extern inj_defnmem_t *inj_defn_mem_create_list(inj_defn_t *,
inj_defnmemtype_t);
extern const char *inj_item2str(inj_itemtype_t);
extern inj_memtype_t inj_item2mem(inj_itemtype_t);
extern const char *inj_mem2str(inj_memtype_t);
extern inj_itemtype_t inj_mem2item(inj_memtype_t);
extern inj_randelem_t *inj_rand_create(inj_defn_t *, uint_t);
extern inj_randelem_t *inj_rand_add(inj_randelem_t *, inj_randelem_t *);
extern void inj_cmds_add(inj_cmd_t *);
extern inj_list_t *inj_cmds_get(void);
extern inj_cmd_t *inj_cmd_rand(inj_randelem_t *);
extern inj_cmd_t *inj_cmd_repeat(inj_cmd_t *, uint_t);
extern inj_cmd_t *inj_cmd_send(inj_defn_t *);
extern inj_cmd_t *inj_cmd_sleep(uint_t);
extern inj_cmd_t *inj_cmd_addhrt(hrtime_t);
extern inj_cmd_t *inj_cmd_endhrt(void);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_EVENT_H */
%{
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* FMA Event Injector language parser
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <inj.h>
#include <inj_err.h>
#include <inj_event.h>
#include <inj_hash.h>
#include <inj_lex.h>
%}
%union {
inj_decl_t *l_decl;
inj_declmem_t *l_declmem;
inj_defn_t *l_defn;
inj_defnmem_t *l_defnmem;
inj_cmd_t *l_command;
inj_randelem_t *l_randelem;
inj_hash_t *l_hash;
char *l_string;
uint_t l_number;
hrtime_t l_hrtime;
}
%type <l_decl> decl_memlist
%type <l_declmem> decl_mem
%type <l_declmem> decl_baremem
%type <l_declmem> decl_mem_intr
%type <l_number> decl_intr_type
%type <l_number> decl_arraydim
%type <l_declmem> decl_mem_cplx
%type <l_hash> decl_enumlist
%type <l_defn> defn_memlist
%type <l_defnmem> defn_memvals
%type <l_defnmem> defn_val
%type <l_command> command
%type <l_command> cmd_repeatable
%type <l_randelem> rand_problist
%type <l_randelem> rand_element
%type <l_defn> defined_event
%type <l_number> number
%type <l_hrtime> hrtime
%token INJ_TOK_EVDEF
%token INJ_TOK_FMRIDEF
%token INJ_TOK_AUTHDEF
%token INJ_TOK_LISTDEF
%token INJ_TOK_INT8
%token INJ_TOK_INT16
%token INJ_TOK_INT32
%token INJ_TOK_INT64
%token INJ_TOK_UINT8
%token INJ_TOK_UINT16
%token INJ_TOK_UINT32
%token INJ_TOK_UINT64
%token INJ_TOK_BOOLEAN
%token INJ_TOK_STRING
%token INJ_TOK_ENUM
%token INJ_TOK_EVENT
%token INJ_TOK_FMRI
%token INJ_TOK_AUTH
%token INJ_TOK_LIST
%token INJ_TOK_ADDHRT
%token INJ_TOK_ENDHRT
%token INJ_TOK_SLEEP
%token INJ_TOK_REPEAT
%token INJ_TOK_RANDOMIZE
%token <l_string> INJ_TOK_IDENT
%token <l_string> INJ_TOK_FMACLASS
%token <l_string> INJ_TOK_IMM
%token <l_string> INJ_TOK_QSTRING
%%
statement_list: /* EMPTY */
| statement_list statement ';'
;
statement: decl
| defn
| command {
if ($1 != NULL)
inj_cmds_add($1);
}
;
/*
* Event, FMRI, Authority, and list declarations
*/
decl: INJ_TOK_EVDEF INJ_TOK_FMACLASS '{' decl_memlist '}' {
if ($4 != NULL)
inj_decl_finish($4, $2, ITEMTYPE_EVENT);
}
| INJ_TOK_FMRIDEF INJ_TOK_IDENT '{' decl_memlist '}' {
if ($4 != NULL)
inj_decl_finish($4, $2, ITEMTYPE_FMRI);
}
| INJ_TOK_AUTHDEF INJ_TOK_IDENT '{' decl_memlist '}' {
if ($4 != NULL)
inj_decl_finish($4, $2, ITEMTYPE_AUTH);
}
| INJ_TOK_LISTDEF INJ_TOK_IDENT '{' decl_memlist '}' {
if ($4 != NULL)
inj_decl_finish($4, $2, ITEMTYPE_LIST);
}
;
decl_memlist: /* EMPTY */ { $$ = NULL; }
| decl_memlist decl_mem ';' {
if ($2 == NULL) {
$$ = $1;
} else if ($1 == NULL) {
$$ = inj_decl_create($2);
} else {
inj_decl_addmem($1, $2);
$$ = $1;
}
}
;
decl_mem: decl_baremem
| decl_baremem decl_arraydim {
if ($1 != NULL)
inj_decl_mem_make_array($1, $2);
$$ = $1;
}
;
decl_baremem: decl_mem_intr
| decl_mem_cplx
;
decl_mem_intr: decl_intr_type INJ_TOK_IDENT {
$$ = inj_decl_mem_create($2, $1);
}
;
decl_intr_type: INJ_TOK_INT8 { $$ = MEMTYPE_INT8; }
| INJ_TOK_INT16 { $$ = MEMTYPE_INT16; }
| INJ_TOK_INT32 { $$ = MEMTYPE_INT32; }
| INJ_TOK_INT64 { $$ = MEMTYPE_INT64; }
| INJ_TOK_UINT8 { $$ = MEMTYPE_UINT8; }
| INJ_TOK_UINT16 { $$ = MEMTYPE_UINT16; }
| INJ_TOK_UINT32 { $$ = MEMTYPE_UINT32; }
| INJ_TOK_UINT64 { $$ = MEMTYPE_UINT64; }
| INJ_TOK_BOOLEAN { $$ = MEMTYPE_BOOL; }
| INJ_TOK_STRING { $$ = MEMTYPE_STRING; }
;
decl_arraydim: '[' number ']' {
$$ = $2;
}
| '[' ']' {
$$ = 0;
}
;
decl_mem_cplx: INJ_TOK_ENUM INJ_TOK_IDENT '{' decl_enumlist '}' {
$$ = inj_decl_mem_create_enum($2, $4);
}
| INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT {
$$ = inj_decl_mem_create_defined($3, $2,
ITEMTYPE_EVENT);
}
| INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT {
$$ = inj_decl_mem_create_defined($3, $2,
ITEMTYPE_FMRI);
}
| INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT {
$$ = inj_decl_mem_create_defined($3, $2,
ITEMTYPE_AUTH);
}
| INJ_TOK_LIST INJ_TOK_IDENT INJ_TOK_IDENT {
$$ = inj_decl_mem_create_defined($3, $2,
ITEMTYPE_LIST);
}
;
decl_enumlist: INJ_TOK_IDENT {
$$ = inj_zalloc(sizeof (inj_hash_t));
inj_strhash_create($$);
inj_strhash_insert($$, $1, 1);
}
| decl_enumlist ',' INJ_TOK_IDENT {
if (inj_strhash_lookup($1, $3) != NULL)
yyerror("duplicate enum value \"%s\"", $3);
else
inj_strhash_insert($1, $3, 1);
$$ = $1;
}
;
/*
* Event, FMRI, Authority, and list definitions
*/
defn: INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT '='
'{' defn_memlist '}' {
inj_defn_finish($6, $2, $3, ITEMTYPE_EVENT);
inj_strfree($2);
}
| INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT '='
'{' defn_memlist '}' {
inj_defn_finish($6, $2, $3, ITEMTYPE_FMRI);
inj_strfree($2);
}
| INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT '='
'{' defn_memlist '}' {
inj_defn_finish($6, $2, $3, ITEMTYPE_AUTH);
inj_strfree($2);
}
;
defn_memlist: defn_memvals {
$$ = inj_defn_create($1);
}
| defn_memlist ',' defn_memvals {
inj_defn_addmem($1, $3);
$$ = $1;
}
;
defn_memvals: defn_val
| INJ_TOK_EVENT INJ_TOK_FMACLASS {
$$ = inj_defn_mem_create($2, DEFNMEM_EVENT);
}
| INJ_TOK_FMRI INJ_TOK_IDENT {
$$ = inj_defn_mem_create($2, DEFNMEM_FMRI);
}
| INJ_TOK_AUTH INJ_TOK_IDENT {
$$ = inj_defn_mem_create($2, DEFNMEM_AUTH);
}
| '[' defn_memlist ']' {
$$ = inj_defn_mem_create_list($2, DEFNMEM_ARRAY);
}
| '{' defn_memlist '}' {
$$ = inj_defn_mem_create_list($2, DEFNMEM_LIST);
}
;
defn_val: INJ_TOK_IMM {
$$ = inj_defn_mem_create($1, DEFNMEM_IMM);
}
| INJ_TOK_IDENT {
$$ = inj_defn_mem_create($1, DEFNMEM_IDENT);
}
| INJ_TOK_QSTRING {
$$ = inj_defn_mem_create($1, DEFNMEM_QSTRING);
}
;
/*
* Commands
*/
command: cmd_repeatable
| INJ_TOK_ADDHRT hrtime { $$ = inj_cmd_addhrt($2); }
| INJ_TOK_ENDHRT { $$ = inj_cmd_endhrt(); }
| INJ_TOK_SLEEP number { $$ = inj_cmd_sleep($2); }
| INJ_TOK_REPEAT number cmd_repeatable {
$$ = ($3 == NULL ? NULL : inj_cmd_repeat($3, $2));
}
;
cmd_repeatable: defined_event {
$$ = ($1 == NULL ? NULL : inj_cmd_send($1));
}
| INJ_TOK_RANDOMIZE '{' rand_problist '}' {
$$ = ($3 == NULL ? NULL : inj_cmd_rand($3));
}
;
rand_problist: rand_element
| rand_problist ',' rand_element {
$$ = ($1 == NULL || $3 == NULL) ?
NULL : inj_rand_add($1, $3);
}
;
rand_element: '{' defined_event ',' number '}' {
$$ = ($2 == NULL ? NULL : inj_rand_create($2, $4));
}
;
defined_event: INJ_TOK_IDENT {
inj_defn_t *ev;
if ((ev = inj_defn_lookup($1, MEMTYPE_EVENT)) ==
NULL) {
yyerror("unknown event \"%s\"\n", $1);
$$ = NULL;
} else
$$ = ev;
}
number: INJ_TOK_IMM {
u_longlong_t val;
if (inj_strtoull($1, 32, &val) < 0) {
yyerror("invalid number");
$$ = 0;
} else
$$ = (uint32_t)val;
}
hrtime: INJ_TOK_IMM INJ_TOK_IDENT {
longlong_t val;
if (inj_strtoll($1, 64, &val) < 0 ||
inj_strtime(&val, $2) < 0) {
yyerror("invalid time");
$$ = 0;
} else
$$ = val;
}
%%
inj_list_t *
inj_program_read(const char *file)
{
if (strcmp(file, "-") == 0) {
yyin = stdin;
yyinname = "stdin";
} else {
if ((yyin = fopen(file, "r")) == NULL)
die("failed to open %s", file);
yyinname = strrchr(file, '/');
if (yyinname != NULL)
yyinname++;
else
yyinname = file;
}
yyreset();
(void) yyparse();
if (yyin != stdin)
(void) fclose(yyin);
if (yynerrors != 0) {
die("parsing failed - %d error%s\n", yynerrors,
(yynerrors > 1 ? "s" : ""));
}
return (inj_cmds_get());
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <string.h>
#include <sys/types.h>
#include <inj.h>
#include <inj_err.h>
#define INJ_HASHSZ 211
struct inj_var {
struct inj_var *v_next;
uintmax_t v_uvalue;
void *v_key;
};
void
inj_hash_create(inj_hash_t *h, ulong_t (*hfn)(void *),
int (*cfn)(void *, void *))
{
h->h_hash = inj_zalloc(sizeof (inj_var_t *) * INJ_HASHSZ);
h->h_hashsz = INJ_HASHSZ;
h->h_nelems = 0;
h->h_hashfn = hfn;
h->h_cmpfn = cfn;
}
static inj_var_t *
inj_var_alloc(void *key, uintmax_t value, inj_var_t *next)
{
inj_var_t *v = inj_alloc(sizeof (inj_var_t));
v->v_next = next;
v->v_key = key;
v->v_uvalue = value;
return (v);
}
static void
inj_var_free(inj_var_t *v, void (*freefn)(inj_var_t *, void *), void *arg)
{
if (freefn != NULL)
freefn(v, arg);
inj_free(v, sizeof (inj_var_t));
}
void
inj_hash_destroy(inj_hash_t *h, void (*freefn)(inj_var_t *, void *), void *arg)
{
inj_var_t *v, *w;
size_t i;
for (i = 0; i < h->h_hashsz; i++) {
for (v = h->h_hash[i]; v != NULL; v = w) {
w = v->v_next;
inj_var_free(v, freefn, arg);
}
}
inj_free(h->h_hash, sizeof (inj_var_t *) * INJ_HASHSZ);
}
int
inj_hash_insert(inj_hash_t *h, void *key, uintmax_t value)
{
size_t i = h->h_hashfn(key) % h->h_hashsz;
inj_var_t *v;
for (v = h->h_hash[i]; v != NULL; v = v->v_next) {
if (h->h_cmpfn(v->v_key, key) == 0)
return (-1);
}
/* not found - make a new one */
v = inj_var_alloc(key, value, h->h_hash[i]);
h->h_hash[i] = v;
h->h_nelems++;
return (0);
}
inj_var_t *
inj_hash_lookup(inj_hash_t *h, void *key)
{
size_t i = h->h_hashfn(key) % h->h_hashsz;
inj_var_t *v;
for (v = h->h_hash[i]; v != NULL; v = v->v_next) {
if (h->h_cmpfn(v->v_key, key) == 0)
return (v);
}
return (NULL);
}
void *
inj_hash_get_key(inj_var_t *v)
{
return (v->v_key);
}
uintmax_t
inj_hash_get_value(inj_var_t *v)
{
return (v->v_uvalue);
}
void *
inj_hash_get_cookie(inj_var_t *v)
{
return ((void *)(uintptr_t)v->v_uvalue);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_HASH_H
#define _INJ_HASH_H
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct inj_var inj_var_t;
typedef struct inj_hash {
inj_var_t **h_hash;
size_t h_hashsz;
size_t h_nelems;
ulong_t (*h_hashfn)(void *);
int (*h_cmpfn)(void *, void *);
void (*h_freefn)(void *, uintmax_t);
} inj_hash_t;
extern void inj_hash_create(inj_hash_t *, ulong_t (*)(void *),
int (*)(void *, void *));
extern void inj_hash_destroy(inj_hash_t *, void (*)(inj_var_t *, void *),
void *);
extern int inj_hash_insert(inj_hash_t *, void *, uintmax_t);
extern inj_var_t *inj_hash_lookup(inj_hash_t *, void *);
extern void *inj_hash_get_key(inj_var_t *);
extern uintmax_t inj_hash_get_value(inj_var_t *);
extern void *inj_hash_get_cookie(inj_var_t *);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_HASH_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_LEX_H
#define _INJ_LEX_H
#ifdef __cplusplus
extern "C" {
#endif
extern int yynerrors;
extern const char *yyinname;
extern FILE *yyin;
extern int yylineno;
/*PRINTFLIKE1*/
extern void yyerror(const char *, ...);
extern void yyreset(void);
extern int yyparse(void);
extern int yylex(void);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_LEX_H */
%{
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <inj.h>
#include <inj_lex.h>
#include <inj_string.h>
#include <inj_event.h>
#include <inj_grammar.h>
int yynerrors;
const char *yyinname;
%}
/*
* S0 is for normal input processing. SCOMMENT is used to process comments.
* We need a separate state for comments to prevent the lex regexp engine from
* overflowing its own buffers as it searches for the end of comments.
*/
%s S0 SCOMMENT
RGX_IMM_SEQ -?([0-9]+|0[xX][0-9A-Fa-f]+)
RGX_STR_SEQ ([^"\\\n]|\\[^"\n]|\\\")*
RGX_IDENT [a-zA-Z][a-zA-Z0-9\-_]*
%%
<S0>"/*" { BEGIN(SCOMMENT); }
<SCOMMENT>.|\n ; /* discard */
<SCOMMENT>"*/" { BEGIN(S0); }
<S0>evdef { return (INJ_TOK_EVDEF); }
<S0>fmridef { return (INJ_TOK_FMRIDEF); }
<S0>authdef { return (INJ_TOK_AUTHDEF); }
<S0>listdef { return (INJ_TOK_LISTDEF); }
<S0>int8_t { return (INJ_TOK_INT8); }
<S0>int16_t { return (INJ_TOK_INT16); }
<S0>int32_t { return (INJ_TOK_INT32); }
<S0>int64_t { return (INJ_TOK_INT64); }
<S0>uint8_t { return (INJ_TOK_UINT8); }
<S0>uint16_t { return (INJ_TOK_UINT16); }
<S0>uint32_t { return (INJ_TOK_UINT32); }
<S0>uint64_t { return (INJ_TOK_UINT64); }
<S0>boolean { return (INJ_TOK_BOOLEAN); }
<S0>boolean_t { return (INJ_TOK_BOOLEAN); }
<S0>string { return (INJ_TOK_STRING); }
<S0>enum { return (INJ_TOK_ENUM); }
<S0>event { return (INJ_TOK_EVENT); }
<S0>fmri { return (INJ_TOK_FMRI); }
<S0>auth { return (INJ_TOK_AUTH); }
<S0>list { return (INJ_TOK_LIST); }
<S0>addhrtime { return (INJ_TOK_ADDHRT); }
<S0>endhrtime { return (INJ_TOK_ENDHRT); }
<S0>sleep { return (INJ_TOK_SLEEP); }
<S0>repeat { return (INJ_TOK_REPEAT); }
<S0>randomize { return (INJ_TOK_RANDOMIZE); }
<S0>\"{RGX_STR_SEQ}$ { yyerror("syntax error: \" unmatched"); }
<S0>\"{RGX_STR_SEQ}\" {
/* Quoted string */
yylval.l_string = inj_strndup(yytext + 1, yyleng - 2);
return (INJ_TOK_QSTRING);
}
<S0>{RGX_IDENT}("."{RGX_IDENT})+ {
yylval.l_string = inj_strdup(yytext);
return (INJ_TOK_FMACLASS);
}
<S0>{RGX_IDENT} {
yylval.l_string = inj_strdup(yytext);
return (INJ_TOK_IDENT);
}
<S0>{RGX_IMM_SEQ} {
yylval.l_string = inj_strdup(yytext);
return (INJ_TOK_IMM);
}
<S0>[ \t\n] ; /* Ignore whitespace */
. { return (yytext[0]); }
%%
void
yyerror(const char *format, ...)
{
int err = errno;
va_list ap;
char *s;
/* Don't print the line number if the message begins with a space */
if (*format == ' ') {
(void) fprintf(stderr, "%s: ", yyinname, yylineno);
format++;
} else
(void) fprintf(stderr, "%s: %d: ", yyinname, yylineno);
va_start(ap, format);
(void) vfprintf(stderr, format, ap);
va_end(ap);
if (strchr(format, '\n') == NULL)
(void) fprintf(stderr, " near \"%s\"\n", yytext);
yynerrors++;
errno = err;
}
int
yywrap(void)
{
return (1);
}
void
yyreset(void)
{
BEGIN(S0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <inj_err.h>
#include <inj_list.h>
#include <assert.h>
#include <unistd.h>
void
inj_list_append(inj_list_t *mlp, void *new)
{
inj_list_t *p = mlp->ml_prev; /* p = tail list element */
inj_list_t *q = new; /* q = new list element */
mlp->ml_prev = q;
q->ml_prev = p;
q->ml_next = NULL;
if (p != NULL) {
assert(p->ml_next == NULL);
p->ml_next = q;
} else {
assert(mlp->ml_next == NULL);
mlp->ml_next = q;
}
}
void
inj_list_prepend(inj_list_t *mlp, void *new)
{
inj_list_t *p = new; /* p = new list element */
inj_list_t *q = mlp->ml_next; /* q = head list element */
mlp->ml_next = p;
p->ml_prev = NULL;
p->ml_next = q;
if (q != NULL) {
assert(q->ml_prev == NULL);
q->ml_prev = p;
} else {
assert(mlp->ml_prev == NULL);
mlp->ml_prev = p;
}
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_LIST_H
#define _INJ_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Simple doubly-linked list implementation. This implementation assumes that
* each element contains an embedded inj_list_t structure. An additional
* inj_list_t is used to store the head and tail pointers. The caller can
* use inj_list_prev() on the master list_t to obtain the tail element, or
* inj_list_next() to obtain the head element. The head and tail list elements
* have their previous and next pointers set to NULL, respectively.
*/
typedef struct inj_list {
struct inj_list *ml_prev; /* Link to previous list element */
struct inj_list *ml_next; /* Link to next list element */
} inj_list_t;
#define inj_list_prev(elem) ((void *)(((inj_list_t *)(elem))->ml_prev))
#define inj_list_next(elem) ((void *)(((inj_list_t *)(elem))->ml_next))
extern void inj_list_append(inj_list_t *, void *);
extern void inj_list_prepend(inj_list_t *, void *);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_LIST_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <strings.h>
#include <inj_event.h>
#include <inj_err.h>
#include <fm/fmd_log.h>
typedef struct inj_logfile {
uint64_t ilf_sec; /* timestamp seconds from previous record */
uint64_t ilf_nsec; /* timestamp nanoseconds from previous record */
int ilf_index; /* record index in log file for fake lineno */
} inj_logfile_t;
/*ARGSUSED*/
static int
inj_logfile_event(fmd_log_t *lp, const fmd_log_record_t *rp, void *data)
{
inj_cmd_t *cmd = inj_zalloc(sizeof (inj_cmd_t));
inj_defn_t *ev = inj_zalloc(sizeof (inj_defn_t));
hrtime_t rec_sec = rp->rec_sec + rp->rec_nsec / NANOSEC;
hrtime_t rec_nsec = rp->rec_nsec % NANOSEC;
inj_logfile_t *ilf = data;
hrtime_t delta;
if (ilf->ilf_index == 1)
goto add_event; /* do not try to adjust time for first record */
/*
* If the current record's time is before that of the previous record,
* advance it to the previous record time. This may occur when delays
* between capturing ENA and enqueuing a sysevent are observed.
*/
if (rec_sec < ilf->ilf_sec ||
(rec_sec == ilf->ilf_sec && rec_nsec < ilf->ilf_nsec)) {
warn("record [%d] (%s) timestamp is out of order: "
"advancing event time to %llx.%llx\n",
ilf->ilf_index, rp->rec_class, ilf->ilf_sec, ilf->ilf_nsec);
rec_sec = ilf->ilf_sec;
rec_nsec = ilf->ilf_nsec;
}
/*
* For now, compute the delta between the previous record and this one
* as a number of nanoseconds and advance the clock. If a massively
* large delay is observed (>INT64_MAX ns), we abort. This could be
* improved if necessary by sending more than one cmd_addhrt in a loop.
*/
delta = (rec_sec - ilf->ilf_sec) * NANOSEC;
delta += (hrtime_t)rec_nsec - (hrtime_t)ilf->ilf_nsec;
if (delta < 0)
die("record [%d] timestamp delta too large\n", ilf->ilf_index);
if (delta > 0)
inj_cmds_add(inj_cmd_addhrt(delta));
add_event:
ev->defn_name = inj_strdup(rp->rec_class);
ev->defn_lineno = ilf->ilf_index++;
if ((errno = nvlist_dup(rp->rec_nvl, &ev->defn_nvl, 0)) != 0)
die("failed to allocate nvl for %s event", rp->rec_class);
cmd->cmd_type = CMD_SEND_EVENT;
cmd->cmd_event = ev;
inj_cmds_add(cmd);
ilf->ilf_sec = rec_sec;
ilf->ilf_nsec = rec_nsec;
return (0);
}
inj_list_t *
inj_logfile_read(fmd_log_t *lp)
{
const char *label = fmd_log_label(lp);
inj_logfile_t ilf;
if (strcmp(label, "error") != 0)
die("cannot use '%s' log as injector input\n", label);
bzero(&ilf, sizeof (ilf));
ilf.ilf_index = 1;
if (fmd_log_iter(lp, inj_logfile_event, &ilf) != 0) {
die("failed to process log: %s\n",
fmd_log_errmsg(lp, fmd_log_errno(lp)));
}
return (inj_cmds_get());
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/sysevent/eventdefs.h>
#include <sys/fm/util.h>
#include <fm/fmd_log.h>
#include <libsysevent.h>
#include <inj.h>
#include <inj_err.h>
#include <inj_string.h>
int verbose;
int quiet;
static int
usage(void)
{
(void) fprintf(stderr, "Usage: %s [-nqv] [-c chan] [file]\n"
"\t-c specify alternate channel to use for publication\n"
"\t-n compile program but do not inject any events\n"
"\t-q enable quiet mode (silence status messages)\n"
"\t-v enable verbose output (display event details)\n",
getpname());
return (E_USAGE);
}
/*
* Sysevent-based event delivery
*/
static void *
sev_open(const char *chan)
{
evchan_t *hdl;
if (chan == NULL)
chan = FM_ERROR_CHAN;
if ((errno = sysevent_evc_bind(chan, &hdl,
EVCH_CREAT | EVCH_HOLD_PEND)) != 0)
die("can't bind to error channel %s", chan);
return (hdl);
}
static void
sev_send(void *arg, nvlist_t *msg)
{
if ((errno = sysevent_evc_publish(arg, EC_FM, ESC_FM_ERROR,
"com.sun", getpname(), msg, EVCH_SLEEP)) != 0)
warn("failed to send event");
}
static void
sev_close(void *arg)
{
(void) sysevent_evc_unbind(arg);
}
static inj_mode_ops_t sysevent_ops = {
sev_open,
sev_send,
sev_close
};
/*
* Simulated delivery
*/
/*ARGSUSED*/
static void *
sim_open(const char *arg)
{
return ((void *)1);
}
/*ARGSUSED*/
static void
sim_send(void *arg, nvlist_t *msg)
{
}
/*ARGSUSED*/
static void
sim_close(void *arg)
{
}
static inj_mode_ops_t simulate_ops = {
sim_open,
sim_send,
sim_close
};
int
main(int argc, char *argv[])
{
const inj_mode_ops_t *mode = NULL;
void *mode_arg = NULL;
int c;
const char *file;
inj_list_t *program;
fmd_log_t *lp;
while ((c = getopt(argc, argv, "c:nqv")) != EOF) {
switch (c) {
case 'c':
if (mode != NULL || mode_arg != NULL)
return (usage());
mode = &sysevent_ops;
mode_arg = optarg;
break;
case 'n':
if (mode != NULL)
return (usage());
mode = &simulate_ops;
break;
case 'q':
quiet = 1;
break;
case 'v':
verbose = 1;
break;
default:
return (usage());
}
}
if (mode == NULL)
mode = &sysevent_ops;
argc -= optind;
argv += optind;
if (argc == 0)
file = "-";
else if (argc == 1)
file = argv[0];
else
return (usage());
srand48(gethrtime());
if (argc > 0 && (lp = fmd_log_open(FMD_LOG_VERSION, file, &c)) != NULL)
program = inj_logfile_read(lp);
else
program = inj_program_read(file);
inj_program_run(program, mode, mode_arg);
return (0);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/types.h>
#include <inj.h>
#include <inj_err.h>
#include <inj_string.h>
char *
inj_strdup(const char *s)
{
char *s1 = inj_alloc(strlen(s) + 1);
(void) strcpy(s1, s);
return (s1);
}
char *
inj_strndup(const char *s, size_t n)
{
char *s2 = inj_alloc(n + 1);
(void) strncpy(s2, s, n + 1);
s2[n] = '\0';
return (s2);
}
void
inj_strfree(const char *s)
{
inj_free((void *)s, strlen(s) + 1);
}
typedef struct type_desc {
int64_t td_min;
uint64_t td_max;
} type_desc_t;
static const type_desc_t signed_types[] = {
{ 0, 0 },
{ INT8_MIN, INT8_MAX },
{ INT16_MIN, INT16_MAX },
{ 0, 0 },
{ INT32_MIN, INT32_MAX },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ INT64_MIN, INT64_MAX }
};
static const type_desc_t unsigned_types[] = {
{ 0, 0 },
{ 0, UINT8_MAX },
{ 0, UINT16_MAX },
{ 0, 0 },
{ 0, UINT32_MAX },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, UINT64_MAX }
};
int
inj_strtoll(const char *str, int width, longlong_t *valp)
{
const type_desc_t *desc;
longlong_t val;
char *c;
if (width != 0) {
assert(width / 8 < (sizeof (signed_types) /
sizeof (signed_types[0])));
desc = &signed_types[width / 8];
assert(desc->td_max != 0);
}
errno = 0;
val = strtoll(str, &c, 0);
if (*c != '\0' || errno == EINVAL)
return (inj_set_errno(EINVAL));
if (errno == ERANGE || (width != 0 && (val < desc->td_min ||
val > (longlong_t)desc->td_max)))
return (inj_set_errno(ERANGE));
if (valp != NULL)
*valp = val;
return (0);
}
int
inj_strtoull(const char *str, int width, u_longlong_t *valp)
{
const type_desc_t *desc;
u_longlong_t val;
char *c;
if (width != 0) {
assert(width / 8 < (sizeof (unsigned_types) /
sizeof (unsigned_types[0])));
desc = &unsigned_types[width / 8];
assert(desc->td_max != 0);
}
errno = 0;
val = strtoull(str, &c, 0);
if (*c != '\0' || errno == EINVAL)
return (inj_set_errno(EINVAL));
if (errno == ERANGE || (width != 0 && val > desc->td_max))
return (inj_set_errno(ERANGE));
if (valp != NULL)
*valp = val;
return (0);
}
int
inj_strtime(hrtime_t *nsp, const char *units)
{
static const struct {
const char *name;
hrtime_t mul;
} suffix[] = {
{ "ns", NANOSEC / NANOSEC },
{ "nsec", NANOSEC / NANOSEC },
{ "us", NANOSEC / MICROSEC },
{ "usec", NANOSEC / MICROSEC },
{ "ms", NANOSEC / MILLISEC },
{ "msec", NANOSEC / MILLISEC },
{ "s", NANOSEC / SEC },
{ "sec", NANOSEC / SEC },
{ "m", NANOSEC * (hrtime_t)60 },
{ "min", NANOSEC * (hrtime_t)60 },
{ "h", NANOSEC * (hrtime_t)(60 * 60) },
{ "hour", NANOSEC * (hrtime_t)(60 * 60) },
{ "d", NANOSEC * (hrtime_t)(24 * 60 * 60) },
{ "day", NANOSEC * (hrtime_t)(24 * 60 * 60) },
{ "hz", 0 },
{ NULL }
};
hrtime_t val = *nsp, mul = 1;
int i;
for (i = 0; suffix[i].name != NULL; i++) {
if (strcasecmp(suffix[i].name, units) == 0) {
mul = suffix[i].mul;
break;
}
}
if (suffix[i].name == NULL && *units != '\0')
return (inj_set_errno(EINVAL));
if (mul == 0) {
if (val != 0)
val = NANOSEC / val; /* compute val as value per sec */
} else
val *= mul;
*nsp = val;
return (0);
}
static ulong_t
inj_hashfn_string(void *key)
{
size_t g, h = 0;
char *p;
assert(key != NULL);
for (p = key; *p != '\0'; p++) {
h = (h << 4) + *p;
if ((g = (h & 0xf0000000)) != 0) {
h ^= (g >> 24);
h ^= g;
}
}
return (h);
}
static int
inj_hashcmp_string(void *k1, void *k2)
{
return (strcmp(k1, k2));
}
/*ARGSUSED*/
static void
inj_hashfree_string(inj_var_t *v, void *arg)
{
inj_strfree(inj_hash_get_key(v));
}
void
inj_strhash_create(inj_hash_t *h)
{
inj_hash_create(h, inj_hashfn_string, inj_hashcmp_string);
}
int
inj_strhash_insert(inj_hash_t *h, const char *str, uintmax_t value)
{
return (inj_hash_insert(h, (void *)inj_strdup(str), value));
}
inj_var_t *
inj_strhash_lookup(inj_hash_t *h, const char *str)
{
return (inj_hash_lookup(h, (void *)str));
}
void
inj_strhash_destroy(inj_hash_t *h)
{
inj_hash_destroy(h, inj_hashfree_string, NULL);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INJ_STRING_H
#define _INJ_STRING_H
#include <sys/types.h>
#include <inj_list.h>
#include <inj_hash.h>
#ifdef __cplusplus
extern "C" {
#endif
extern char *inj_strdup(const char *);
extern char *inj_strndup(const char *, size_t);
extern void inj_strfree(const char *);
extern int inj_strtoll(const char *, int, longlong_t *);
extern int inj_strtoull(const char *, int, u_longlong_t *);
extern int inj_strtime(hrtime_t *, const char *);
extern void inj_strhash_create(inj_hash_t *);
extern int inj_strhash_insert(inj_hash_t *, const char *, uintmax_t);
extern inj_var_t *inj_strhash_lookup(inj_hash_t *, const char *);
extern void inj_strhash_destroy(inj_hash_t *);
#ifdef __cplusplus
}
#endif
#endif /* _INJ_STRING_H */
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <umem.h>
#include <inj.h>
void *
inj_alloc(size_t sz)
{
return (umem_alloc(sz, UMEM_NOFAIL));
}
void *
inj_zalloc(size_t sz)
{
return (umem_zalloc(sz, UMEM_NOFAIL));
}
void
inj_free(void *buf, size_t sz)
{
umem_free(buf, sz);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <inj.h>
#include <inj_err.h>
#include <assert.h>
const char *
inj_item2str(inj_itemtype_t item)
{
static const char *const names[] = { "event", "fmri", "auth", "list" };
return (item >= 0 &&
item < sizeof (names) / sizeof (char *) ? names[item] : "???");
}
inj_memtype_t
inj_item2mem(inj_itemtype_t item)
{
static const inj_memtype_t mems[] = {
MEMTYPE_EVENT, MEMTYPE_FMRI, MEMTYPE_AUTH, MEMTYPE_LIST
};
assert(item >= 0 && item < sizeof (mems) / sizeof (inj_memtype_t));
return (mems[item]);
}
/*
* Convert a *subset* of inj_memtype_t's to inj_itemtype_t's.
*/
inj_itemtype_t
inj_mem2item(inj_memtype_t mem)
{
switch (mem) {
case MEMTYPE_EVENT:
return (ITEMTYPE_EVENT);
case MEMTYPE_FMRI:
return (ITEMTYPE_FMRI);
case MEMTYPE_AUTH:
return (ITEMTYPE_AUTH);
case MEMTYPE_LIST:
return (ITEMTYPE_LIST);
default:
return (-1);
}
}
const char *
inj_mem2str(inj_memtype_t mem)
{
static const char *names[] = {
"UNKNOWN",
"int8", "int16", "int32", "int64",
"uint8", "uint16", "uint32", "uint64",
"bool", "string", "enum",
"event", "fmri", "auth"
};
return (mem >= 0 &&
mem < sizeof (names) / sizeof (char *) ? names[mem] : "???");
}
|