summaryrefslogtreecommitdiff
path: root/src/tet3/tcm/ictp.c
blob: 1e81c16956b9013bfb233644148a86637a8087f1 (plain)
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
/*
 *	SCCS: @(#)ictp.c	1.22 (98/09/22)
 *
 *	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.
 */

/*
 * Copyright 1990 Open Software Foundation (OSF)
 * Copyright 1990 Unix International (UI)
 * Copyright 1990 X/Open Company Limited (X/Open)
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of OSF, UI or X/Open not be used in 
 * advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission.  OSF, UI and X/Open make 
 * no representations about the suitability of this software for any purpose.  
 * It is provided "as is" without express or implied warranty.
 *
 * OSF, UI and X/Open DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 
 * EVENT SHALL OSF, UI or X/Open BE LIABLE FOR ANY SPECIAL, INDIRECT OR 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 
 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 
 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
 * PERFORMANCE OF THIS SOFTWARE.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/************************************************************************

SCCS:   	@(#)ictp.c	1.22 98/09/22 TETware release 3.3
NAME:		ictp.c
PRODUCT:	TETware
AUTHOR:		Geoff Clare, UniSoft Ltd.
DATE CREATED:	25 July 1990
DESCRIPTION:

	tet_icstart(), tet_icend(), tet_tpstart() and
	tet_tpend() are used by the TCM to output TCM start lines, IC
	start and end lines and test purpose start and result lines to
	the combined execution results file maintained by XRESD

MODIFICATIONS:
	
	June 1992
	DTET development - apilib/dresfile.c is derived from
	TET release 1.10

	Andrew Dingwall, UniSoft Ltd,. October 1992
	Some non-API functions specific to parent TCMs moved from
	apilib/dresfile.c to here.

	All vestages of the local execution results file and temporary
	execution results file removed - in the DTET, all the processing
	associated with these files is done by XRESD.

	All these functions completely re-written - auto-syncs are used
	to pass deletion and Abort information between TCMs as follows:

		if a TP is deleted within a TCM, that TCM votes NO at the
		TP start sync point
		if a TCM receives a NO sync vote at TP start, it knows that
		the TP has been deleted in another TCM

		if a result code action is Abort, XRESD returns ER_ABORT
		when the MTCM calls tet_xdtpend() from tet_tpend();
		the MTCM syncs with a NO vote to the end of the last TP

		STCMs will receive this NO vote at the start of any remaining
		TPs in the current IC, thus causing them to believe that
		these TPs have been deleted in the MTCM

		when STCMs receive the NO vote at the start of the next IC,
		they will interpret it as the signal to perform Abort
		processing

	Andrew Dingwall, UniSoft Ltd., November 1992
	Increased tpend sync timeout to 10 mins so as to allow for
	larger inbalance between test part execution times.

	Denis McConalogue, UniSoft Limited, June 1993
	API enhancements - moved all functions from [ms]tcmdist.c
			   to here. Added tet_ismaster().

	Denis McConalogue, UniSoft Limited, September 1993
	do not open tet_combined in tet_opencom() if an tet_xrid is
	already initialised.

	Andrew Dingwall, UniSoft Ltd., November 1994
	signal IC end from MTCM when result code action is Abort

	Geoff Clare, UniSoft Ltd., August 1996
	Changes for TETWare.

	Andrew Dingwall, UniSoft Ltd., August 1996
	changes for use with tetware tcc

	Geoff Clare, UniSoft Ltd., Sept 1996
	Changes for TETWare-Lite.

	Andrew Dingwall, UniSoft Ltd., June 1997
	changes to support the defined test case interface

	Andrew Dingwall, UniSoft Ltd., July 1998
	Added support for shared API libraries.

************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#  include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#include "dtmac.h"
#include "error.h"
#include "globals.h"
#include "dtmsg.h"
#include "dtthr.h"
#include "ltoa.h"
#include "synreq.h"
#include "servlib.h"
#include "dtetlib.h"
#include "tcmfuncs.h"
#include "tet_api.h"
#include "tet_jrnl.h"
#include "apilib.h"

#define MODE666 (mode_t) (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

#ifdef TET_LITE	/* -LITE-CUT-LINE- */
   char *tet_tmpresfile;
   static char *tmpresenv;
   static char *resfile;
#else		/* -START-LITE-CUT- */
   TET_IMPORT int tet_iclast = ~(~0 << S_ICBITS) - 2;
					/* used in auto sync before cleanup */
   TET_IMPORT int tet_XSync_del = 0;	/* true when a TP is deleted in a
					   test case part on another system */
   TET_IMPORT struct synreq *tet_synreq = (struct synreq *) 0;
					/* used when analysing the results
					   of an auto-sync */
#endif		/* -END-LITE-CUT- */


/* static function declarations */
static void icend2 PROTOLIST((int, int));
static int icstart2 PROTOLIST((int, int));
static int tpend2 PROTOLIST((int, int, int));
static void tpstart2 PROTOLIST((int, int, int));
#ifdef TET_LITE	/* -LITE-CUT-LINE- */
   static char *curtime PROTOLIST((void));
   static void lite_output PROTOLIST((int, char *, char *));
#else		/* -START-LITE-CUT- */
   static int ismaster PROTOLIST((void));
   static int mtcm_tpend2 PROTOLIST((void));
#endif		/* -END-LITE-CUT- */


/*
**	tet_icstart() - signal IC start
**
**	return 0 if successful or -1 to abort the test case
**
**	in Distributed TETware, if the previous result code action was Abort,
**	this function is only executed by STCMs
*/

TET_IMPORT int tet_icstart(icno, tpcount)
int icno, tpcount;
{
	int rc;

	TRACE3(tet_Ttcm, 7, "tet_icstart(): icno = %s, tpcount = %s",
		tet_i2a(icno), tet_i2a(tpcount));

	rc = icstart2(icno, tpcount);

	TRACE2(tet_Ttcm, 7, "tet_icstart() RETURN %s", tet_i2a(rc));
	return(rc);
}

#ifdef TET_LITE	/* -LITE-CUT-LINE- */

static int icstart2(icno, tpcount)
int icno, tpcount;
{
	char buf[128];

	(void) sprintf(buf, "%d %d %s", icno, tpcount, curtime());
	lite_output(TET_JNL_IC_START, buf, "IC Start");
	return(0);
}

#else		/* -START-LITE-CUT- */

static int icstart2(icno, tpcount)
int icno, tpcount;
{
	register struct synreq *sp;
	int nsys = tet_Nsname;
	int errflag;
	char errmsg[128];

	/* the MTCM informs XRESD of IC start */
	if (
		ismaster() &&
		tet_xdicstart(tet_xrid, icno, tet_activity, tpcount) < 0
	) {
		tet_error(tet_xderrno, "can't inform XRESD of IC start");
		tet_exit(EXIT_FAILURE);
	}

	/*
	** then all TCMs sync on IC start -
	**	if the MTCM votes NO, this means that the previous result
	**	code action was Abort
	*/
	ASSERT(tet_synreq);
	if (tet_tcm_async(MK_ASPNO(icno, 0, S_ICSTART), SV_YES, SV_SYNC_TIMEOUT,
		tet_synreq, &nsys) < 0) {
			(void) sprintf(errmsg,
				"Auto Sync failed at start of IC %d", icno);
			tet_error(tet_sderrno, errmsg);
			tet_exit(EXIT_FAILURE);
	}

	if (tet_sderrno == ER_OK)
		return(0);

	/*
	** here if the auto sync failed in an expected way -
	** 	a NO vote from the MTCM means that the test is to be aborted
	*/
	errflag = 0;
	for (sp = tet_synreq; sp < tet_synreq + nsys; sp++)
		switch (sp->sy_state) {
		case SS_SYNCYES:
			break;
		case SS_SYNCNO:
			if (sp->sy_sysid == 0)
				break;
			/* else fall through */
		default:
			(void) sprintf(errmsg,
		"Auto sync error at start of IC %d, sysid = %d, state = %s",
				icno, sp->sy_sysid, tet_systate(sp->sy_state));
			tet_error(tet_sderrno, errmsg);
			errflag = 1;
			break;
		}


	if (errflag)
		tet_exit(EXIT_FAILURE);

	/* here if MTCM voted NO - return -1 to force a cleanup and exit */
	return(-1);
}

#endif		/* -END-LITE-CUT- */

/*
**	tet_icend() - signal IC end
*/

TET_IMPORT void tet_icend(icno, tpcount)
int icno, tpcount;
{

	TRACE3(tet_Ttcm, 7, "tet_icend(): icno = %s, tpcount = %s",
		tet_i2a(icno), tet_i2a(tpcount));

	icend2(icno, tpcount);

	TRACE1(tet_Ttcm, 7, "tet_icend() RETURN");
}


#ifdef TET_LITE	/* -LITE-CUT-LINE- */

static void icend2(icno, tpcount)
int icno, tpcount;
{
	char buf[128];

	(void) sprintf(buf, "%d %d %s", icno, tpcount, curtime());
	lite_output(TET_JNL_IC_END, buf, "IC End");
}

#else		/* -START-LITE-CUT- */

/* ARGSUSED */
static void icend2(icno, tpcount)
{
	/* the MTCM informs XRESD of IC end */
	if (ismaster() && tet_xdicend(tet_xrid) < 0) {
		tet_error(tet_xderrno, "can't inform XRESD of IC end");
		tet_exit(EXIT_FAILURE);
	}
}

#endif		/* -END-LITE-CUT- */


/*
**	tet_tpstart() - signal TP start
*/

TET_IMPORT void tet_tpstart(icno, tpno, testnum)
int icno, tpno, testnum;
{

	TRACE4(tet_Ttcm, 7, "tet_tpstart(): icno = %s, tpno = %s, testnum = %s",
		tet_i2a(icno), tet_i2a(tpno), tet_i2a(testnum));

#ifdef TET_THREADS
	tet_next_block = 1;
#endif
	tet_block = 1;
	tet_sequence = 1;

	tpstart2(icno, tpno, testnum);

	TRACE1(tet_Ttcm, 7, "tet_tpstart() RETURN");
}


#ifdef TET_LITE	/* -LITE-CUT-LINE- */

static void tpstart2(icno, tpno, testnum)
int icno, tpno, testnum;
{
	char buf[128];

	(void) sprintf(buf, "%d %s", testnum, curtime());
	lite_output(TET_JNL_TP_START, buf, "TP Start");

	/* create temporary result file */
	(void) remove(tet_tmpresfile);
	if ((tet_tmpresfp = fopen(tet_tmpresfile, "a+b")) == (FILE *) 0)
		fatal(errno, "cannot create temporary result file:",
			tet_tmpresfile);

	/* override umask (must be writable by set-uid children) */
	(void) CHMOD(tet_tmpresfile, MODE666);

	/*
	** put pathname in environment to be picked up by tet_result() in
	** exec'ed programs
	*/
	ASSERT(tmpresenv);
	if (tet_putenv(tmpresenv) != 0)
		tet_error(0, "tet_putenv() failed setting TET_TMPRESFILE");
}

#else		/* -START-LITE-CUT- */

static void tpstart2(icno, tpno, testnum)
int icno, tpno, testnum;
{
	register struct synreq *sp;
	register int vote;
	int nsys = tet_Nsname;
	int errflag;
	char errmsg[128];

	/* the MTCM informs XRESD of TP start */
	if (ismaster() && tet_xdtpstart(tet_xrid, testnum) < 0) {
		tet_error(tet_xderrno, "can't inform XRESD of TP start");
		tet_exit(EXIT_FAILURE);
	}

	/*
	** see if the TP has been deleted in this TCM and set our vote
	** accordingly
	*/
	vote = tet_reason(testnum) ? SV_NO : SV_YES;

	/* then all the TCMs sync on TP start */
	ASSERT(tet_synreq);
	if (tet_tcm_async(MK_ASPNO(icno, tpno, S_TPSTART), vote,
		SV_SYNC_TIMEOUT, tet_synreq, &nsys) < 0) {
			(void) sprintf(errmsg,
				"Auto Sync failed at start of TP %d", testnum);
			tet_error(tet_sderrno, errmsg);
			tet_exit(EXIT_FAILURE);
	}

	if (tet_sderrno == ER_OK)
		return;

	/*
	** here if sync failed in an expected way -
	**	a NO vote means that the TP has been deleted in another TCM
	*/
	errflag = 0;
	for (sp = tet_synreq; sp < tet_synreq + nsys; sp++)
		switch (sp->sy_state) {
		case SS_SYNCYES:
			break;
		case SS_SYNCNO:
			tet_XSync_del = 1;
			break;
		default:
			(void) sprintf(errmsg,
		"Auto Sync error at start of TP %d, sysid = %d, state = %s",
				testnum, sp->sy_sysid,
				tet_systate(sp->sy_state));
			tet_error(tet_sderrno, errmsg);
			errflag = 1;
			break;
		}

	if (errflag)
		tet_exit(EXIT_FAILURE);
}

#endif		/* -END-LITE-CUT- */


/*
**	tet_tpend() - signal TP end
**
**	return 0 if successful or -1 to abort the test case
*/

TET_IMPORT int tet_tpend(icno, tpno, testnum)
int icno, tpno, testnum;
{
	int rc;

	TRACE4(tet_Ttcm, 7, "tet_tpend(): icno = %s, tpno = %s, testnum = %s",
		tet_i2a(icno), tet_i2a(tpno), tet_i2a(testnum));

	rc = tpend2(icno, tpno, testnum);

	TRACE2(tet_Ttcm, 7, "tet_tpend(): RETURN %s", tet_i2a(rc));
	return(rc);
}


#ifdef TET_LITE	/* -LITE-CUT-LINE- */

static int tpend2(icno, tpno, testnum)
int icno, tpno, testnum;
{
	char *res;
	int have_result, nextres, err;
	int result = TET_NORESULT;
	int abrt = 0;
	char buf[128];

	/*
	 * output a "TP Result" line to the execution results file,
	 * based on the result code(s) written to a temporary result
	 * file by tet_result()
	 */

	/* rewind temporary result file */
	if (fseek(tet_tmpresfp, 0L, SEEK_SET) != 0)
	{
		tet_error(errno, "failed to rewind temporary result file");

		/* fall through: no results will be read */
	}

	/*
	** read result code(s) from temporary file - if more than one
	** has been written, choose the one with the highest priority
	*/

	have_result = 0;
	while (fread((void *)&nextres, sizeof(nextres), (size_t) 1, tet_tmpresfp) == 1)
	{
		/* if it's the first result, take it (for now) */
		if (!have_result)
		{
			result = nextres;
			have_result = 1;
			continue;
		}

		/* decide if this result supersedes any previous ones */

		result = tet_addresult(result, nextres);
	}
	err = errno;

	if (ferror(tet_tmpresfp))
	{
		tet_error(err, "read error on temporary results file");
		have_result = 0;
	}

	(void) fclose(tet_tmpresfp);
	(void) UNLINK(tet_tmpresfile);
	(void) tet_putenv("TET_TMPRESFILE=");

	if (!have_result)
	{
		result = TET_NORESULT;
		res = "NORESULT";
	}
	else
	{
		res = tet_get_code(result, &abrt);
		if (res == NULL)
		{
			/*
			** This should never happen, as the codes have
			** already been validated by tet_result().
			** It is not a serious problem - the name is only
			** there to make the results file more readable
			*/
			res = "(NO RESULT NAME)";
		}
	}

	(void) sprintf(buf, "%d %d %s", testnum, result, curtime());
	lite_output(TET_JNL_TP_RESULT, buf, res);

	/*
	** Abort is done here rather than in tet_result() since the
	** latter may have been called in a child.
	** Test purposes should not assume that tet_result() will not return
	** when called with an abort code.
	*/
	if (abrt)
	{
#  ifdef TET_THREADS
		tet_cln_threads(0);
		tet_mtx_destroy();
		tet_mtx_init();
#  endif
		(void) sprintf(buf, "ABORT on result code %d \"%s\"",
			result, res);
		lite_output(TET_JNL_TCM_INFO, "", buf);
		return(-1);
	}

	return(result);
}

#else		/* -START-LITE-CUT- */

static int tpend2(icno, tpno, testnum)
int icno, tpno, testnum;
{
	register struct synreq *sp;
	int err;
	int nsys = tet_Nsname;
	char errmsg[128];

	/*
	** all the TCMs sync YES on TP end -
	**	there is an assumption here that the parts of a TP will
	**	arrive at their ends within 10 minutes of each other;
	**	if this is not so for a particular test, the test writer
	**	is expected to use tet_sync() with a longer timeout
	**	to delay the ends of the quicker test parts
	*/
	ASSERT(tet_synreq);
	if (tet_tcm_async(MK_ASPNO(icno, tpno, S_TPEND), SV_YES,
		SV_SYNC_TIMEOUT * 10, tet_synreq, &nsys) < 0) {
			(void) sprintf(errmsg, 
				"Auto Sync failed at end of TP %d", testnum);
			tet_error(tet_sderrno, errmsg);
			tet_exit(EXIT_FAILURE);
	}
	err = tet_sderrno;

	/*
	** then the MTCM informs XRESD of TP end -
	**	if XRESD returns ER_ABORT when tet_xdtpend() is called, this
	**	function does not return in the MTCM
	*/
	if (ismaster() && mtcm_tpend2() < 0)
		return(-1);

	if (err == ER_OK)
		return(0);

	/* here if a TCM voted NO ("can't happen"), timed out or died */
	for (sp = tet_synreq; sp < tet_synreq + nsys; sp++)
		switch (sp->sy_state) {
		case SS_SYNCYES:
			break;
		default:
			(void) sprintf(errmsg,
		"Auto Sync error at end of TP %d, sysid = %d, state = %s",
				testnum, sp->sy_sysid,
				tet_systate(sp->sy_state));
			tet_error(err, errmsg);
			break;
		}

	tet_exit(EXIT_FAILURE);

	/* NOTREACHED */
	return(-1);
}

/*
**	mtcm_tpend2() - inform XRESD of TP end from MTCM
**
**	return 0 if successful or -1 if XRESD indicates that the testcase
**	must be aborted
*/

static int mtcm_tpend2()
{
	char errmsg[128];
	struct synreq *synreq;
	int nsys, errflag;
	register struct synreq *sp;

	/* signal TP end to XRESD */
	(void) tet_xdtpend(tet_xrid);
	switch (tet_xderrno) {
	case ER_OK:
		return(0);
	case ER_ABORT:
		/* XRESD prints the "ABORT on result code" message */
		break;
	default:
		tet_error(tet_xderrno, "can't inform XRESD of TP end");
		tet_exit(EXIT_FAILURE);
		/* NOTREACHED */
	}

	/*
	** here if previous TP result code action was Abort -
	** allocate memory for synreq array; don't worry if it fails
	*/
	errno = 0;
	if ((synreq = (struct synreq *) malloc((size_t)(sizeof *synreq * tet_Nsname))) == (struct synreq *) 0) {
		tet_error(errno, " can't allocate synreq array for Abort sync");
		nsys = 0;
	}
	else
		nsys = tet_Nsname;

	/* signal IC end to XRESD */
	if (tet_xdicend(tet_xrid) < 0)
		tet_error(tet_xderrno, "ABORT: can't inform XRESD of IC end");

	/*
	** sync NO to the end of the last IC -
	**	this communicates the Abort action to other TCMs
	*/
	if (tet_tcm_async(MK_ASPNO(tet_iclast, ~0, S_ICEND), SV_NO,
		SV_SYNC_TIMEOUT, synreq, &nsys) < 0) {
			tet_error(tet_sderrno, "Abort Auto Sync failed");
			tet_exit(EXIT_FAILURE);
	}

	/* make sure that the other TCMs are still alive */
	if (synreq) {
		errflag = 0;
		for (sp = synreq; sp < synreq + nsys; sp++)
			switch (sp->sy_state) {
			case SS_SYNCYES:
			case SS_SYNCNO:
				break;
			default:
				(void) sprintf(errmsg,
			"Abort Auto Sync error, sysid = %d, state = %s",
					sp->sy_sysid,
					tet_systate(sp->sy_state));
				tet_error(tet_sderrno, errmsg);
				errflag = 1;
				break;
			}
		if (errflag)
			tet_exit(EXIT_FAILURE);
	}

	/* here if we should attempt to call (*tet_cleanup)() */
	return(-1);
}

#endif		/* -END-LITE-CUT- */


/*
**	tet_tcmstart() - send TCM Start journal line to XRESD
*/

void tet_tcmstart(versn, no_ics)
char *versn;
int no_ics;
{
	char buf[128];

#ifdef TET_LITE	/* -LITE-CUT-LINE- */

	(void) sprintf(buf, "%s %d", versn, no_ics);
	lite_output(TET_JNL_TCM_START, buf, "TCM Start");

#else		/* -START-LITE-CUT- */

	if (!ismaster()) 
		return;

	(void) sprintf(buf, "%d|%ld %s %d|TCM Start", 
		TET_JNL_TCM_START, tet_activity, versn, no_ics);

	if (tet_xdxres(tet_xrid, buf) < 0) {
		tet_error(tet_xderrno,
			"can't send \"TCM Start\" journal line to XRESD");
		tet_exit(EXIT_FAILURE);
	}

#endif		/* -END-LITE-CUT- */

}


#ifndef TET_LITE	/* -START-LITE-CUT- */

/*
**	tet_init_synreq() - allocate memory for the tet_synreq array
*/

TET_IMPORT void tet_init_synreq()
{
	if (tet_synreq != (struct synreq *) 0)
		return;

	errno = 0;
	if ((tet_synreq = (struct synreq *) malloc(sizeof *tet_synreq * tet_Nsname)) == (struct synreq *) 0) {
		tet_error(errno, "can't allocate memory for tet_synreq array");
		tet_exit(EXIT_FAILURE);
	}

	TRACE2(tet_Tbuf, 6, "allocate tet_synreq = %s", tet_i2x(tet_synreq));
}

/*
**	ismaster() - return true if we are running on the master
**			 system.
*/

static int ismaster()
{
	if (tet_myptype == PT_MTCM)
		return (1);
	else if (tet_myptype == PT_STCM)
		return (0);
	else {
		tet_error(0, "Can't determine system type");
		tet_exit(EXIT_FAILURE);
		/* NOTREACHED */
		return(0);
	}
}

#endif		/* -END-LITE-CUT- */



#ifdef TET_LITE	/* -LITE-CUT-LINE- */

/*
**	tet_openres() - open the tet_xres file in TETware-Lite
*/

TET_IMPORT void tet_openres(progname)
char *progname;
{
	static char tmpvar[] = "TET_TMPRESFILE";
	char buf[MAXPATH];
	char *p;

	/* get results filename from the environment */
	resfile = getenv("TET_RESFILE");
	if (!resfile)
		fatal(0, "TET_RESFILE not set in the environment", NULL);

	tmpresenv = malloc(strlen(tmpvar) + strlen(resfile) +
				strlen("=.tmp") + 1);
	if (tmpresenv == NULL)
		fatal(errno, "can't allocate tmpresenv in tet_openres()",
			(char *) 0);
	TRACE2(tet_Tbuf, 6, "allocate tmpresenv = %s",
		tet_i2x(tmpresenv));

	sprintf(tmpresenv, "%s=%s.tmp", tmpvar, resfile);
	tet_tmpresfile = tmpresenv + sizeof(tmpvar);

	/* create the leading directories for the results file */
	strncpy(buf, resfile, sizeof(buf) - 1);
	for (p = buf + strlen(buf) - 1; p > buf; p--)
		if (isdirsep(*p))
			break;
	if (p > buf) {
		*p = '\0';
		if (tet_mkalldirs(buf) != 0 && errno != EEXIST)
			fatal(errno,
				"cannot create results file directory:",
				buf);
	}

	/* create the execution results file and open in append mode */

	(void) remove(resfile);
	tet_resfp = fopen(resfile, "a");
	if (tet_resfp == NULL)
		fatal(errno, "cannot create results file:", resfile);

	/* override umask (must be writable by set-uid children) */
	(void) CHMOD(resfile, MODE666);

	tet_combined_ok = 1;
}

/*
**	lite_output() - print a line to the tet_xres file in TETware-Lite
*/

static void lite_output(mtype, fields, data)
int mtype;
char *fields;
char *data;
{
	char outbuf[TET_JNL_LEN];
	char *obp;
	static char fmt[] = "%d|%ld%s%.64s|";
	char header[sizeof fmt + (LNUMSZ * 2) + 64];

	if (data == NULL)
		data = "";

	(void) sprintf(header, fmt, mtype, tet_activity,
		fields[0] == '\0' ? "" : " ", fields);
	tet_msgform(header, data, outbuf);
	obp = outbuf;
	tet_routput(&obp, 1);
}

/*
**	curtime() - return string containing current time
*/

static char *curtime()
{
	time_t t;
	struct tm *tp;
	static char s[10];

	(void) time(&t);
	tp = localtime(&t);
	(void) sprintf(s, "%02d:%02d:%02d", tp->tm_hour,
		tp->tm_min, tp->tm_sec);

	return s;
}

#endif		/* -END-LITE-CUT- */