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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
This module contains routines that find C. files
in a system spool directory, return the next C. file
to process, and break up the C. line into arguments
for processing.
*/
#include "uucp.h"
#define BOOKMARK_PRE 'A'
#define CLEAN_RETURN(fp) {\
if (fp != NULL) \
(void) fclose(fp); \
fp = NULL; \
return(0); \
/* NOTREACHED */ \
}
/* C.princetN0026 - ('C' + '.') - "princet" */
#define SUFSIZE (MAXBASENAME - 2 - SYSNSIZE)
#define LLEN 50
#define MAXRQST 250
static void insert();
static int anlwrk(), bldflst();
extern int iswrk(), gtwvec(), gnamef();
static char Filent[LLEN][NAMESIZE]; /* array of C. file names (text) */
static char *Fptr[LLEN]; /* pointers to names in Filent */
static short Nnext; /* index of next C. file in Fptr list */
static short Nfiles = 0; /* Number of files in Filent */
/*
* read a line from the workfile (C.file)
* file -> work file (Input/Output) made '\0' after work completion
* wvec -> address of array to return arguments (Output)
* wcount -> maximum # of arguments to return in wvec
* NOTE: wvec should be large enough to accept wcount + 1 pointers
* since NULL is inserted after last item.
* returns:
* 0 -> no more work in this file
* positive # -> number of arguments
*/
static int
anlwrk(file, wvec, wcount)
char *file, **wvec;
{
int i;
FILE *p_bookmark; /* pointer to afile */
static FILE *fp = NULL; /* currently opened C. file pointer */
static char afile[NAMESIZE]; /* file with line count for book marks */
static char str[MAXRQST]; /* the string which wvec points to */
static short acount;
struct stat stbuf;
int nargs; /* return value == # args in the line */
if (file[0] == '\0') {
if (fp != NULL)
errent("anlwrk",
"attempt made to use old workfile was thwarted", 0,
__FILE__, __LINE__);
CLEAN_RETURN(fp);
/* NOTREACHED */
}
if (fp == NULL) {
fp = fopen(file, "r");
if (fp == NULL){ /* can't open C. file! */
errent(Ct_OPEN,file,errno, __FILE__, __LINE__);
/* this may not work, but we'll try it */
/* It will fail if the C. name is more than */
/* the standard 14 characters - if this is the */
/* tocorrupt will exit with ASSERT */
toCorrupt(file);
return(0);
}
(void) fstat(fileno(fp), &stbuf);
Nstat.t_qtime = stbuf.st_mtime;
(void) strncpy(afile, BASENAME(file, '/'), NAMESIZE);
afile[NAMESIZE-1] = NULLCHAR;
*afile = BOOKMARK_PRE; /* make up name by replacing C with A */
acount = 0;
p_bookmark = fopen(afile, "r");
if (p_bookmark != NULL) {
/* get count of already completed work */
i = fscanf(p_bookmark, "%hd", &acount);
(void) fclose(p_bookmark);
if (i <= 0)
acount = 0;
/* skip lines which have already been processed */
for (i = 0; i < acount; i++) {
if (fgets(str, MAXRQST, fp) == NULL)
break;
}
}
}
if (fgets(str, MAXRQST, fp) == NULL) {
ASSERT(unlink(file) == 0, Ct_UNLINK, file, errno);
(void) unlink(afile);
DEBUG(4,"Finished Processing file: %s\n",file);
*file = '\0';
CLEAN_RETURN(fp);
/*NOTREACHED*/
}
nargs = getargs(str, wvec, wcount);
/* sanity checks for C. file */
if ((str[0] != 'R' && str[0] != 'S') /* legal wrktypes are R and S */
|| (str[0] == 'R' && nargs < 6) /* R lines need >= 6 entries */
|| (str[0] == 'S' && nargs < 7)) { /* S lines need >= 7 entries */
/* bad C. file - stash it */
toCorrupt(file);
(void) unlink(afile);
*file = '\0';
CLEAN_RETURN(fp);
/*NOTREACHED*/
}
p_bookmark = fopen(afile, "w"); /* update bookmark file */
if (p_bookmark == NULL)
errent(Ct_OPEN, afile, errno, __FILE__, __LINE__);
else {
chmod(afile, CFILEMODE);
(void) fprintf(p_bookmark, "%d", acount);
(void) fclose(p_bookmark);
}
acount++;
return(nargs);
}
/*
* Check the list of work files (C.sys).
* If it is empty or the present work is exhausted, it
* will call bldflst to generate a new list.
*
* If there are no more jobs in the current job grade,
* it will call findgrade to get the new job grade to process.
*
* file -> address of array to return full pathname in
* returns:
* 0 -> no more work (or some error)
* 1 -> there is work
*/
extern int
iswrk(file)
char *file;
{
char newspool[MAXFULLNAME];
char lockname[MAXFULLNAME];
char gradedir[2*MAXBASENAME];
if (Nfiles == 0) {
/* If Role is MASTER and JobGrade is null, then
* there is no work for the remote.
*
* In the case of uucico slave, the job grade
* to process should be determined before building
* the work list.
*/
if (Role == MASTER) {
if (*JobGrade == NULLCHAR)
return(0);
if (bldflst() != 0) {
(void) sprintf(file, "%s/%s", RemSpool, Fptr[Nnext]);
Nfiles--;
Nnext++;
return(1);
}
(void) sprintf(lockname, "%.*s.%s", SYSNSIZE, Rmtname, JobGrade);
delock(LOCKPRE, lockname);
} else {
(void) sprintf(lockname, "%ld", (long) getpid());
delock(LOCKPRE, lockname);
}
(void) sprintf(newspool, "%s/%s", SPOOL, Rmtname);
ASSERT(chdir(newspool) == 0, Ct_CHDIR, newspool, errno);
findgrade(newspool, JobGrade);
DEBUG(4, "Job grade to process - %s\n", JobGrade);
if (*JobGrade == NULLCHAR)
return(0);
(void) sprintf(lockname, "%.*s.%s", SYSNSIZE, Rmtname, JobGrade);
(void) umlock(LOCKPRE, lockname);
/* Make the new job grade directory the working directory
* and set RemSpool.
*/
(void) sprintf(gradedir, "%s/%s", Rmtname, JobGrade);
chremdir(gradedir);
bldflst();
}
(void) sprintf(file, "%s/%s", RemSpool, Fptr[Nnext]);
Nfiles--;
Nnext++;
return(1);
}
/*
* build list of work files for given system using an insertion sort
* Nfiles, Nnext, RemSpool and Rmtname are global
*
* return:
* number of C. files in list - (Nfiles)
*/
static int
bldflst()
{
DIR *pdir;
char filename[NAMESIZE];
char prefix[SYSNSIZE+3];
Nnext = Nfiles = 0;
if ((pdir = opendir(RemSpool)) == NULL)
return(0);
(void) sprintf(prefix, "C.%.*s", SYSNSIZE, Rmtname);
while (gnamef(pdir, filename) ) {
if (!PREFIX(prefix, filename))
continue;
if ((strlen(filename)-strlen(prefix)) != SUFSIZE) {
errent("bldflst: Funny filename", filename, 0,
__FILE__, __LINE__);
continue;
}
insert(filename);
}
closedir(pdir);
return(Nfiles);
}
/*
* get work return
* file -> place to deposit file name
* wrkvec -> array to return arguments
* wcount -> max number of args for wrkvec
* returns:
* nargs -> number of arguments
* 0 -> no arguments - fail
*/
extern int
gtwvec(file, wrkvec, wcount)
char *file, **wrkvec;
{
int nargs;
DEBUG(7, "gtwvec: dir %s\n", RemSpool);
while ((nargs = anlwrk(file, wrkvec, wcount)) == 0) {
if (!iswrk(file))
return(0);
}
DEBUG(7, " return - %d\n", nargs);
return(nargs);
}
/*
* insert - insert file name in sorted list
* return - none
*/
static void
insert(file)
char *file;
{
int i, j;
char *p;
DEBUG(7, "insert(%s) ", file);
for (i = Nfiles; i>0; i--) {
if (strcmp(file, Fptr[i-1]) > 0)
break;
}
if (i == LLEN) /* if this is off the end get out */
return;
/* get p (pointer) to where the text of name will go */
if (Nfiles == LLEN) /* last possible entry */
/* put in text of last and decrement Nfiles for make hole */
p = strcpy(Fptr[--Nfiles], file);
else
p = strcpy(Filent[Nfiles], file); /* copy to next free */
/* make a hole for new entry */
for (j = Nfiles; j >i; j--)
Fptr[j] = Fptr[j-1];
DEBUG(7, "insert %s ", p);
DEBUG(7, "at %d\n", i);
Fptr[i] = p;
Nfiles++;
return;
}
|