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
|
/*
* SCCS: @(#)syncd.c 1.13 (98/09/01)
*
* UniSoft Ltd., London, England
*
* (C) Copyright 1992 X/Open Company Limited
* (C) Copyright 1994 UniSoft 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.
*
* 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[] = "@(#)syncd.c 1.13 (98/09/01) TET3 release 3.3";
static char *copyright[] = {
"(C) Copyright 1996 X/Open Company Limited",
"All rights reserved"
};
#endif
/************************************************************************
SCCS: @(#)syncd.c 1.13 98/09/01 TETware release 3.3
NAME: syncd.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: April 1992
DESCRIPTION:
server-specific functions for syncd server
MODIFICATIONS:
Denis McConalogue, UniSoft Limited, June 1993
XTI enhancements - fill in transport provider address
from server -P option
Denis McConalogue, UniSoft Limited, September 1993
allow logon from more than one MTCC
Denis McConalogue, UniSoft Limited, September 1993
added ss_disconnect() routine
Andrew Dingwall, UniSoft Ltd., November 1993
enhancements for FIFO transport interface
moved XTI-specific stuff to syncd_xt.c
removed ss_disconnect stuff
Andrew Dingwall, UniSoft Ltd., October 1994
added support for sync message data
Andrew Dingwall, UniSoft Ltd., July 1998
Added support for shared API libraries.
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <time.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "ptab.h"
#include "synreq.h"
#include "stab.h"
#include "ltoa.h"
#include "error.h"
#include "globals.h"
#include "bstring.h"
#include "syncd.h"
#include "server.h"
#include "servlib.h"
#include "dtetlib.h"
#include "tslib.h"
#ifdef NEEDsrcFile
static char srcFile[] = __FILE__; /* file name for error reporting */
#endif
/************************************************************************
** *
** MAIN ROUTINES *
** *
************************************************************************/
int main(argc, argv)
int argc;
char **argv;
{
/* must be first */
tet_init_globals("tetsyncd", PT_SYNCD, 0, tet_generror, tet_genfatal);
tet_root[0] = '\0';
return(tet_si_main(argc, argv, 1));
}
/*
** tet_ss_argproc() - syncd command-line argument processing
*/
int tet_ss_argproc(firstarg, nextarg)
char *firstarg, *nextarg;
{
int rc = 0;
switch (*(firstarg + 1)) {
default:
rc = ss_tsargproc(firstarg, nextarg);
}
return(rc);
}
/*
** tet_ss_initdaemon() - syncd daemon initialisation
*/
void tet_ss_initdaemon()
{
/* perform syncd transport-specific initialisation */
ss_tsinitb4fork();
/* start the daemon */
tet_si_forkdaemon();
/* detach from the control terminal */
tet_tiocnotty();
}
/*
** tet_ss_serverloop() - syncd main processing loop
*/
int tet_ss_serverloop()
{
extern struct ptab *tet_ptab;
/* perform the generic server loop */
tet_si_serverloop();
/* exit if the proc table is empty,
otherwise arrange to come back */
return(tet_ptab ? 1 : 0);
}
/*
** tet_ss_procrun() - server-specific end-procrun routine
*/
void tet_ss_procrun()
{
/* perform the sync table service loop */
stloop();
}
/*
** tet_ss_timeout() - server-specific timeout processing routine
*/
void tet_ss_timeout(pp)
register struct ptab *pp;
{
register struct stab *sp;
register struct ustab *up;
if (pp->pt_state != PS_WAITSYNC)
return;
sp = ((struct sptab *) pp->pt_sdata)->sp_stab;
ASSERT(sp);
TRACE4(tet_Tsyncd, 6, "%s: sync timed out, snid = %s, xrid = %s",
tet_r2a(&pp->pt_rid), tet_l2a(sp->st_snid),
tet_l2a(sp->st_xrid));
/* update the sync state for this process */
for (up = sp->st_ud; up < sp->st_ud + sp->st_nud; up++)
if (up->us_ptab == pp) {
ASSERT(up->us_state != SS_NOTSYNCED);
switch (up->us_state) {
case SS_SYNCYES:
case SS_SYNCNO:
up->us_state = SS_TIMEDOUT;
stcheck(sp);
break;
}
break;
}
ASSERT(up < sp->st_ud + sp->st_nud);
pp->pt_flags &= ~PF_TIMEDOUT;
}
/************************************************************************
** *
** SERVER-SPECIFIC PARTS OF GENERIC SERVICE ROUTINES *
** *
************************************************************************/
/*
** tet_ss_dead() - server-specific routine to handle a dead process
*/
void tet_ss_dead(pp)
register struct ptab *pp;
{
/* emit a diagnostic message if this is unexpected */
if ((pp->pt_flags & PF_LOGGEDOFF) == 0)
error(0, "client connection closed", tet_r2a(&pp->pt_rid));
pp->pt_flags = (pp->pt_flags & ~PF_LOGGEDON) | PF_LOGGEDOFF;
/* update all sync events referencing this process */
stdead(pp);
/* syncd is never a client - call the server-only dead process
routine to remove the ptab entry */
tet_so_dead(pp);
}
/************************************************************************
** *
** FULL REQUEST PROCESSING ROUTINES *
** *
************************************************************************/
/*
** tet_ss_process() - request processing routine
*/
void tet_ss_process(pp)
struct ptab *pp;
{
tet_si_serverproc(pp);
}
/*
** tet_ss_serverproc() - request processing as a server
*/
void tet_ss_serverproc(pp)
register struct ptab *pp;
{
switch (pp->ptm_req) {
case OP_SNGET:
op_snget(pp);
break;
case OP_SNSYS:
op_snsys(pp);
break;
case OP_ASYNC:
op_async(pp);
break;
case OP_USYNC:
op_usync(pp);
break;
case OP_SNRM:
op_snrm(pp);
break;
default:
pp->ptm_rc = ER_REQ;
pp->ptm_mtype = MT_NODATA;
pp->ptm_len = 0;
break;
}
if (pp->pt_state != PS_WAITSYNC) {
pp->pt_state = PS_SNDMSG;
pp->pt_flags = (pp->pt_flags & ~PF_IODONE) | PF_ATTENTION;
}
}
/************************************************************************
** *
** SERVER-SPECIFIC PARTS OF GENERIC REQUEST PROCESSING *
** *
************************************************************************/
/*
** tet_ss_logon() - server-specific logon processing routine
**
** return ER_OK if successful or other ER_* error code on error
*/
int tet_ss_logon(pp)
register struct ptab *pp;
{
register struct ptab *pp1, *pp2;
register int count;
extern struct ptab *tet_ptab;
/* make sure that we only have one MTCC and one XRESD logged on */
switch (pp->ptr_ptype) {
/*
** case PT_MTCC:
*/
case PT_XRESD:
pp1 = tet_ptab;
count = 0;
while ((pp2 = tet_getnextptbyptype(pp->ptr_ptype, pp1)) != (struct ptab *) 0) {
if (pp2 != pp)
count++;
if ((pp1 = pp2->pt_next) == (struct ptab *) 0)
break;
}
if (count > 0) {
error(0, "client of this type already logged on",
tet_r2a(&pp->pt_rid));
return(ER_LOGON);
}
break;
}
return(ER_OK);
}
/*
** tet_ss_logoff() - server-specific logoff processing
*/
void tet_ss_logoff(pp)
struct ptab *pp;
{
stdead(pp);
}
/*
** tet_ss_cleanup() - clean up and exit
*/
void tet_ss_cleanup()
{
tet_ts_cleanup();
exit(0);
}
/************************************************************************
** *
** PUBLIC SUBROUTINES *
** *
************************************************************************/
/*
** tet_ss_ptalloc() - allocate server-specific data element in a ptab
** structure
**
** return 0 if successful or -1 on error
*/
int tet_ss_ptalloc(pp)
struct ptab *pp;
{
register struct sptab *sp;
errno = 0;
if ((sp = (struct sptab *) malloc(sizeof *sp)) == (struct sptab *) 0) {
error(errno, "can't get memory for ss data", (char *) 0);
pp->pt_sdata = (char *) 0;
return(-1);
}
TRACE2(tet_Tbuf, 6, "allocate sptab = %s", tet_i2x(sp));
bzero((char *) sp, sizeof *sp);
sp->sp_xrid = -1L;
pp->pt_sdata = (char *) sp;
return(0);
}
/*
** tet_ss_ptfree() - free server-specific data element in a ptab structure
*/
void tet_ss_ptfree(pp)
struct ptab *pp;
{
TRACE2(tet_Tbuf, 6, "free sptab = %s", tet_i2x(pp->pt_sdata));
if (pp->pt_sdata) {
free(pp->pt_sdata);
pp->pt_sdata = (char *) 0;
}
}
/*
** tet_ss_newptab() - server-specific new ptab entry handler
*/
void tet_ss_newptab(pp)
struct ptab *pp;
{
/* add the entry to the process table */
tet_ptadd(pp);
}
|