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
|
/*
* SCCS: @(#)config.c 1.12 (98/12/11)
*
* UniSoft Ltd., London, England
*
* (C) Copyright 1996 X/Open Company Limited
*
* All rights reserved. No part of this source code may be reproduced,
* stored in a retrieval system, or transmitted, in any form or by any
* means, electronic, mechanical, photocopying, recording or otherwise,
* except as stated in the end-user licence agreement, without the prior
* permission of the copyright owners.
* A copy of the end-user licence agreement is contained in the file
* Licence which accompanies this distribution.
*
* X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
* the UK and other countries.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef lint
static char sccsid[] = "@(#)config.c 1.12 (98/12/11) TET3 release 3.3";
#endif
/************************************************************************
SCCS: @(#)config.c 1.12 98/12/11 TETware release 3.3
NAME: config.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: August 1996
DESCRIPTION:
functions which deal with configuration variables
MODIFICATIONS:
Geoff Clare, UniSoft Ltd., August 1996
Missing <string.h>.
Andrew Dingwall, UniSoft Ltd., June 1997.
added get_runtime_tsroot() to return the runtime value of
TET_TSROOT - required to support the correct operation of TET_RUN
when a remote system's test suite root directory resides on
a read-only file system
Andrew Dingwall, UniSoft Ltd., June 1998
Don't try to do a config variable exchange with a remote system
when TET_TSROOT is undefined or when remote config file is
inaccessible.
Give TET_REMnnn variables in the master configurations priority
over generic ones when performing a configuration variable exchange.
Andrew Dingwall, UniSoft Ltd., July 1998
Added support for configuration variable expansion.
Andrew Dingwall, UniSoft Ltd., December 1998
In TETware-Lite, write the local system's per-system configurations
to the temporary files instead of the master configurations.
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
# include <unistd.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "ptab.h"
#include "error.h"
#include "globals.h"
#include "ltoa.h"
#include "servlib.h"
#include "dtetlib.h"
#include "tet3_config.h"
#include "systab.h"
#include "tcc.h"
#include "dtcc.h"
#ifdef NEEDsrcFile
static char srcFile[] = __FILE__; /* file name for error reporting */
#endif
/* default config file names on each system */
static char *defcfname[] = {
"tetbuild.cfg",
"tetexec.cfg",
"tetclean.cfg",
#ifndef TET_LITE /* -START-LITE-CUT- */
"tetdist.cfg"
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
};
/* the default config file name for a particular mode */
#define DEFCFNAME(mode) (defcfname[TC_CONF_MODE(mode)])
/* config file names - these get filled in by initcfg() */
static char *cfname[sizeof defcfname / sizeof defcfname[0]];
/* the actual config file name for a particular mode */
#define CFNAME(mode) (cfname[TC_CONF_MODE(mode)])
/*
** the master configuration lists
**
** there are master lists for: build mode, execute mode, clean mode,
** the so-called distributed variables and variables specified with -v
** on the command-line
**
** for each list there is a pointer, a length and the number of entries in
** the list
**
** the per-system lists are maintained in the systab entry for each system
*/
static struct cflist mcflist[TC_NCONF_MODES + 1];
static struct cflist vopts;
/* the master config list for a particular mode */
#define MCFLIST(mode) (mcflist[TC_CONF_MODE(mode)])
/* config error counter */
static int conferrors;
#ifdef TET_LITE /* -LITE-CUT-LINE- */
/*
** file names for the temporary master config files which are passed
** to test cases via the TET_CONFIG communication variable
*/
static char *tcfname[sizeof defcfname / sizeof defcfname[0]];
#define Ntcfname (sizeof tcfname / sizeof tcfname[0])
#define TCFNAME(mode) (tcfname[TC_CONF_MODE(mode)])
#else /* -START-LITE-CUT- */
/*
** file names for the temporary master exec, distrib and command-line
** config files which are passed to XRESD in order to support tet_remexec()
*/
static char *ecfname, *dcfname, *ccfname;
#endif /* TET_LITE */ /* -END-LITE-CUT- */
/*
** names of defined distributed variables
**
** environment variables with these names on the master system are added
** to the distributed configuration
**
** note that the number and order of these variables must
** correspond to the initialisation code in initdvar()
*/
struct dvar {
char *dv_name; /* variable name */
int dv_needed; /* variable is needed on each system */
int dv_len; /* strlen(mv_name) */
char *dv_value; /* value on master system */
};
static struct dvar dvar[] = {
{ "TET_ROOT", 1 },
{ "TET_SUITE_ROOT", 0 },
{ "TET_TSROOT", 1 },
{ "TET_EXECUTE", 0 },
{ "TET_TMP_DIR", 0 },
{ "TET_RUN", 0 }
};
#define Ndvar (sizeof dvar / sizeof dvar[0])
/*
** names of variables that may appear in the master distributed configuration
** but should not be copied to the per-system distributed configurations
*/
static struct dvar mdvar[] = {
{ "TET_LOCALHOST", 0 },
{ "TET_XTI_MODE", 0 },
{ "TET_XTI_TPI", 0 }
};
#define Nmdvar (sizeof mdvar / sizeof mdvar[0])
/*
** a simple stack structure -
** used to detect configuration variable substitution loops
*/
struct cfstack {
struct cfstack *cs_last; /* pointer to the previous element */
char *cs_name; /* variable name */
};
/* static function declarations */
static void addvopts PROTOLIST((struct cflist *));
static int cfix2 PROTOLIST((int));
static int cflag2bool PROTOLIST((char *, char *));
static void checkbvar PROTOLIST((struct cflist *, int, int));
static void compat_fix PROTOLIST((void));
static void confgiveup PROTOLIST((void));
static void config_variable_dollar PROTOLIST((void));
static void cvd2 PROTOLIST((int));
static void cvd3 PROTOLIST((struct cflist *, int, int));
static void cvd4 PROTOLIST((char *));
static void config_variable_expand PROTOLIST((struct cflist *, int, int));
static char *cp2value PROTOLIST((char **, int, int, struct cfstack *));
static void cve2 PROTOLIST((char **, int, int, struct cfstack *));
static void cve3 PROTOLIST((char **, char *, char *, int, int, int *,
struct cfstack *));
static char *cve3_getvalue PROTOLIST((char *, char *, int, int,
struct cfstack *));
static char *cve3_dist PROTOLIST((char *, char *, int, int, struct cfstack *));
static char *cve3_opmode PROTOLIST((char *, char *, int, int, int,
struct cfstack *));
static void cve_error PROTOLIST((char *, int, int, char *));
static int docff2 PROTOLIST((char *, struct cflist *, char *));
static char *docffile PROTOLIST((struct cflist *, char *));
static void docfl2 PROTOLIST((struct systab *, int));
static void docfloc PROTOLIST((struct systab *));
static char **findcfg PROTOLIST((char *, struct cflist *));
static char **finddcfg PROTOLIST((char *, int));
static void fix_tet_api_compliant PROTOLIST((int));
static void fix_tet_pass_tc_name PROTOLIST((int));
static void initdvar PROTOLIST((void));
static void initmdvar PROTOLIST((void));
static int is_dist_var PROTOLIST((char *));
static int is_mdist_var PROTOLIST((char *));
static void proccfl2 PROTOLIST((char *, struct cflist *));
static void proccfline PROTOLIST((char *, struct cflist *, int, char *));
static void readmconf PROTOLIST((char *, struct cflist *));
static void reportcfg PROTOLIST((struct cflist *, int, int));
#ifndef TET_LITE /* -START-LITE-CUT- */
static void docfr2 PROTOLIST((struct systab *, struct cflist *, int));
static void docfrem PROTOLIST((struct systab *));
static void reportdcfg PROTOLIST((void));
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/************************************************************************
* *
* configuration file processing functions *
* *
************************************************************************/
/*
** initcfg() - perform initial configuration
**
** fopt is the -f command-line option
** gopt is the -g command-line option
** xopt is the -x command-line option
** cwd is tcc's initial working directory
*/
void initcfg(fopt, gopt, xopt, cwd)
char *fopt, *gopt, *xopt, *cwd;
{
static char tet_version[] =
#ifdef TET_LITE /* -LITE-CUT-LINE- */
"TET_VERSION=3.3-lite";
#else /* -START-LITE-CUT- */
"TET_VERSION=3.3";
#endif /* -END-LITE-CUT- */
char fname[MAXPATH];
TRACE5(tet_Ttcc, 2, "initcfg(): fopt = \"%s\", gopt = \"%s\", xopt = \"%s\", cwd = \"%s\"",
fopt ? fopt : "", gopt ? gopt : "", xopt ? xopt : "", cwd);
/* read in the configuration variables for each of the chosen
modes of operation */
if (tcc_modes & TCC_BUILD) {
if (gopt && *gopt)
fullpath(cwd, gopt, fname, sizeof fname, 0);
else
fullpath(tet_tsroot, DEFCFNAME(CONF_BUILD), fname,
sizeof fname, 0);
readmconf(fname, &MCFLIST(CONF_BUILD));
CFNAME(CONF_BUILD) = rstrstore(fname);
TRACE2(tet_Ttcc, 1, "build config file = %s",
CFNAME(CONF_BUILD));
}
if (tcc_modes & TCC_EXEC) {
if (xopt && *xopt)
fullpath(cwd, xopt, fname, sizeof fname, 0);
else if (tet_execute && *tet_execute) {
fullpath(tet_execute, DEFCFNAME(CONF_EXEC), fname,
sizeof fname, 0);
if (tet_eaccess(fname, 0) < 0)
fullpath(tet_tsroot, DEFCFNAME(CONF_EXEC),
fname, sizeof fname, 0);
}
else
fullpath(tet_tsroot, DEFCFNAME(CONF_EXEC), fname,
sizeof fname, 0);
readmconf(fname, &MCFLIST(CONF_EXEC));
CFNAME(CONF_EXEC) = rstrstore(fname);
TRACE2(tet_Ttcc, 1, "exec config file = %s",
CFNAME(CONF_EXEC));
}
if (tcc_modes & TCC_CLEAN) {
if (fopt && *fopt)
fullpath(cwd, fopt, fname, sizeof fname, 0);
else
fullpath(tet_tsroot, DEFCFNAME(CONF_CLEAN), fname,
sizeof fname, 0);
readmconf(fname, &MCFLIST(CONF_CLEAN));
CFNAME(CONF_CLEAN) = rstrstore(fname);
TRACE2(tet_Ttcc, 1, "clean config file = %s",
CFNAME(CONF_CLEAN));
}
if (conferrors)
confgiveup();
/*
** add in the command-line variables
** supply default TET_API_COMPLIANT and TET_PASS_TC_NAME
** add in TET_VERSION
*/
if (tcc_modes & TCC_BUILD) {
addvopts(&MCFLIST(CONF_BUILD));
fix_tet_api_compliant(CONF_BUILD);
fix_tet_pass_tc_name(CONF_BUILD);
proccfl2(tet_version, &MCFLIST(CONF_BUILD));
}
if (tcc_modes & TCC_EXEC) {
addvopts(&MCFLIST(CONF_EXEC));
fix_tet_api_compliant(CONF_EXEC);
fix_tet_pass_tc_name(CONF_EXEC);
proccfl2(tet_version, &MCFLIST(CONF_EXEC));
}
if (tcc_modes & TCC_CLEAN) {
addvopts(&MCFLIST(CONF_CLEAN));
fix_tet_api_compliant(CONF_CLEAN);
fix_tet_pass_tc_name(CONF_CLEAN);
proccfl2(tet_version, &MCFLIST(CONF_CLEAN));
}
/* fix up tet_compat */
compat_fix();
if (conferrors)
confgiveup();
TRACE1(tet_Ttcc, 2, "initcfg() RETURN");
}
/*
** readmconf() - read in a set of master configuration variables
** from a configuration file
*/
static void readmconf(fname, lp)
char *fname;
struct cflist *lp;
{
FILE *fp;
char buf[MAXPATH * 2];
register char *p;
int lcount = 0;
/* open the config file */
if ((fp = fopen(fname, "r")) == (FILE *) 0) {
error(errno, "can't open", fname);
conferrors++;
return;
}
/* process each line in turn -
** ignore blank lines and comments
** trim trailing spaces
*/
while (fgets(buf, sizeof buf, fp) != (char *) 0) {
lcount++;
for (p = buf; *p; p++)
if (*p == '\n' || *p == '#') {
*p = '\0';
break;
}
while (--p >= buf)
if (isspace(*p))
*p = '\0';
else
break;
if (p >= buf)
proccfline(buf, lp, lcount, fname);
}
(void) fclose(fp);
}
/*
** proccfline() - process a single configuration line
*/
static void proccfline(line, lp, lineno, fname)
char *line, *fname;
struct cflist *lp;
int lineno;
{
static char fmt[] =
"bad format config variable assignment at line %d in file";
char msg[sizeof fmt + LNUMSZ];
/* check the format of the config line */
if (!tet_equindex(line) || !tet_remvar(line, -1)) {
(void) sprintf(msg, fmt, lineno);
error(0, msg, fname);
conferrors++;
return;
}
/* perform common variable assignment processing */
proccfl2(line, lp);
}
/*
** proccfl2() - common config line processing
*/
static void proccfl2(line, lp)
char *line;
register struct cflist *lp;
{
register char **cp;
/* add a new value or update an existing one */
if ((cp = findcfg(line, lp)) == (char **) 0) {
RBUFCHK((char **) &lp->cf_conf, &lp->cf_lconf,
(int) ((lp->cf_nconf + 1) * sizeof *lp->cf_conf));
*(lp->cf_conf + lp->cf_nconf++) = rstrstore(line);;
}
else {
ASSERT(*cp);
if (strcmp(line, *cp)) {
TRACE2(tet_Tbuf, 6, "proccfl2(): free config line = %s",
tet_i2x(*cp));
free(*cp);
*cp = rstrstore(line);
}
}
}
/*
** addvopts() - add the command-line variables (except distributed
** variables) to a configuration variable list
**
** this function should not be called for the master distributed
** configuration list
*/
static void addvopts(lp)
struct cflist *lp;
{
register char **cp;
TRACE1(tet_Ttcc, 6, "addvopts()");
ASSERT(lp != &MCFLIST(CONF_DIST));
for (cp = vopts.cf_conf; cp < vopts.cf_conf + vopts.cf_nconf; cp++)
if (!is_mdist_var(*cp))
proccfl2(*cp, lp);
TRACE1(tet_Ttcc, 6, "addvopts() RETURN");
}
/*
** fix_tet_api_compliant() - provide a default value for TET_API_COMPLIANT
*/
static void fix_tet_api_compliant(mode)
int mode;
{
static char name[] = "TET_API_COMPLIANT";
char line[sizeof name + 6];
TRACE2(tet_Ttcc, 6, "fix_tet_api_compliant(%s)", prcfmode(mode));
ASSERT(CONF_MODE_OK(mode, mcflist));
/* return now if TET_API_COMPLIANT is already defined */
if (getmcfg(name, mode))
return;
/* here to add a default value of !TET_OUTPUT_CAPTURE */
(void) sprintf(line, "%s=%s", name,
getmcflag("TET_OUTPUT_CAPTURE", mode) ? "False" : "True");
proccfl2(line, &MCFLIST(mode));
}
/*
** fix_tet_pass_tc_name() - provide a default value for TET_PASS_TC_NAME
*/
static void fix_tet_pass_tc_name(mode)
int mode;
{
static char name[] = "TET_PASS_TC_NAME";
char line[sizeof name + 6];
TRACE2(tet_Ttcc, 6, "fix_pass_tc_name(%s)", prcfmode(mode));
ASSERT(CONF_MODE_OK(mode, mcflist));
/* return now if TET_PASS_TC_NAME is already defined */
if (getmcfg(name, mode))
return;
/* here to add a default value of TET_OUTPUT_CAPTURE */
(void) sprintf(line, "%s=%s", name,
getmcflag("TET_OUTPUT_CAPTURE", mode) ? "True" : "False");
proccfl2(line, &MCFLIST(mode));
}
/*
** compat_fix() - fix up the value of tet_compat
**
** the value of TET_COMPAT is extracted from the master config list
** for each of the selected modes of operation
*/
static void compat_fix()
{
int compat;
int conflict;
TRACE1(tet_Ttcc, 6, "compat_fix()");
/*
** get the value of TET_COMPAT from each of the master
** configurations and check for conflicts
*/
tet_compat = cfix2(CONF_BUILD);
conflict = 0;
if ((compat = cfix2(CONF_EXEC)) != 0) {
if (tet_compat && compat != tet_compat)
conflict++;
tet_compat = compat;
}
if ((compat = cfix2(CONF_CLEAN)) != 0) {
if (tet_compat && compat != tet_compat)
conflict++;
tet_compat = compat;
}
/* report a conflict if one has been detected */
if (conflict) {
error(0, "conflicting values for TET_COMPAT",
"have been specified");
conferrors++;
}
#ifndef NOTRACE
if (tet_compat)
TRACE2(tet_Tscen, 1, "running in %sTET compatibility mode",
tet_compat == COMPAT_ETET ? "E" : "D");
else
TRACE1(tet_Tscen, 1, "no compatibility mode specified");
#endif
}
/*
** cfix2() - extend the compat_fix() processing for a particular
** master configuration list
**
** return COMPAT_DTET or COMPAT_ETET if TET_COMPAT has been so
** defined, or 0 if TET_COMPAT has not been defined with a valid value
*/
static int cfix2(mode)
int mode;
{
static char compatname[] = "TET_COMPAT";
register char *p;
if ((p = getmcfg(compatname, mode)) != (char *) 0)
switch (*p) {
case 'D':
case 'd':
return(COMPAT_DTET);
case 'E':
case 'e':
return(COMPAT_ETET);
default:
error(0, compatname, "variable has ambiguous value");
conferrors++;
break;
}
return(0);
}
/*
** distcfg() - process the distributed configuration
*/
void distcfg()
{
struct dvar *dvp;
int sysid, sysmax;
char *p;
struct systab *sp;
char buf[MAXPATH + 40];
static char fmt1[] =
"%s distributed configuration variable for system %d";
static char fmt2[] =
"%s distributed configuration variable not defined for system";
#ifndef TET_LITE /* -START-LITE-CUT- */
char **cp;
struct cflist *lp;
char fname[MAXPATH];
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
TRACE1(tet_Ttcc, 2, "distcfg(): process distributed configuration");
sysmax = symax();
ASSERT_LITE(sysmax == 0);
initdvar();
/*
** if we are processing test cases on the local system,
** copy the (non-empty) defined environment variables to the
** distributed configuration for the local system
** and mark the list as set up
*/
if ((sp = syfind(0)) != (struct systab *) 0) {
for (dvp = dvar; dvp < dvar + Ndvar; dvp++) {
if (!dvp->dv_value || !*dvp->dv_value)
continue;
(void) sprintf(buf, "%s=%.*s",dvp->dv_name,
(int) sizeof buf - dvp->dv_len - 1,
dvp->dv_value);
proccfl2(buf, &CFLIST(sp, CONF_DIST));
}
SET_CFSETUP(sp, CONF_DIST);
}
#ifndef TET_LITE /* -START-LITE-CUT- */
/*
** if we need the distributed config file, read it in; then add in
** distributed variables with nnn > 0 from the tcc command line set
*/
if (sysmax > 0 || ts_needdist()) {
fullpath(tet_tsroot, DEFCFNAME(CONF_DIST), fname,
sizeof fname, 0);
readmconf(fname, &MCFLIST(CONF_DIST));
CFNAME(CONF_DIST) = rstrstore(fname);
TRACE2(tet_Ttcc, 1, "distributed config file = %s",
CFNAME(CONF_DIST));
for (cp = vopts.cf_conf; cp < vopts.cf_conf + vopts.cf_nconf; cp++)
if (is_mdist_var(*cp) && tet_remvar_sysid(*cp) != 0)
proccfl2(*cp, &MCFLIST(CONF_DIST));
}
/*
** copy the defined distributed variables to the appropriate
** per-system distributed configuration(s)
**
** if a defined distributed variable has a TET_REMnnn_ prefix:
** if nnn is one of the sysids mentioned in the chosen scenario,
** then the unadorned variable assignment is copied to the
** distributed configuration for that system
** otherwise:
** the variable assignment is copied to the distributed
** configuration for each of the sysids mentioned in the
** chosen scenario
*/
lp = &MCFLIST(CONF_DIST);
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++) {
if (!is_dist_var(*cp))
continue;
if ((sysid = tet_remvar_sysid(*cp)) > 0) {
p = tet_remvar(*cp, -1);
ASSERT(p && p != *cp);
if ((sp = syfind(sysid)) != (struct systab *) 0)
proccfl2(p, &CFLIST(sp, CONF_DIST));
continue;
}
ASSERT(sysid == -1);
for (sysid = 1; sysid <= sysmax; sysid++)
if ((sp = syfind(sysid)) != (struct systab *) 0)
proccfl2(*cp, &CFLIST(sp, CONF_DIST));
}
/* mark the destination lists as being set up */
for (sysid = 1; sysid <= sysmax; sysid++)
if ((sp = syfind(sysid)) != (struct systab *) 0)
SET_CFSETUP(sp, CONF_DIST);
/*
** perform variable expansion on the distributed configurations
** for remote systems
*/
config_variable_expand(&MCFLIST(CONF_DIST), -1, CONF_DIST);
for (sysid = 1; sysid <= sysmax; sysid++)
if ((sp = syfind(sysid)) != (struct systab *) 0)
config_variable_expand(&CFLIST(sp, CONF_DIST),
sysid, CONF_DIST);
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/*
** ensure that we have all the dist config variables that we need
** and that they refer to full path names
*/
for (sysid = 0; sysid <= sysmax; sysid++) {
if (!syfind(sysid))
continue;
for (dvp = dvar; dvp < dvar + Ndvar; dvp++) {
p = getdcfg(dvp->dv_name, sysid);
if (p && *p) {
if (sysid == 0)
ASSERT(isabspathloc(p));
else if (!isabspathrem(p)) {
(void) sprintf(buf, fmt1,
dvp->dv_name, sysid);
error(0, buf,
"is not an absolute path name");
conferrors++;
}
}
else if (dvp->dv_needed) {
(void) sprintf(buf, fmt2, dvp->dv_name);
error(0, buf, tet_i2a(sysid));
conferrors++;
}
}
}
if (conferrors)
confgiveup();
TRACE1(tet_Ttcc, 2, "distcfg() RETURN");
}
/*
** procvopt() - process a -v command-line option
**
** return 0 if successful or -1 on error
*/
int procvopt(line)
char *line;
{
/* check the format of the config line */
if (!tet_equindex(line) || !tet_remvar(line, -1)) {
error(0, "-v option is badly formatted:", line);
return(-1);
}
/* perform common variable assignment processing */
proccfl2(line, &vopts);
return(0);
}
/************************************************************************
* *
* configuration fixup and reporting functions *
* *
************************************************************************/
/*
** doconfig() - fix up all the configurations and write them to the
** journal
*/
void doconfig()
{
register struct systab *sp;
struct cflist *blp, *elp, *clp;
#ifndef TET_LITE /* -START-LITE-CUT- */
register int sysid, sysmax;
struct cflist tmp;
struct cflist *lp;
char **cp;
static char fmt[] = "TET_REM%03d_%.*s";
char buf[MAXPATH + sizeof fmt];
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
TRACE1(tet_Ttcc, 2, "doconfig(): fix up all the configurations and write them to the journal");
/*
** if we are processing on the local system, fix up the local configs
** and arrange to report the local configs to the journal;
** otherwise, arrange to report the master configs to the journal
*/
if ((sp = syfind(0)) != (struct systab *) 0) {
docfloc(sp);
blp = &CFLIST(sp, CONF_BUILD);
elp = &CFLIST(sp, CONF_EXEC);
clp = &CFLIST(sp, CONF_CLEAN);
}
else {
blp = &MCFLIST(CONF_BUILD);
elp = &MCFLIST(CONF_EXEC);
clp = &MCFLIST(CONF_CLEAN);
}
#ifndef TET_LITE /* -START-LITE-CUT- */
/* fix up the remote configs */
sysmax = symax();
for (sysid = 1; sysid <= sysmax; sysid++)
if ((sp = syfind(sysid)) != (struct systab *) 0)
docfrem(sp);
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/* give up if any of the above failed */
if (conferrors)
confgiveup();
/*
** now that all the config variable expansion is done,
** condense each occurrence of $$ to a single $
*/
config_variable_dollar();
/* report the local/master configs to the journal */
if (tcc_modes & TCC_BUILD)
reportcfg(blp, 0, CONF_BUILD);
if (tcc_modes & TCC_EXEC)
reportcfg(elp, 0, CONF_EXEC);
if (tcc_modes & TCC_CLEAN)
reportcfg(clp, 0, CONF_CLEAN);
#ifdef TET_LITE /* -LITE-CUT-LINE- */
/*
** write out the temporary config files for the local system which are
** passed to test cases via the TET_CONFIG communication variable
*/
if (
(tcc_modes & TCC_BUILD) &&
(TCFNAME(CONF_BUILD) = docffile(blp, "build")) == (char *) 0
)
conferrors++;
if (
(tcc_modes & TCC_EXEC) &&
(TCFNAME(CONF_EXEC) = docffile(elp, "exec")) == (char *) 0
)
conferrors++;
if (
(tcc_modes & TCC_CLEAN) &&
(TCFNAME(CONF_CLEAN) = docffile(clp, "clean")) == (char *) 0
)
conferrors++;
#else /* -START-LITE-CUT- */
/* report the dist config */
if (sysmax > 0 || ts_needdist())
reportdcfg();
/* report the remote configs */
for (sysid = 1; sysid <= sysmax; sysid++) {
if ((sp = syfind(sysid)) == (struct systab *) 0)
continue;
if (tcc_modes & TCC_BUILD)
reportcfg(&CFLIST(sp, CONF_BUILD), sysid, CONF_BUILD);
if (tcc_modes & TCC_EXEC)
reportcfg(&CFLIST(sp, CONF_EXEC), sysid, CONF_EXEC);
if (tcc_modes & TCC_CLEAN)
reportcfg(&CFLIST(sp, CONF_CLEAN), sysid, CONF_CLEAN);
}
/*
** write the master exec, distributed and command-line config
** variables to temporary files for use with tet_remexec()
*/
if ((ecfname = docffile(&MCFLIST(CONF_EXEC), "master exec")) == (char *) 0)
conferrors++;
#if 0
if ((dcfname = docffile(&MCFLIST(CONF_DIST), "distributed")) == (char *) 0)
conferrors++;
#endif
tmp.cf_conf = (char **) 0;
tmp.cf_lconf = 0;
tmp.cf_nconf = 0;
for (sysid = 0; sysid <= sysmax; sysid++) {
if ((sp = syfind(sysid)) == (struct systab *) 0)
continue;
lp = &CFLIST(sp, CONF_DIST);
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++) {
if (!*cp)
continue;
(void) sprintf(buf, fmt, sysid % 1000,
(int) (sizeof buf - sizeof fmt), *cp);
RBUFCHK((char **) &tmp.cf_conf, &tmp.cf_lconf,
(int) ((tmp.cf_nconf + 1) * sizeof *tmp.cf_conf));
*(tmp.cf_conf + tmp.cf_nconf++) = rstrstore(buf);;
}
}
if ((dcfname = docffile(&tmp, "distributed")) == (char *) 0)
conferrors++;
for (cp = tmp.cf_conf; cp < tmp.cf_conf + tmp.cf_nconf; cp++) {
TRACE2(tet_Tbuf, 6, "free tmp dist config var = %s",
tet_i2x(*cp));
free(*cp);
}
TRACE2(tet_Tbuf, 6, "free tmp dist config var list = %s",
tet_i2x(tmp.cf_conf));
free((char *) tmp.cf_conf);
if ((ccfname = docffile(&vopts, "command-line")) == (char *) 0)
conferrors++;
/* give up if any of the above failed */
if (conferrors)
confgiveup();
/* then send the file names to XRESD */
if (tet_xdcfname(ecfname, dcfname, ccfname) < 0) {
error(tet_xderrno, "can't send config file names to XRESD",
(char *) 0);
conferrors++;
}
#endif /* TET_LITE */ /* -END-LITE-CUT- */
/* give up if any of the above failed */
if (conferrors)
confgiveup();
}
/*
** docfloc() - fix up the local configs for each of the selected
** modes of operation
*/
static void docfloc(sp)
struct systab *sp;
{
TRACE1(tet_Ttcc, 2, "docfloc(): fix up all the local configurations");
if (tcc_modes & TCC_BUILD)
docfl2(sp, CONF_BUILD);
if (tcc_modes & TCC_EXEC)
docfl2(sp, CONF_EXEC);
if (tcc_modes & TCC_CLEAN)
docfl2(sp, CONF_CLEAN);
}
/*
** docfl2() - extend the docfloc() processing for a particular mode
*/
static void docfl2(sp, mode)
struct systab *sp;
int mode;
{
struct cflist *from, *to;
register char **cp;
register char *p;
TRACE2(tet_Ttcc, 3, "docfl2(): fix up the local %s configuration",
prcfmode(mode));
/*
** determine the source (master config list)
** and destination (per-system config list for the local system)
*/
ASSERT(CONF_MODE_OK(mode, sp->sy_cflist));
from = &MCFLIST(mode);
to = &CFLIST(sp, mode);
/*
** do two passes down the source list;
**
** in the first pass we add/update all the non TET_REMnnn_
** variables into the destination list
**
** in the second pass we add/update all the TET_REMnnn_
** variables for the local system into the destination list without
** the TET_REMnnn_ prefix
*/
/* first pass */
for (cp = from->cf_conf; cp < from->cf_conf + from->cf_nconf; cp++)
if (tet_remvar(*cp, -1) == *cp)
proccfl2(*cp, to);
/* second pass */
for (cp = from->cf_conf; cp < from->cf_conf + from->cf_nconf; cp++)
if ((p = tet_remvar(*cp, 0)) != *cp) {
ASSERT(p);
proccfl2(p, to);
}
/* mark the destination list as being set up */
SET_CFSETUP(sp, mode);
/* perform variable expansion if so required */
if (getcflag("TET_EXPAND_CONF_VARS", sp->sy_sysid, mode))
config_variable_expand(to, sp->sy_sysid, mode);
/* finally, check all of the boolean variables */
checkbvar(to, 0, mode);
}
#ifndef TET_LITE /* -START-LITE-CUT- */
/*
** docfrem() - fix up the remote configs for each of the selected
** modes of operation
*/
static void docfrem(sp)
struct systab *sp;
{
struct cflist tmp;
TRACE2(tet_Ttcc, 2,
"docfrem() - fix up all the configurations on system %s",
tet_i2a(sp->sy_sysid));
ASSERT(sp->sy_sysid > 0);
/* initialise the scratchpad */
tmp.cf_conf = (char **) 0;
tmp.cf_lconf = 0;
tmp.cf_nconf = 0;
/* fix up the configs for each mode */
if (tcc_modes & TCC_BUILD)
docfr2(sp, &tmp, CONF_BUILD);
if (tcc_modes & TCC_EXEC)
docfr2(sp, &tmp, CONF_EXEC);
if (tcc_modes & TCC_CLEAN)
docfr2(sp, &tmp, CONF_CLEAN);
/* free the scratchpad area */
if (tmp.cf_conf) {
TRACE2(tet_Tbuf, 6, "free tmp config list = %s",
tet_i2x(tmp.cf_conf));
free((char *) tmp.cf_conf);
}
}
/*
** docfr2() - extend the docfrem() processing for a particular mode
*/
static void docfr2(sp, tp, mode)
struct systab *sp;
struct cflist *tp;
int mode;
{
char fname[MAXPATH];
char *texec, *tsroot;
register char **cp;
struct cflist *from, *to;
static char fmt1[] = "can't access %s mode configuration file %.*s on system";
static char fmt2[] = "tet_tcxconfig() failed when performing %s mode configuration variable exchange with system";
char msg[sizeof fmt1 + MAXPATH + 6];
TRACE3(tet_Ttcc, 3,
"docfr2(): fix up the %s configuration on system %s",
prcfmode(mode), tet_i2a(sp->sy_sysid));
/*
** determine the source (master config list)
** and destination (per-system config list for this system)
*/
ASSERT(CONF_MODE_OK(mode, sp->sy_cflist));
from = &MCFLIST(mode);
to = &CFLIST(sp, mode);
/* determine the config file name on the remote system */
if ((tsroot = getdcfg("TET_TSROOT", sp->sy_sysid)) == (char *) 0) {
error(0, "TET_TSROOT not defined for system",
tet_i2a(sp->sy_sysid));
conferrors++;
return;
}
ASSERT(CONF_MODE_OK(mode, defcfname));
if (mode == CONF_EXEC &&
(texec = getdcfg("TET_EXECUTE", sp->sy_sysid)) != (char *) 0) {
fullpath(texec, DEFCFNAME(mode), fname,
sizeof fname, 1);
if (tet_tcaccess(sp->sy_sysid, fname, 0) < 0)
fullpath(tsroot, DEFCFNAME(mode), fname,
sizeof fname, 1);
}
else
fullpath(tsroot, DEFCFNAME(mode), fname, sizeof fname, 1);
/* make sure that the remote config file is accessible */
if (tcc_access(sp->sy_sysid, fname, 04) < 0) {
(void) sprintf(msg, fmt1, prcfmode(mode), MAXPATH, fname);
error(errno ? errno : tet_tcerrno, msg, tet_i2a(sp->sy_sysid));
conferrors++;
return;
}
/*
** build a list of configuration variables to send to the remote
** system which consists of all the generic variables plus all
** the TET_REMnnn variables for that system;
** the generic variables go first so as to give TET_REMnnn variables
** priority over them
*/
tp->cf_nconf = 0;
for (cp = from->cf_conf; cp < from->cf_conf + from->cf_nconf; cp++) {
if (tet_remvar(*cp, -1) != *cp)
continue;
RBUFCHK((char **) &tp->cf_conf, &tp->cf_lconf,
(int) ((tp->cf_nconf + 1) * sizeof *tp->cf_conf));
*(tp->cf_conf + tp->cf_nconf++) = *cp;
}
for (cp = from->cf_conf; cp < from->cf_conf + from->cf_nconf; cp++) {
if (tet_remvar(*cp, sp->sy_sysid) == *cp)
continue;
RBUFCHK((char **) &tp->cf_conf, &tp->cf_lconf,
(int) ((tp->cf_nconf + 1) * sizeof *tp->cf_conf));
*(tp->cf_conf + tp->cf_nconf++) = *cp;
}
/* perform a config variable exchange with the remote system */
if (tet_tcxconfig(sp->sy_sysid, fname, tp, &vopts, to) < 0) {
(void) sprintf(msg, fmt2, prcfmode(mode));
error(tet_tcerrno, msg, tet_i2a(sp->sy_sysid));
conferrors++;
}
/* mark the destination list as being set up */
SET_CFSETUP(sp, mode);
/* perform variable expansion if so required */
if (getcflag("TET_EXPAND_CONF_VARS", sp->sy_sysid, mode))
config_variable_expand(to, sp->sy_sysid, mode);
/* finally, check all of the boolean variables */
checkbvar(to, sp->sy_sysid, mode);
}
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/*
** checkbvar() - check that all the boolean variables are
** either "True" or "False" in a particular configuration
*/
static void checkbvar(lp, sysid, mode)
struct cflist *lp;
int sysid;
int mode;
{
/* list of boolean configuration variables */
static struct bvar {
char *bv_name;
int bv_len;
} bvar[] = {
{ "TET_EXEC_IN_PLACE" },
{ "TET_OUTPUT_CAPTURE" },
{ "TET_API_COMPLIANT" },
{ "TET_PASS_TC_NAME" },
{ "TET_TRANSFER_SAVE_FILES" },
{ "TET_EXPAND_CONF_VARS" }
};
#define Nbvar (sizeof bvar / sizeof bvar[0])
static char fmt[] = "bad value for boolean variable %s in %s configuration on system";
char msg[sizeof fmt + 40];
register char *p1, *p2;
register char **cp;
register struct bvar *vp;
TRACE3(tet_Ttcc, 2, "checkbvar(): check the boolean variables in the %s configuration for system %s",
prcfmode(mode), tet_i2a(sysid));
/* initialise the name lengths first time through */
if (!bvar[0].bv_len)
for (vp = bvar; vp < bvar + Nbvar; vp++)
vp->bv_len = strlen(vp->bv_name);
/*
** search the list for boolean variables and check that each one is
** either "true" or "false" (actually we only check for 't' and 'f')
*/
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++) {
if ((p1 = tet_remvar(*cp, -1)) == (char *) 0 ||
(p2 = tet_equindex(p1)) == (char *) 0)
continue;
for (vp = bvar; vp < bvar + Nbvar; vp++) {
if (vp->bv_len != p2 - p1 ||
strncmp(p1, vp->bv_name, vp->bv_len))
continue;
switch (*++p2) {
case 'T':
case 'F':
case 't':
case 'f':
break;
default:
(void) sprintf(msg, fmt, vp->bv_name,
prcfmode(mode));
error(0, msg, tet_i2a(sysid));
conferrors++;
break;
}
break;
}
}
}
/*
** reportcfg() - report a per-mode configuration to the journal
*/
static void reportcfg(lp, sysid, mode)
struct cflist *lp;
int sysid, mode;
{
char **cp;
TRACE3(tet_Ttcc, 3,
"reportcfg(): report %s mode configuration for system %s",
prcfmode(mode), tet_i2a(sysid));
ASSERT_LITE(sysid == 0);
ASSERT(mode != CONF_DIST);
/* emit the config start message */
if (sysid == 0) {
ASSERT(CONF_MODE_OK(mode, cfname));
jnl_mcfg_start(CFNAME(mode), mode);
}
#ifndef TET_LITE /* -START-LITE-CUT- */
else
jnl_scfg_start(sysid, mode);
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/* emit the config lines */
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
jnl_cfg(*cp);
/* emit the config end message */
jnl_cfg_end();
}
#ifndef TET_LITE /* -START-LITE-CUT- */
/*
** reportdcfg() - report the distributed configuration to the journal
*/
static void reportdcfg()
{
struct systab *sp;
struct cflist *lp;
char **cp;
int sysid, sysmax;
char *buf = (char *) 0;
int buflen = 0;
TRACE1(tet_Ttcc, 3,
"reportdcfg(): report the distributed configuration");
/* emit the config start message */
jnl_mcfg_start(CFNAME(CONF_DIST), CONF_DIST);
/*
** first, report all the defined distributed configuration
** variables in sysid order
*/
for (sysid = 0, sysmax = symax(); sysid <= sysmax; sysid++) {
if ((sp = syfind(sysid)) == (struct systab *) 0)
continue;
lp = &CFLIST(sp, CONF_DIST);
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++) {
RBUFCHK(&buf, &buflen, (int) strlen(*cp) + 12);
(void) sprintf(buf, "TET_REM%03d_%s",
sysid % 1000, *cp);
jnl_cfg(buf);
}
}
if (buf) {
TRACE2(tet_Tbuf, 6, "reportdcfg(): free buf = %s",
tet_i2x(buf));
free(buf);
buf = (char *) 0;
buflen = 0;
}
/*
** then, report the other variables (if any) that are in
** the master distributed configuration
*/
lp = &MCFLIST(CONF_DIST);
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
if (!is_dist_var(*cp))
jnl_cfg(*cp);
/* emit the config end message */
jnl_cfg_end();
}
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/*
** docffile() - write out a configuration to a temporary file
** and return a pointer to the file name which is stored
** in malloc'd memory
**
** return (char *) 0 on error
*/
static char *docffile(lp, type)
struct cflist *lp;
char *type;
{
char *fname;
/* get a temporary file name */
if ((fname = tet_mktfname("tcc")) == (char *) 0)
return(fname);
/* write out the variables to the file */
if (docff2(fname, lp, type) < 0) {
TRACE2(tet_Tbuf, 6, "free tmp config file name = %s",
tet_i2x(fname));
free(fname);
fname = (char *) 0;
}
return(fname);
}
/*
** docff2() - extend the docffile() processing
**
** return 0 if successful or -1 on error
*/
static int docff2(fname, lp, type)
register struct cflist *lp;
char *fname, *type;
{
register char **cp;
FILE *fp;
/* open the file */
if ((fp = fopen(fname, "w")) == (FILE *) 0) {
error(errno, "can't open", fname);
return(-1);
}
/* write out the variables */
(void) fprintf(fp, "# %s configuration variables\n\n", type);
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
if (fprintf(fp, "%s\n", *cp) < 0) {
error(errno, "write error on", fname);
(void) fclose(fp);
return(-1);
}
/* close the file */
if (fclose(fp) < 0) {
error(errno, "close error on", fname);
return(-1);
}
/* all OK so return success */
return(0);
}
/************************************************************************
* *
* configuration variable expansion *
* *
************************************************************************/
/*
** config_variable_expand() - expand variables in the specified
** configuration
**
** if a value contains a ${variable}, then the variable's value is
** interpolated
**
** a $$ in the value is left in place for now -
** later it will be condensed to a single $
**
** lp points to the configuration list to process
** if the list is for a per-system configuration, sysid is the
** system number;
** otherwise, if the list is for the distributed configuration,
** sysid should be -1
*/
static void config_variable_expand(lp, sysid, mode)
struct cflist *lp;
int sysid, mode;
{
char **cp;
#ifndef NOTRACE
if (mode == CONF_DIST && sysid < 0)
TRACE1(tet_Ttcc, 3, "config_variable_expand(): expand master distributed configuration variables");
else
TRACE3(tet_Ttcc, 3, "config_variable_expand(): expand %s mode configuration variables for system %s",
prcfmode(mode), tet_i2a(sysid));
TRACE1(tet_Ttcc, 10, "configuration list before expansion:");
if (tet_Ttcc > 0)
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
TRACE4(tet_Ttcc, 10, "\tcp = %s, *cp = %s -> \"%s\"",
tet_i2x(cp), tet_i2x(*cp),
*cp ? *cp : "<NULL>");
#endif
ASSERT_LITE(sysid == 0 || mode == CONF_DIST);
/* process each configuration variable assignment in turn */
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
cve2(cp, sysid, mode, (struct cfstack *) 0);
#ifndef NOTRACE
TRACE1(tet_Ttcc, 10, "configuration list after expansion:");
if (tet_Ttcc > 0)
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
TRACE4(tet_Ttcc, 10, "\tcp = %s, *cp = %s -> \"%s\"",
tet_i2x(cp), tet_i2x(*cp),
*cp ? *cp : "<NULL>");
TRACE1(tet_Ttcc, 3, "config_variable_expand() RETURN");
#endif
}
/*
** cve2() - extend the config_variable_expand() processing
** for a particular variable assignment
**
** this function can be called recursively -
** the stack at *stp is used to detect a configuration variable
** substitution loop
*/
#ifdef NOTRACE
# define TRACE_ENTER
# define TRACE_RETURN
#else
# define TRACE_ENTER \
level++; \
TRACE6(tet_Ttcc, 8, "cve2() ENTER at level %s, cp = %s, sysid = %s, mode = %s, assignment = \"%s\"", \
tet_i2a(level), tet_i2x(cp), tet_i2a(sysid), \
prcfmode(mode), *cp)
# define TRACE_RETURN \
TRACE2(tet_Ttcc, 8, "cve2() RETURN from level %s", tet_i2a(level)); \
--level; \
return
#endif
static void cve2(cp, sysid, mode, stp)
char **cp;
int sysid, mode;
struct cfstack *stp;
{
char *p, *s;
int syntax_errors;
static char fmt[] = "ignoring useless %.50s";
char msg[sizeof fmt + 50];
#ifndef NOTRACE
static int level;
#endif
TRACE_ENTER;
/*
** if this variable is in a distributed configuration:
**
** if it is a master distributed configuration variable:
** ignore defined distributed variables
*/
if (mode == CONF_DIST) {
if (sysid < 0) {
if (is_dist_var(*cp)) {
TRACE1(tet_Ttcc, 8, "cve2(): ignoring a defined distributed variable in the master distributed configuration");
TRACE_RETURN;
}
if (tet_remvar_sysid(*cp) >= 0) {
p = tet_equindex(*cp);
ASSERT(*p == '=');
*p = '\0';
(void) sprintf(msg, fmt, *cp);
*p = '=';
error(0, msg,
"variable assignment in the distributed configuration");
TRACE_RETURN;
}
}
else
ASSERT(tet_remvar_sysid(*cp) == -1);
}
/*
** loop until all the ${variable}s have been expanded
** but leave all the $$s in place for now
*/
syntax_errors = 0;
for (;;) {
p = tet_equindex(*cp);
ASSERT(p);
for (p += 1; *p; p++)
if (*p == '$')
if (*(p + 1) == '$')
p++;
else
break;
if (!*p)
break;
s = rstrstore(*cp);
p = tet_equindex(s);
ASSERT(p);
*p++ = '\0';
cve3(cp, s, p, sysid, mode, &syntax_errors, stp);
TRACE2(tet_Tbuf, 6, "cve2(): free config line = %s",
tet_i2x(s));
free(s);
}
TRACE_RETURN;
}
/*
** cve3() - extend the config_variable_expand() processing some more
** when the variable assignment at *cp is known to contain
** a ${variable}
**
** name and value should point to null-terminated COPIES of the original
** assignment
** these copies can get modified below here
*/
static void cve3(cp, name, value, sysid, mode, errp, stp)
char **cp, *name, *value;
int sysid, mode, *errp;
struct cfstack *stp;
{
static char badsyntax[] = "bad variable substitution syntax";
char *p, *head, *tail, *fullvar;
int buflen, len;
TRACE2(tet_Ttcc, 8, "cve3(): expand variable assignment \"%s\"", *cp);
/*
** split the value into three null-terminated parts:
** head
** variable name (fullvar)
** tail
**
** again, a $$ is left in place for now
*/
head = value;
for (p = value; *p; p++)
if (*p == '$')
if (*(p + 1) == '$')
p++;
else
break;
ASSERT(*p == '$');
*p++ = '\0';
if (*p == '{') {
fullvar = tail = ++p;
for (; *p; p++)
if (*p == '}') {
*p = '\0';
tail = p + 1;
break;
}
else if (*p == '$') {
fullvar = (char *) 0;
tail = p;
break;
}
}
else {
fullvar = (char *) 0;
tail = p;
}
/*
** here:
** fullvar points to the name of the variable to be interpolated
** or is (char *) 0 to indicate a syntax error
** head points to the part of the value before the variable name
** tail points to the part of the value after the variable name
**
** each of these strings are null-terminated
*/
/* interpolate the value and return */
if (!fullvar || !*fullvar) {
if ((*errp)++ == 0)
cve_error(name, mode, sysid, badsyntax);
p = (char *) 0;
}
else
p = cve3_getvalue(name, fullvar, sysid, mode, stp);
len = (int) (strlen(name) + strlen(head) + strlen(tail)) + 2;
if (p)
len += (int) strlen(p);
buflen = (int) strlen(*cp) + 1;
RBUFCHK(cp, &buflen, len);
(void) sprintf(*cp, "%s=%s%s%s", name, head, p ? p : "", tail);
TRACE2(tet_Ttcc, 8, "cve3(): assignment after expansion: \"%s\"", *cp);
}
/*
** cve3_getvalue() - extend the cve3 processing
**
** return pointer to the value to be interpolated,
** or (char *) 0 on error
*/
static char *cve3_getvalue(name, fullvar, sysid, mode, stp1)
char *name, *fullvar;
int sysid, mode;
struct cfstack *stp1;
{
static char subloop[] = "variable substitution loop";
static char fmt[] = "can't find a value to substitute for ${%.40s}";
char msg[sizeof fmt + 40];
struct cfstack *stp2;
char *p, *var;
int mmm;
/*
** if this is a recursive call, stp1 points to a stack containing the
** names of all the variables currently in the process of
** being interpolated
**
** check for a variable substitution loop by looking back up the
** stack to see if we are already trying to interpolate the
** current variable name
*/
for (stp2 = stp1; stp2; stp2 = stp2->cs_last)
if (!strcmp(name, stp2->cs_name)) {
cve_error(name, mode, sysid, subloop);
return((char *) 0);
}
/*
** set var to the short (unadorned) name of the variable whose value
** is to be looked up
*/
if ((mmm = tet_remvar_sysid(fullvar)) >= 0) {
var = tet_remvar(fullvar, mmm);
ASSERT(fullvar != var);
}
else {
ASSERT(mmm == -1);
var = fullvar;
}
/* look up the value of the variable that is to be interpolated */
if (mode == CONF_DIST)
p = cve3_dist(name, var, mmm, sysid, stp1);
else
p = cve3_opmode(name, var, mmm, sysid, mode, stp1);
if (!p) {
(void) sprintf(msg, fmt, fullvar);
cve_error(name, mode, sysid, msg);
}
return(p);
}
/*
** cve3_dist() - extend the config_variable_expand() processing for a
** distributed configuration variable assignment
**
** return a pointer to the value to be interpolated,
** or (char *) 0 if no value can be found
**
** variable assignment can take one of these forms:
**
** FOO=head${TET_REMmmm_BAR}tail
** FOO=head${BAR}tail
**
** TET_REMnnn_FOO variables don't appear in a per-system distributed
** configuration
** TET_REMnnn_FOO variables in the master distributed configuration
** get filtered out in cve2() above
**
** the following strategy is used:
**
** if ${fullvar} is TET_REMmmm_BAR:
** look for BAR in the distributed configuration for system mmm;
** if not found:
** look for BAR in the distributed configuration for system sysid;
** if not found:
** report an error
** otherwise:
** (${fullvar} is BAR)
** look for BAR in the distributed configuration for system sysid;
** if not found:
** report an error
*/
static char *cve3_dist(name, var, mmm, sysid, stp)
char *name, *var;
int mmm, sysid;
struct cfstack *stp;
{
struct cfstack stack;
char **cp;
int n;
/*
** make cp point to the address of the configuration variable
** assignment whose value we want to interpolate
**
** most of the work is done by finddcfg() which looks for
** var in the per-system distributed configuration first, then
** drops back to looking in the master distributed configuration
*/
if ((n = (mmm >= 0) ? mmm : sysid) >= 0)
cp = finddcfg(var, n);
else
cp = findcfg(var, &MCFLIST(CONF_DIST));
/*
** perform recursive varible expansion on the chosen variable
** and return its value
*/
stack.cs_name = name;
stack.cs_last = stp;
return(cp2value(cp, n, CONF_DIST, &stack));
}
/*
** cve3_opmode() - extend the config_variable_expand() processing for a
** build, exec or clean mode configuration variable assignment
**
** return a pointer to the value to be interpolated,
** or (char *) 0 if no value can be found
**
** variable assignment can take one of these forms:
**
** FOO=head${TET_REMmmm_BAR}tail
** FOO=head${BAR}tail
**
** (there are no TET_REMnnn_ variables in a per-system configuration)
**
** the following strategy is used:
**
** if ${fullvar} is one of the known distributed variables:
** if ${fullvar} is TET_REMmmm_BAR:
** get the value of BAR for system mmm from the
** distributed configuration;
** if not defined:
** report an error
** otherwise:
** (${fullvar} is BAR)
** get the value of BAR for system sysid from the
** distributed configuration;
** if not defined:
** report an error
** otherwise:
** (${fullvar} is not a distributed variable)
** if ${fullvar} is TET_REMmmm_BAR:
** look for BAR in the configuration for system mmm;
** if not found:
** report an error
** otherwise:
** (${fullvar} is BAR)
** look for BAR in the configuration for system sysid;
** if not found:
** report an error
*/
static char *cve3_opmode(name, var, mmm, sysid, mode, stp)
char *name, *var;
int mmm, sysid, mode;
struct cfstack *stp;
{
struct systab *sp;
struct cfstack stack;
int n;
n = (mmm >= 0) ? mmm : sysid;
/*
** if var is one of the defined distributed configuration variables,
** return its value
**
** we don't need to perform recursive variable expansion on a
** distributed configuration variable because all such variables
** have already been fully expanded
*/
if (is_dist_var(var))
return(cp2value(finddcfg(var, n), n, CONF_DIST,
(struct cfstack *) 0));
/*
** not a defined distributed configuration variable, so look for
** the variable in the configuration for the current mode
**
** perform recursive variable expansion on it before returning
** its value
*/
if ((sp = syfind(n)) == (struct systab *) 0)
return((char *) 0);
ASSERT(CONF_MODE_OK(mode, sp->sy_cflist));
stack.cs_name = name;
stack.cs_last = stp;
return(cp2value(findcfg(var, &CFLIST(sp, mode)), n, mode, &stack));
}
/*
** cp2value() - return pointer to the value part of a
** configuration variable assignment whose address is
** pointed to by cp
*/
static char *cp2value(cp, sysid, mode, stp)
char **cp;
int sysid, mode;
struct cfstack *stp;
{
char *p;
/* return now if we have been passed a NULL pointer */
if (cp == (char **) 0)
return((char *) 0);
/*
** if required, perform recursive configuration variable expansion on
** the value that we are about to return
*/
if (stp)
cve2(cp, sysid, mode, stp);
/* locate the value and return it */
p = tet_equindex(*cp);
ASSERT(p);
return(p + 1);
}
/*
** cve_error() - common error reporting function for
** configuration variable expansion errors
*/
static void cve_error(name, mode, sysid, text)
char *name, *text;
int mode, sysid;
{
static char fmt1[] = "%.80s in %.40s assignment in the %s";
static char fmt2[] = "%.14s for system %d";
static char conf[] = "configuration";
char msg1[sizeof fmt1 + 80 + 40 + 14 + LNUMSZ];
char msg2[sizeof fmt2 + 14 + LNUMSZ];
char *p;
if (mode == CONF_DIST) {
p = "Distributed";
(void) sprintf(msg2, conf);
}
else {
p = prcfmode(mode);
if (sysid < 0) {
(void) sprintf(msg2, "%s %s", p, conf);
p = "master";
}
else
(void) sprintf(msg2, fmt2, conf, sysid);
}
(void) sprintf(msg1, fmt1, text, name, p);
error(0, msg1, msg2);
conferrors++;
}
/*
** config_variable_dollar() - condense each occurrence of $$ to $
** in variable assignments
*/
static void config_variable_dollar()
{
if (tcc_modes & TCC_BUILD)
cvd2(CONF_BUILD);
if (tcc_modes & TCC_EXEC)
cvd2(CONF_EXEC);
if (tcc_modes & TCC_CLEAN)
cvd2(CONF_CLEAN);
cvd2(CONF_DIST);
}
/*
** cvd2() - extend the config_variable_dollar() processing for
** a particular mode of operation
*/
static void cvd2(mode)
int mode;
{
struct systab *sp;
int sysid, sysmax;
#ifndef TET_LITE /* -START-LITE-CUT- */
if (mode == CONF_DIST)
cvd3(&MCFLIST(CONF_DIST), -1, CONF_DIST);
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/*
** for each system in the chosen scenario:
** process the list if:
** mode is DIST and sysid > 0, or
** variable expansion is enabled
*/
for (sysid = 0, sysmax = symax(); sysid <= sysmax; sysid++)
if (
(mode != CONF_DIST || sysid > 0) &&
(sp = syfind(sysid)) != (struct systab *) 0 &&
(
mode == CONF_DIST ||
getcflag("TET_EXPAND_CONF_VARS", sysid, mode)
)
)
cvd3(&CFLIST(sp, mode), sysid, mode);
}
/*
** cvd3() - extend the config_variable_dollar() processing for
** a particular configuration list
*/
static void cvd3(lp, sysid, mode)
struct cflist *lp;
int sysid, mode;
{
char **cp;
/*
** process each variable assigment in the list
**
** entries in build, exec and clean configurations are
** always processed
**
** entries in a per-system distributed configurations are
** always processed
** (these lists contain only defined distributed variables)
**
** in the master distributed configuration, only entries that are
** not defined distributed variables are processed
*/
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
if (mode != CONF_DIST || sysid >= 0 || !is_dist_var(*cp))
cvd4(*cp);
}
/*
** cvd4() - extend the config_variable_dollar() processing
** for an individual configuration variable assignment
*/
static void cvd4(s)
char *s;
{
char *p1, *p2;
p1 = tet_equindex(s);
ASSERT(p1);
/* replace each $$ with a $ */
while (*++p1)
if (*p1 == '$') {
p2 = p1 + 1;
ASSERT(*p2 == '$');
do {
*p2 = *(p2 + 1);
} while (*++p2);
}
}
/*
** is_dist_var() - see if name is a defined distributed variable
** which may appear in a per-system distributed configuration
**
** return 1 if name is FOO or TET_REMnnn_FOO, where FOO is a
** defined distributed variable
**
** otherwise, return 0
**
** name may be delimited either by '=' or '\0'
*/
static int is_dist_var(name)
char *name;
{
struct dvar *dvp;
char *p, *shortname;
int len;
initdvar();
shortname = tet_remvar(name, -1);
ASSERT(shortname);
if ((p = tet_equindex(shortname)) == (char *) 0)
len = (int) strlen(shortname);
else
len = (int) (p - shortname);
for (dvp = dvar; dvp < dvar + Ndvar; dvp++)
if (len == dvp->dv_len &&
!strncmp(shortname, dvp->dv_name, len))
return(1);
return(0);
}
/*
** is_mdist_var() - see if name is a variable which may appear in
** the master distributed configuration
**
** return 1 if name is FOO or TET_REMnnn_FOO, where FOO is a
** distributed variable
**
** otherwise, return 0
**
** name may be delimited either by '=' or '\0'
*/
static int is_mdist_var(name)
char *name;
{
struct dvar *dvp;
char *p, *shortname;
int len;
initmdvar();
shortname = tet_remvar(name, -1);
ASSERT(shortname);
if ((p = tet_equindex(shortname)) == (char *) 0)
len = (int) strlen(shortname);
else
len = (int) (p - shortname);
for (dvp = mdvar; dvp < mdvar + Nmdvar; dvp++)
if (len == dvp->dv_len &&
!strncmp(shortname, dvp->dv_name, len))
return(1);
return(is_dist_var(shortname));
}
/************************************************************************
* *
* configuration variable lookup functions *
* *
************************************************************************/
/*
** getmcfg() - return pointer to value of config variable "name"
** in the master configuration for the specified mode
**
** return (char *) 0 if no entry appears for name
*/
char *getmcfg(name, mode)
char *name;
int mode;
{
register char **cp, *p;
mode = tcc2cfmode(mode);
ASSERT(CONF_MODE_OK(mode, mcflist));
if ((cp = findcfg(name, &MCFLIST(mode))) == (char **) 0)
p = (char *) 0;
else {
p = tet_equindex(*cp);
ASSERT(p);
p++;
}
TRACE4(tet_Ttcc, 10, "getmcfg(\"%s\", %s) returns %s",
name, prcfmode(mode), p ? p : "NULL");
return(p);
}
/*
** getcfg() - return pointer to value of config variable "name"
** in the per-system configuration for the specified mode
**
** return (char *) 0 if no entry appears for name
*/
char *getcfg(name, sysid, mode)
char *name;
int sysid, mode;
{
register char **cp, *p;
register struct systab *sp;
ASSERT_LITE(sysid == 0);
/* get the systab entry for this system */
sp = syfind(sysid);
/*
** if there is no systab entry for this system:
** if this is the local system, return the master config value;
** otherwise bail out on a programming error
*/
if (sp == (struct systab *) 0 && sysid == 0)
return(getmcfg(name, mode));
ASSERT(sp);
/* convert mode if necessary and check it */
mode = tcc2cfmode(mode);
ASSERT(CONF_MODE_OK(mode, sp->sy_cflist));
/* look up the variable in the per-system configuration */
if ((cp = findcfg(name, &CFLIST(sp, mode))) == (char **) 0)
p = (char *) 0;
else {
p = tet_equindex(*cp);
ASSERT(p);
p++;
}
TRACE5(tet_Ttcc, 10, "getcfg(\"%s\", %s, %s) returns %s",
name, tet_i2a(sysid), prcfmode(mode), p ? p : "NULL");
return(p);
}
/*
** getdcfg() - return pointer to value of config variable "name"
** in the per-system distributed configuration for sysid
**
** return (char *) 0 if no entry appears for name
**
** this function must not be called before the per-system distributed
** configurations have been set up
*/
char *getdcfg(name, sysid)
char *name;
int sysid;
{
char *p, **cp;
if ((cp = finddcfg(name, sysid)) == (char **) 0)
p = (char *) 0;
else {
p = tet_equindex(*cp);
ASSERT(p);
p++;
}
TRACE4(tet_Ttcc, 10, "getdcfg(\"%s\", %s) returns %s",
name, tet_i2a(sysid), p ? p : "NULL");
return(p);
}
/*
** putdcfg() - add/update a distributed configuration variable
** for a particular system
**
** this function must not be called before the per-system
** distributed configurations have been set up
*/
void putdcfg(name, sysid, value)
char *name, *value;
int sysid;
{
struct cflist *lp;
struct systab *sp;
char buf[MAXPATH + 40];
ASSERT_LITE(sysid == 0);
sp = syfind(sysid);
ASSERT(sp);
ASSERT(IS_CFSETUP(sp, CONF_DIST));
lp = &CFLIST(sp, CONF_DIST);
(void) sprintf(buf, "%s=%.*s", name,
(int) sizeof buf - (int) strlen(name) - 2, value);
proccfl2(buf, lp);
}
/*
** getmcflag() - get the value of a configuration variable from the
** specified master configuration list whose value can be
** True or False
**
** return 1 if the variable is set and its value is True, 0 otherwise
**
** it is assumed that all flags default to False if unset
** (currently this is the case)
*/
int getmcflag(name, mode)
char *name;
int mode;
{
register char *p;
if ((p = getmcfg(name, mode)) == (char *) 0)
return(0);
return(cflag2bool(name, p));
}
/*
** getcflag() - get the value of a configuration variable from the
** per-system configuration for the specified mode
** whose value can be True or False
**
** return 1 if the variable is set and its value is True, 0 otherwise
**
** it is assumed that all flags default to False if unset
** (currently this is the case)
*/
int getcflag(name, sysid, mode)
char *name;
int sysid, mode;
{
register char *p;
ASSERT_LITE(sysid == 0);
if ((p = getcfg(name, sysid, mode)) == (char *) 0)
return(0);
return(cflag2bool(name, p));
}
/*
** findcfg() - find a config list entry in a configuration list
** for the specified name and return a pointer to the
** entry's address
**
** name may be delimited either by '=' or '\0'
**
** return (char **) 0 if no match can be found
*/
static char **findcfg(name, lp)
char *name;
register struct cflist *lp;
{
register int len;
register char **cp, *p;
/* make len equal to the number of bytes in the name */
if ((p = tet_equindex(name)) == (char *) 0)
len = strlen(name);
else
len = p - name;
/*
** search the list for an entry whose initial part matches the
** specified name
*/
for (cp = lp->cf_conf; cp < lp->cf_conf + lp->cf_nconf; cp++)
if (*cp && !strncmp(*cp, name, len) && *(*cp + len) == '=')
return(cp);
return((char **) 0);
}
/*
** finddcfg() - find a config variable assignment for name on sysid
** in the distributed configuration and return a pointer
** to the entry's address
**
** name may be delimited either by '=' or '\0'
**
** return (char **) 0 if no match can be found
**
** this function must not be called before the per-system distributed
** configurations have been set up
*/
static char **finddcfg(name, sysid)
char *name;
int sysid;
{
struct systab *sp;
char **cp;
ASSERT(sysid >= 0);
ASSERT_LITE(sysid == 0);
ASSERT(tet_remvar_sysid(name) == -1);
/*
** first look for a defined distributed variable in the per-system
** distributed configuration
*/
if (
is_dist_var(name) &&
(sp = syfind(sysid)) != (struct systab *) 0
) {
ASSERT(IS_CFSETUP(sp, CONF_DIST));
if ((cp = findcfg(name, &CFLIST(sp, CONF_DIST))) != (char **) 0)
return(cp);
}
/*
** not found
** if sysid > 0, look for the variable in
** the master distributed configuration
**
** we don't look for system 0 variables in the master config -
** this is because distributed variables for system 0 are are derived
** from environment variables and we don't want an undadorned variable
** in tetdist.cfg supplying a default value when the corresponding
** environment variable has not been specified on the local system
*/
return(sysid > 0 ? findcfg(name, &MCFLIST(CONF_DIST)) : (char **) 0);
}
/************************************************************************
* *
* miscellaneous functions *
* *
************************************************************************/
/*
** tcc2cfmode() - convert a mode of operation to a config mode
**
** returns mode if mode is not a valid tcc mode of operation
*/
int tcc2cfmode(mode)
int mode;
{
switch (mode) {
case TCC_BUILD:
return(CONF_BUILD);
case TCC_EXEC:
return(CONF_EXEC);
case TCC_CLEAN:
return(CONF_CLEAN);
case CONF_BUILD:
case CONF_EXEC:
case CONF_CLEAN:
case CONF_DIST:
return(mode);
default:
/* this "can't happen" */
fatal(0, "unexpected mode", tet_i2o(mode));
/* NOTREACHED */
return(mode);
}
}
/*
** prcfmode() - return printable representation of a configuration
** mode
*/
char *prcfmode(mode)
int mode;
{
static char text[] = "conf-mode ";
static char msg[sizeof text + LNUMSZ];
switch (mode) {
case CONF_BUILD:
return("BUILD");
case CONF_EXEC:
return("EXEC");
case CONF_CLEAN:
return("CLEAN");
case CONF_DIST:
return("DIST");
default:
(void) sprintf(msg, "%s%d", text, mode);
return(msg);
}
}
/*
** cflag2bool() - return the boolean value of a string which should
** either be "True" or "False"
*/
static int cflag2bool(name, val)
char *name, *val;
{
switch (*val) {
case 'T':
case 't':
return(1);
case 'F':
case 'f':
break;
default:
error(0, name, "variable has ambiguous value - False assumed");
break;
}
return(0);
}
#ifdef TET_LITE /* -LITE-CUT-LINE- */
/*
** tet_config_putenv() - set up the value of the TET_CONFIG environment
** variable which corresponds to the current mode of operation
**
** return 0 if successful or -1 on error
*/
int tet_config_putenv(opmode)
int opmode;
{
static int currmode = -1;
static char *var;
static int lvar;
static char envname[] = "TET_CONFIG";
int cfmode;
cfmode = tcc2cfmode(opmode);
ASSERT(CONF_MODE_OK(cfmode, cfname));
/* return now if the current value has already been set */
if (cfmode == currmode)
return(0);
/*
** here to change the setting of TET_CONFIG in the environment
**
** ensure that the environment string is big enough,
** then format the variable
*/
ASSERT(TCFNAME(cfmode));
if (BUFCHK(&var, &lvar, (int) (sizeof envname + strlen(TCFNAME(cfmode)) + 1)) < 0)
return(-1);
(void) sprintf(var, "%s=%s", envname, TCFNAME(cfmode));
/* put the variable in the environment */
if (tet_putenv(var) < 0)
return(-1);
/* all ok so remember the current mode and return success */
currmode = cfmode;
return(0);
}
#endif /* TET_LITE */ /* -LITE-CUT-LINE- */
/*
** confgiveup() - exit after finding configuration errors
*/
static void confgiveup()
{
(void) fprintf(stderr,
"%s: giving up after %d configuration error%s\n",
tet_progname, conferrors, conferrors == 1 ? "" : "s");
tcc_exit(1);
}
/*
** config_cleanup() - remove temporary config files before exit
*/
void config_cleanup()
{
#ifdef TET_LITE /* -LITE-CUT-LINE- */
char **fname;
for (fname = tcfname; fname < &tcfname[Ntcfname]; fname++)
if (*fname)
(void) UNLINK(*fname);
#else /* -START-LITE-CUT- */
if (ecfname)
(void) UNLINK(ecfname);
if (dcfname)
(void) UNLINK(dcfname);
if (ccfname)
(void) UNLINK(ccfname);
#endif /* TET_LITE */ /* -END-LITE-CUT- */
}
/*
** get_runtime_tsroot() - return the name of the test suite root
** directory to be used at runtime on a particular system
**
** this function should not be called before distcfg() has set
** up the distributed configurations for each system
**
** the value returned by this function may not be useful before any
** required runtime copy operations have been performed
** (see the calls to rtlcopy() and rtrcopy() in tcc.c)
*/
char *get_runtime_tsroot(sysid)
int sysid;
{
char *retval, *rtdir, *tsroot;
static char rtsroot[MAXPATH];
/*
** if there is no TET_RUN, just return the system's TET_TSROOT;
** otherwise we must construct the name of the tsroot directory
** below TET_RUN and return that
*/
tsroot = getdcfg("TET_TSROOT", sysid);
ASSERT(tsroot);
if ((rtdir = getdcfg("TET_RUN", sysid)) == (char *) 0)
retval = tsroot;
else {
fullpath(rtdir, tet_basename(tsroot), rtsroot, sizeof rtsroot,
sysid == 0 ? 0 : 1);
retval = rtsroot;
}
TRACE3(tet_Ttcc, 10, "get_runtime_tsroot(%s) returns %s",
tet_i2a(sysid), retval);
return(retval);
}
/*
** initdvar() - initialise elements of the dvar array
*/
static void initdvar()
{
register struct dvar *dvp = dvar;
static int been_here;
if (been_here)
return;
else
been_here = 1;
/*
** set up dvar first time through -
** the number and order of these assignments must
** correspond to the variables in the dvar array
*/
(dvp++)->dv_value = tet_root;
(dvp++)->dv_value = tet_suite_root;
(dvp++)->dv_value = tet_tsroot;
(dvp++)->dv_value = tet_execute;
(dvp++)->dv_value = tet_tmp_dir;
(dvp++)->dv_value = tet_run;
for (dvp = dvar; dvp < dvar + Ndvar; dvp++)
dvp->dv_len = strlen(dvp->dv_name);
}
/*
** initmdvar() - initialise elements of the mdvar array
*/
static void initmdvar()
{
register struct dvar *dvp = mdvar;
static int been_here;
if (been_here)
return;
else
been_here = 1;
/* set up mdvar first time through - */
for (dvp = mdvar; dvp < mdvar + Nmdvar; dvp++)
dvp->dv_len = strlen(dvp->dv_name);
}
|