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
|
/*
* SCCS: @(#)dtcc.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
#ifndef lint
static char sccsid[] = "@(#)dtcc.c 1.6 (98/09/01) TET3 release 3.3";
#endif
/************************************************************************
SCCS: @(#)dtcc.c 1.6 98/09/01 TETware release 3.3
NAME: dtcc.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: August 1996
DESCRIPTION:
functions related to distributed processing
interface to the generic client/server
MODIFICATIONS:
Andrew Dingwall, UniSoft Ltd., June 1997
check each environment string for valid format before sending
it to tccd on system 0
************************************************************************/
#ifndef TET_LITE /* -START-LITE-CUT- */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "ptab.h"
#include "error.h"
#include "globals.h"
#include "ltoa.h"
#include "server.h"
#include "servlib.h"
#include "dtetlib.h"
#include "tslib.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
extern char **ENVIRON;
/* ptrs to syncd and xresd ptabs */
struct ptab *tet_sdptab, *tet_xdptab;
/* static function declarations */
static int env2sys0 PROTOLIST((void));
static int sd_start PROTOLIST((void));
static int tccdlogon PROTOLIST((void));
static int ti_st2 PROTOLIST((struct ptab *, char **));
static struct ptab *ti_stserver PROTOLIST((int, char **));
static int xd_start PROTOLIST((char *));
/*
** initdtcc() - start up all the servers and log on to them
*/
void initdtcc()
{
TRACE1(tet_Ttcc, 1, "initdtcc(): start up the servers and log on to each remote system");
tet_ts_startup();
if (
ts_tccinit() < 0 ||
sd_start() < 0 ||
tet_sdlogon() < 0 ||
xd_start(resdirname()) < 0 ||
tet_xdlogon() < 0 ||
tccdlogon() < 0
)
tcc_exit(1);
TRACE1(tet_Ttcc, 1, "initdtcc(): normal RETURN");
}
/*
** sd_start() - start a syncd
**
** return 0 if successful or -1 on error
*/
static int sd_start()
{
static char *argv[] = { "tetsyncd", tet_root, (char *) 0 };
if (tet_sdptab) {
error(0, "syncd already started", (char *) 0);
return(-1);
}
if ((tet_sdptab = ti_stserver(PT_SYNCD, argv)) == (struct ptab *) 0)
return(-1);
return(0);
}
/*
** xd_start() - start an xresd
**
** return 0 if successful or -1 on error
*/
static int xd_start(savedir)
char *savedir;
{
static char *argv[] = {
"tetxresd",
"-s", (char *) 0,
tet_root,
(char *) 0
};
if (tet_xdptab) {
error(0, "xresd already started", (char *) 0);
return(-1);
}
argv[2] = savedir;
if ((tet_xdptab = ti_stserver(PT_XRESD, argv)) == (struct ptab *) 0)
return(-1);
return(0);
}
/*
** ti_stserver() - start a server
**
** return ptr to allocated ptab entry if successful,
** (struct ptab *) 0 otherwise
*/
static struct ptab *ti_stserver(ptype, argv)
int ptype;
char **argv;
{
register struct ptab *pp;
/* allocate a new ptab for the server and initialise it */
if ((pp = tet_ptalloc()) == (struct ptab *) 0)
return(pp);
pp->ptr_sysid = 0;
pp->ptr_ptype = ptype;
pp->pt_flags = PF_SERVER;
if (ti_st2(pp, argv) < 0) {
tet_ptfree(pp);
return((struct ptab *) 0);
}
return(pp);
}
/*
** ti_st2() - extend ti_stserver processing
**
** return 0 if successful, -1 otherwise
*/
static int ti_st2(pp, argv)
struct ptab *pp;
char **argv;
{
register int rc;
register char **avp;
#ifndef NOTRACE
/* add trace flags to the argv list */
if ((avp = tet_traceargs(pp->ptr_ptype, argv)) == (char **) 0)
return(-1);
#else
avp = argv;
#endif
/* start the server */
rc = ts_stserver(pp, avp);
return(rc);
}
/*
** tccdlogon() - log on to each tccd for which we have a systab entry
**
** return 0 if successful or -1 on error
*/
static int tccdlogon()
{
static char fmt[] = "can't access %.*s on system";
char msg[sizeof fmt + MAXPATH];
register int sysid, sysmax;
char *dir;
for (sysid = 0, sysmax = symax(); sysid <= sysmax; sysid++)
if (syfind(sysid) && !tet_getptbysysptype(sysid, PT_STCC) &&
tet_tclogon(sysid) < 0) {
error(0, "can't log on to TCCD on system",
tet_i2a(sysid));
return(-1);
}
/* send the local system environment to tccd on system 0 */
if (syfind(0) && env2sys0() < 0)
return(-1);
/* check that TET_ROOT and TET_TSROOT exist on each remote system */
for (sysid = 1, sysmax = symax(); sysid <= sysmax; sysid++)
if (syfind(sysid)) {
dir = getdcfg("TET_ROOT", sysid);
ASSERT(dir && *dir);
if (tcc_access(sysid, dir, 04) < 0) {
(void) sprintf(msg, fmt,
sizeof msg - sizeof fmt, dir);
error(errno, msg, tet_i2a(sysid));
return(-1);
}
dir = getdcfg("TET_TSROOT", sysid);
ASSERT(dir && *dir);
if (tcc_access(sysid, dir, 04) < 0) {
(void) sprintf(msg, fmt,
sizeof msg - sizeof fmt, dir);
error(errno, msg, tet_i2a(sysid));
return(-1);
}
}
return(0);
}
/*
** env2sys0() - send the local system environment to tccd on system 0
**
** return 0 if successful or -1 on error
*/
static int env2sys0()
{
register char **ep;
int bad_environ, rc;
char **envp;
int lenv, nenv;
/*
** count the number of environment strings and check each one
**
** if the environment contains garbage (as can happen when the
** user's shell is csh), we must first weed out the junk before
** sending the environment to tccd, otherwise tccd complains with
** an ER_INVAL error
*/
bad_environ = 0;
for (ep = ENVIRON; *ep; ep++)
if (tet_equindex(*ep) == (char *) 0) {
bad_environ = 1;
break;
}
if (bad_environ) {
TRACE1(tet_Ttcc, 8,
"env2sys0(): environment contains bad strings");
envp = (char **) 0;
lenv = nenv = 0;
for (ep = ENVIRON; *ep; ep++)
if (tet_equindex(*ep)) {
RBUFCHK((char **) &envp, &lenv,
(int) ((nenv + 1) * sizeof *envp));
*(envp + nenv++) = *ep;
}
}
else {
envp = ENVIRON;
nenv = ep - ENVIRON;
}
/* send the environment strings to tccd on system 0 */
if ((rc = tet_tcputenvv(0, envp, nenv)) < 0)
error(tet_tcerrno,
"can't send local environment to tccd on system 0",
(char *) 0);
/* free up any storage allocated here */
if (bad_environ) {
TRACE2(tet_Tbuf, 6, "env2sys0(): free envp = %s",
tet_i2x(envp));
free((char *) envp);
}
return(rc);
}
/*
** tet_ss_dead() - server-specific dead process handler
**
** should only be called from tet_si_service() when a server dies
** unexpectedly
**
** server logoff routines do not come here
*/
void tet_ss_dead(pp)
struct ptab *pp;
{
/* emit a diagnostic if this is unexpected */
if ((pp->pt_flags & PF_LOGGEDOFF) == 0)
error(0, "server connection closed", tet_r2a(&pp->pt_rid));
pp->pt_flags = (pp->pt_flags & ~PF_LOGGEDON) | PF_LOGGEDOFF;
}
/*
** tet_ss_connect() - connect to remote process
*/
void tet_ss_connect(pp)
struct ptab *pp;
{
tet_ts_connect(pp);
}
/*
** tet_ss_ptalloc(), tet_ss_ptfree() - allocate and free server-specific
** ptab data area
**
** tcc does not make use of server-specific data
*/
int tet_ss_ptalloc(pp)
struct ptab *pp;
{
pp->pt_sdata = (char *) 0;
return(0);
}
/* ARGSUSED */
void tet_ss_ptfree(pp)
struct ptab *pp;
{
/* nothing */
}
#else /* -END-LITE-CUT- */
int tet_dtcc_c_not_used;
#endif /* !TET_LITE */ /* -LITE-CUT-LINE- */
|