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
|
/*
* SCCS: @(#)rescode.c 1.6 (98/09/01)
*
* 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
/************************************************************************
SCCS: @(#)rescode.c 1.6 98/09/01 TETware release 3.3
NAME: rescode.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: August 1996
DESCRIPTION:
result code file processing functions
MODIFICATIONS:
Aaron Plattner, April 2010
Fixed warnings when compiled with GCC's -Wall option.
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
# include <unistd.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "error.h"
#include "globals.h"
#include "ltoa.h"
#include "servlib.h"
#include "dtetlib.h"
#include "restab.h"
#include "tet3_config.h"
#include "systab.h"
#include "tcc.h"
/* name of the temporary master results code file name */
static char *rcftmp;
/* static function declarations */
static void irc2 PROTOLIST((void));
#ifndef TET_LITE /* -START-LITE-CUT- */
static int rdist2 PROTOLIST((struct systab *, char **, int));
static void rescode_distribute PROTOLIST((void));
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/*
** initrescode() - set up the results code file
*/
void initrescode()
{
struct systab *sp;
TRACE1(tet_Ttcc, 4, "initrescode()");
/* initialise the rescode table */
irc2();
if ((sp = syfind(0)) != (struct systab *) 0)
sp->sy_rcfname = rcftmp;
#ifndef TET_LITE /* -START-LITE-CUT- */
/* propagate the rescode table to each remote system */
if (symax() > 0)
rescode_distribute();
/* then send the file name to XRESD */
if (tet_xdcodesfile(rcftmp) < 0)
fatal(tet_xderrno,
"can't send results code file name to XRESD",
(char *) 0);
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
}
/*
** irc2() - extend the initrescode() processing
**
** there is no return on error
*/
static void irc2()
{
char fname[MAXPATH];
register struct restab *rtp;
register char *p;
FILE *fp;
static char tet_rescodes_file[] = "TET_RESCODES_FILE";
TRACE1(tet_Ttcc, 4, "irc2()");
/* determine the name of the rescode file */
if (tcc_modes & TCC_EXEC)
p = getmcfg(tet_rescodes_file, TCC_EXEC);
else
p = (char *) 0;
if ((!p || !*p) && (tcc_modes & TCC_BUILD))
p = getmcfg(tet_rescodes_file, TCC_BUILD);
if ((!p || !*p) && (tcc_modes & TCC_CLEAN))
p = getmcfg(tet_rescodes_file, TCC_CLEAN);
if (!p || !*p)
p = "tet_code";
/* pick up the generic result code file if there is one */
fullpath(tet_root, p, fname, sizeof fname, 0);
if (tet_initrestab() < 0 ||
(tet_eaccess(fname, 04) == 0 && tet_readrescodes(fname) < 0))
tcc_exit(1);
/* pick up the testsuite-specific result code file if there is one */
fullpath(tet_tsroot, p, fname, sizeof fname, 0);
if (tet_eaccess(fname, 04) == 0 && tet_readrescodes(fname) < 0)
tcc_exit(1);
/*
** here to install the master rescode file -
** create a temporary file and open it
*/
if ((rcftmp = tet_mktfname("tcc")) == (char *) 0)
tcc_exit(1);
if ((fp = fopen(rcftmp, "w")) == (FILE *) 0)
fatal(errno, "can't open combined rescode file", rcftmp);
/* write out the default results codes */
(void) fprintf(fp, "# master results code file\n\n");
for (rtp = tet_restab; rtp < tet_restab + tet_nrestab; rtp++)
if (fprintf(fp, "%d \"%s\" %s\n", rtp->rt_code, rtp->rt_name,
rtp->rt_abrt ? "Abort" : "Continue") < 0)
fatal(errno, "write error on", rcftmp);
if (fclose(fp) < 0)
fatal(errno, "close error on", rcftmp);
}
#ifndef TET_LITE /* -START-LITE-CUT- */
/*
** rescode_distribute() - propagate the result codes file to each
** remote system
*/
static void rescode_distribute()
{
register int sysid, sysmax;
FILE *fp;
char line[LBUFLEN];
char **lines = (char **) 0;
int llines = 0, nlines = 0;
register char *p, **lp;
register struct systab *sp;
int rc = 0;
TRACE1(tet_Ttcc, 4, "rescode_distribute()");
/* open the master results code file */
if ((fp = fopen(rcftmp, "r")) == (FILE *) 0)
fatal(errno, "can't open", rcftmp);
/* read in all the lines */
while (fgets(line, sizeof line, fp) != (char *) 0) {
for (p = line; *p; p++)
if (*p == '\n') {
*p = '\0';
break;
}
RBUFCHK((char **) &lines, &llines, (int) ((nlines + 1) * sizeof *lines));
*(lines + nlines++) = rstrstore(line);
}
(void) fclose(fp);
/* distribute the lines to each remote system */
for (sysid = 1, sysmax = symax(); sysid <= sysmax; sysid++)
if ((sp = syfind(sysid)) != (struct systab *) 0 &&
rdist2(sp, lines, nlines) < 0)
rc = -1;
/* free storage allocated here */
for (lp = lines; lp < lines + nlines; lp++) {
TRACE2(tet_Tbuf, 6, "free rescode line = %s", tet_i2x(*lp));
free(*lp);
*lp = (char *) 0;
}
TRACE2(tet_Tbuf, 6, "free rescode list = %s", tet_i2x(lines));
free((char *) lines);
if (rc < 0)
tcc_exit(1);
}
/*
** rdist2() - extend the rescode_distribute() processing
**
** send the result codes file to a single system
**
** return 0 if successful or -1 on error
*/
static int rdist2(sp, lines, nlines)
struct systab *sp;
char **lines;
int nlines;
{
static char fmt[] = "can't open tmp result codes file %.*s on system";
char msg[sizeof fmt + MAXPATH];
char cfname[MAXPATH];
int fid, rc = 0;
TRACE2(tet_Ttcc, 4, "rdist2(): sysid = %s", tet_i2a(sp->sy_sysid));
/*
** determine the name of the remote temporary result codes file
** below the saved files directory
*/
fullpath(sp->sy_sfdir, "tet_rescode", cfname, sizeof cfname, 1);
/* open the remote file */
if ((fid = tet_tcfopen(sp->sy_sysid, cfname)) < 0) {
(void) sprintf(msg, fmt, sizeof msg - sizeof fmt, cfname);
if (!IS_ER_ERRNO(tet_tcerrno))
errno = 0;
error(errno ? errno : tet_tcerrno, msg, tet_i2a(sp->sy_sysid));
return(-1);
}
sp->sy_rcfname = rstrstore(cfname);
/* send all the result code lines to the remote system */
if (tet_tcputsv(sp->sy_sysid, fid, lines, nlines) < 0) {
if (!IS_ER_ERRNO(tet_tcerrno))
errno = 0;
error(errno ? errno : tet_tcerrno,
"can't send result code lines to system",
tet_i2a(sp->sy_sysid));
rc = -1;
}
/* close the file */
if (tet_tcfclose(sp->sy_sysid, fid) < 0) {
error(tet_tcerrno, "tet_tcfclose() failed for tmp result code file on system",
tet_i2a(sp->sy_sysid));
rc = -1;
}
return(rc);
}
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/*
** rescode_cleanup() - remove a temporary rescode file before exit
*/
void rescode_cleanup()
{
#ifndef TET_LITE /* -START-LITE-CUT- */
register int sysid, sysmax;
register struct systab *sp;
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
/* remove the local tmp result code file */
(void) UNLINK(rcftmp);
#ifndef TET_LITE /* -START-LITE-CUT- */
/* remove all the remote tmp rescode files */
for (sysid = 1, sysmax = symax(); sysid <= sysmax; sysid++)
if ((sp = syfind(sysid)) != (struct systab *) 0 &&
sp->sy_rcfname)
(void) tet_tcunlink(sysid, sp->sy_rcfname);
#endif /* !TET_LITE */ /* -END-LITE-CUT- */
}
|