4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 This module contains routines that find C. files
34 in a system spool directory, return the next C. file
35 to process, and break up the C. line into arguments
41 #define BOOKMARK_PRE 'A'
42 #define CLEAN_RETURN(fp) {\
50 /* C.princetN0026 - ('C' + '.') - "princet" */
51 #define SUFSIZE (MAXBASENAME - 2 - SYSNSIZE)
56 static int anlwrk(), bldflst();
57 extern int iswrk(), gtwvec(), gnamef();
59 static char Filent
[LLEN
][NAMESIZE
]; /* array of C. file names (text) */
60 static char *Fptr
[LLEN
]; /* pointers to names in Filent */
61 static short Nnext
; /* index of next C. file in Fptr list */
62 static short Nfiles
= 0; /* Number of files in Filent */
65 * read a line from the workfile (C.file)
66 * file -> work file (Input/Output) made '\0' after work completion
67 * wvec -> address of array to return arguments (Output)
68 * wcount -> maximum # of arguments to return in wvec
69 * NOTE: wvec should be large enough to accept wcount + 1 pointers
70 * since NULL is inserted after last item.
72 * 0 -> no more work in this file
73 * positive # -> number of arguments
76 anlwrk(file
, wvec
, wcount
)
80 FILE *p_bookmark
; /* pointer to afile */
81 static FILE *fp
= NULL
; /* currently opened C. file pointer */
82 static char afile
[NAMESIZE
]; /* file with line count for book marks */
83 static char str
[MAXRQST
]; /* the string which wvec points to */
86 int nargs
; /* return value == # args in the line */
88 if (file
[0] == '\0') {
91 "attempt made to use old workfile was thwarted", 0,
97 fp
= fopen(file
, "r");
99 if (fp
== NULL
){ /* can't open C. file! */
100 errent(Ct_OPEN
,file
,errno
, __FILE__
, __LINE__
);
101 /* this may not work, but we'll try it */
102 /* It will fail if the C. name is more than */
103 /* the standard 14 characters - if this is the */
104 /* tocorrupt will exit with ASSERT */
108 (void) fstat(fileno(fp
), &stbuf
);
109 Nstat
.t_qtime
= stbuf
.st_mtime
;
111 (void) strncpy(afile
, BASENAME(file
, '/'), NAMESIZE
);
112 afile
[NAMESIZE
-1] = NULLCHAR
;
113 *afile
= BOOKMARK_PRE
; /* make up name by replacing C with A */
115 p_bookmark
= fopen(afile
, "r");
116 if (p_bookmark
!= NULL
) {
117 /* get count of already completed work */
118 i
= fscanf(p_bookmark
, "%hd", &acount
);
119 (void) fclose(p_bookmark
);
123 /* skip lines which have already been processed */
124 for (i
= 0; i
< acount
; i
++) {
125 if (fgets(str
, MAXRQST
, fp
) == NULL
)
132 if (fgets(str
, MAXRQST
, fp
) == NULL
) {
133 ASSERT(unlink(file
) == 0, Ct_UNLINK
, file
, errno
);
134 (void) unlink(afile
);
135 DEBUG(4,"Finished Processing file: %s\n",file
);
141 nargs
= getargs(str
, wvec
, wcount
);
143 /* sanity checks for C. file */
144 if ((str
[0] != 'R' && str
[0] != 'S') /* legal wrktypes are R and S */
145 || (str
[0] == 'R' && nargs
< 6) /* R lines need >= 6 entries */
146 || (str
[0] == 'S' && nargs
< 7)) { /* S lines need >= 7 entries */
147 /* bad C. file - stash it */
149 (void) unlink(afile
);
155 p_bookmark
= fopen(afile
, "w"); /* update bookmark file */
156 if (p_bookmark
== NULL
)
157 errent(Ct_OPEN
, afile
, errno
, __FILE__
, __LINE__
);
159 chmod(afile
, CFILEMODE
);
160 (void) fprintf(p_bookmark
, "%d", acount
);
161 (void) fclose(p_bookmark
);
168 * Check the list of work files (C.sys).
169 * If it is empty or the present work is exhausted, it
170 * will call bldflst to generate a new list.
172 * If there are no more jobs in the current job grade,
173 * it will call findgrade to get the new job grade to process.
175 * file -> address of array to return full pathname in
177 * 0 -> no more work (or some error)
184 char newspool
[MAXFULLNAME
];
185 char lockname
[MAXFULLNAME
];
186 char gradedir
[2*MAXBASENAME
];
189 /* If Role is MASTER and JobGrade is null, then
190 * there is no work for the remote.
192 * In the case of uucico slave, the job grade
193 * to process should be determined before building
196 if (Role
== MASTER
) {
197 if (*JobGrade
== NULLCHAR
)
200 if (bldflst() != 0) {
201 (void) sprintf(file
, "%s/%s", RemSpool
, Fptr
[Nnext
]);
206 (void) sprintf(lockname
, "%.*s.%s", SYSNSIZE
, Rmtname
, JobGrade
);
207 delock(LOCKPRE
, lockname
);
209 (void) sprintf(lockname
, "%ld", (long) getpid());
210 delock(LOCKPRE
, lockname
);
213 (void) sprintf(newspool
, "%s/%s", SPOOL
, Rmtname
);
214 ASSERT(chdir(newspool
) == 0, Ct_CHDIR
, newspool
, errno
);
216 findgrade(newspool
, JobGrade
);
217 DEBUG(4, "Job grade to process - %s\n", JobGrade
);
218 if (*JobGrade
== NULLCHAR
)
221 (void) sprintf(lockname
, "%.*s.%s", SYSNSIZE
, Rmtname
, JobGrade
);
222 (void) umlock(LOCKPRE
, lockname
);
224 /* Make the new job grade directory the working directory
227 (void) sprintf(gradedir
, "%s/%s", Rmtname
, JobGrade
);
232 (void) sprintf(file
, "%s/%s", RemSpool
, Fptr
[Nnext
]);
240 * build list of work files for given system using an insertion sort
241 * Nfiles, Nnext, RemSpool and Rmtname are global
244 * number of C. files in list - (Nfiles)
250 char filename
[NAMESIZE
];
251 char prefix
[SYSNSIZE
+3];
254 if ((pdir
= opendir(RemSpool
)) == NULL
)
257 (void) sprintf(prefix
, "C.%.*s", SYSNSIZE
, Rmtname
);
258 while (gnamef(pdir
, filename
) ) {
259 if (!PREFIX(prefix
, filename
))
261 if ((strlen(filename
)-strlen(prefix
)) != SUFSIZE
) {
262 errent("bldflst: Funny filename", filename
, 0,
274 * file -> place to deposit file name
275 * wrkvec -> array to return arguments
276 * wcount -> max number of args for wrkvec
278 * nargs -> number of arguments
279 * 0 -> no arguments - fail
282 gtwvec(file
, wrkvec
, wcount
)
283 char *file
, **wrkvec
;
287 DEBUG(7, "gtwvec: dir %s\n", RemSpool
);
288 while ((nargs
= anlwrk(file
, wrkvec
, wcount
)) == 0) {
292 DEBUG(7, " return - %d\n", nargs
);
298 * insert - insert file name in sorted list
308 DEBUG(7, "insert(%s) ", file
);
309 for (i
= Nfiles
; i
>0; i
--) {
310 if (strcmp(file
, Fptr
[i
-1]) > 0)
313 if (i
== LLEN
) /* if this is off the end get out */
316 /* get p (pointer) to where the text of name will go */
317 if (Nfiles
== LLEN
) /* last possible entry */
318 /* put in text of last and decrement Nfiles for make hole */
319 p
= strcpy(Fptr
[--Nfiles
], file
);
321 p
= strcpy(Filent
[Nfiles
], file
); /* copy to next free */
323 /* make a hole for new entry */
324 for (j
= Nfiles
; j
>i
; j
--)
327 DEBUG(7, "insert %s ", p
);
328 DEBUG(7, "at %d\n", i
);