141
128
*** D A T A S T R U C T U R E S ***
142
129
*******************************************/
144
struct collstruct { /* one per collection to be upgraded */
145
char *Cname; /* collection name */
146
char *Cbase; /* local base directory */
147
char *Cprefix; /* local collection pathname prefix */
148
struct collstruct *Cnext; /* next collection */
131
struct scan_collstruct { /* one per collection to be upgraded */
132
char *Cname; /* collection name */
133
char *Cbase; /* local base directory */
134
char *Cprefix; /* local collection pathname prefix */
135
struct scan_collstruct *Cnext; /* next collection */
150
typedef struct collstruct COLLECTION;
137
typedef struct scan_collstruct SCAN_COLLECTION;
152
139
/*********************************************
153
140
*** G L O B A L V A R I A B L E S ***
154
141
*********************************************/
156
int trace; /* -v flag */
158
COLLECTION *firstC; /* collection list pointer */
159
char *collname; /* collection name */
160
char *basedir; /* base directory name */
161
char *prefix; /* collection pathname prefix */
162
long lasttime = 0; /* time of last upgrade */
163
long scantime; /* time of this scan */
164
int newonly = FALSE; /* new files only */
165
jmp_buf sjbuf; /* jump location for errors */
167
TREELIST *listTL; /* list of all files specified by <coll>.list */
168
TREE *listT; /* final list of files in collection */
169
TREE *refuseT = NULL; /* list of all files specified by <coll>.list */
143
int trace; /* -v flag */
144
int quiet; /* -q flag */
146
SCAN_COLLECTION *firstC; /* collection list pointer */
147
char *collname; /* collection name */
148
char *basedir; /* base directory name */
149
char *prefix; /* collection pathname prefix */
150
time_t lasttime = 0; /* time of last upgrade */
151
time_t scantime; /* time of this scan */
152
int newonly = FALSE; /* new files only */
153
jmp_buf sjbuf; /* jump location for errors */
155
TREELIST *listTL; /* list of all files specified by <coll>.list */
156
TREE *listT; /* final list of files in collection */
157
TREE *refuseT = NULL; /* list of all files specified by <coll>.list */
161
void init(int, char **);
162
static SCAN_COLLECTION *getscancoll(char *, char *, char *);
163
int localhost(char *);
164
int main(int, char **);
173
166
/*************************************
174
167
*** M A I N R O U T I N E ***
175
168
*************************************/
171
main(int argc, char **argv)
181
register COLLECTION *c;
183
init (argc,argv); /* process arguments */
177
if (getrlimit(RLIMIT_DATA, &dlim) == -1)
178
goaway("Error getting resource limit (%s)",
180
if (dlim.rlim_cur != dlim.rlim_max) {
181
dlim.rlim_cur = dlim.rlim_max;
182
if (setrlimit(RLIMIT_DATA, &dlim) == -1)
183
goaway("Error setting resource limit (%s)",
189
/* Avoid longjmp clobbering */
193
init(argc, argv); /* process arguments */
184
194
for (c = firstC; c; c = c->Cnext) {
185
195
collname = c->Cname;
186
196
basedir = c->Cbase;
187
197
prefix = c->Cprefix;
188
(void) chdir (basedir);
189
scantime = time ((long *)NULL);
190
printf ("SUP Scan for %s starting at %s",collname,
192
(void) fflush (stdout);
193
if (!setjmp (sjbuf)) {
194
makescanlists (); /* record names in scan files */
195
scantime = time ((long *)NULL);
196
printf ("SUP Scan for %s completed at %s",collname,
198
(void) chdir(basedir);
199
scantime = time((time_t *) NULL);
201
printf("SUP Scan for %s starting at %s", collname,
203
(void) fflush(stdout);
204
if (!setjmp(sjbuf)) {
205
makescanlists(); /* record names in scan files */
206
scantime = time((time_t *) NULL);
208
printf("SUP Scan for %s completed at %s",
209
collname, ctime(&scantime));
199
printf ("SUP: Scan for %s aborted at %s",collname,
201
(void) fflush (stdout);
212
"SUP: Scan for %s aborted at %s", collname,
215
(void) fflush(stdout);
217
while ((c = firstC) != NULL) {
204
218
firstC = firstC->Cnext;
207
if (c->Cprefix) free (c->Cprefix);
213
227
/*****************************************
214
228
*** I N I T I A L I Z A T I O N ***
215
229
*****************************************/
219
fprintf (stderr,"Usage: supscan [ -v ] collection [ basedir ]\n");
220
fprintf (stderr," supscan [ -v ] -f dirfile\n");
221
fprintf (stderr," supscan [ -v ] -s\n");
234
fprintf(stderr, "Usage: supscan [ -vq ] collection [ basedir ]\n");
235
fprintf(stderr, " supscan [ -vq ] -f dirfile\n");
236
fprintf(stderr, " supscan [ -vq ] -s\n");
241
init(int argc, char **argv)
229
char buf[STRINGLENGTH],fbuf[STRINGLENGTH],*p,*q;
243
char buf[STRINGLENGTH], fbuf[STRINGLENGTH], *p, *q;
231
COLLECTION **c, *getcoll();
247
char *filename = NULL;
255
fprintf (stderr,"supscan: Invalid flag %s ignored\n",argv[1]);
256
(void) fflush (stderr);
273
fprintf(stderr, "supscan: Invalid flag %s ignored\n",
275
(void) fflush(stderr);
262
(void) sprintf (fbuf,FILEDIRS,DEFDIR);
281
(void) sprintf(fbuf, FILEDIRS, DEFDIR);
270
(void) sprintf (buf,FILEHOSTS,DEFDIR);
271
if ((f = fopen (buf,"r")) == NULL)
272
quit (1,"supscan: Unable to open %s\n",buf);
273
while ((p = fgets (buf,STRINGLENGTH,f)) != NULL) {
276
if (index ("#;:",*p)) continue;
277
collname = nxtarg (&p," \t=");
278
p = skipover (p," \t=");
279
if (!localhost (p)) continue;
280
*c = getcoll(filename,salloc (collname),
282
if (*c) c = &((*c)->Cnext);
289
(void) sprintf(buf, FILEHOSTS, DEFDIR);
290
if ((f = fopen(buf, "r")) == NULL)
291
quit(1, "supscan: Unable to open %s\n", buf);
292
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
296
if (index("#;:", *p))
298
collname = nxtarg(&p, " \t=");
299
p = skipover(p, " \t=");
302
*c = getscancoll(filename, estrdup(collname),
287
310
if (argc < 2 && fflag) {
290
if ((f = fopen (filename,"r")) == NULL)
291
quit (1,"supscan: Unable to open %s\n",filename);
292
while (p = fgets (buf,STRINGLENGTH,f)) {
295
if (index ("#;:",*p)) continue;
296
q = nxtarg (&p," \t=");
297
p = skipover (p," \t=");
298
*c = getcoll(filename,salloc (q),salloc (p));
299
if (*c) c = &((*c)->Cnext);
313
if ((f = fopen(filename, "r")) == NULL)
314
quit(1, "supscan: Unable to open %s\n", filename);
315
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
319
if (index("#;:", *p))
321
q = nxtarg(&p, " \t=");
322
p = skipover(p, " \t=");
323
*c = getscancoll(filename, estrdup(q), estrdup(p));
304
330
if (argc < 2 || argc > 3)
306
firstC = getcoll(filename,salloc (argv[1]),
307
argc > 2 ? salloc (argv[2]) : (char *)NULL);
332
firstC = getscancoll(filename, estrdup(argv[1]),
333
argc > 2 ? estrdup(argv[2]) : (char *) NULL);
311
getcoll(filename, collname, basedir)
312
register char *filename,*collname,*basedir;
336
static SCAN_COLLECTION *
337
getscancoll(char *filename, char *collname, char *basedir)
314
char buf[STRINGLENGTH],*p,*q;
339
char buf[STRINGLENGTH], *p, *q;
318
343
if (basedir == NULL) {
319
if (f = fopen (filename,"r")) {
320
while (p = fgets (buf,STRINGLENGTH,f)) {
323
if (index ("#;:",*p)) continue;
324
q = nxtarg (&p," \t=");
325
if (strcmp (q,collname) == 0) {
326
p = skipover (p," \t=");
327
basedir = salloc (p);
344
if ((f = fopen(filename, "r")) != NULL) {
345
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
349
if (index("#;:", *p))
351
q = nxtarg(&p, " \t=");
352
if (strcmp(q, collname) == 0) {
353
p = skipover(p, " \t=");
354
basedir = estrdup(p);
333
360
if (basedir == NULL) {
334
(void) sprintf (buf,FILEBASEDEFAULT,collname);
335
basedir = salloc (buf);
361
(void) sprintf(buf, FILEBASEDEFAULT, collname);
362
basedir = estrdup(buf);
338
365
if (chdir(basedir) < 0) {
339
fprintf (stderr,"supscan: Can't chdir to base directory %s for %s\n",
366
fprintf(stderr, "supscan: Can't chdir to base directory %s for %s\n",
344
(void) sprintf (buf,FILEPREFIX,collname);
345
if (f = fopen (buf,"r")) {
346
while (p = fgets (buf,STRINGLENGTH,f)) {
349
if (index ("#;:",*p)) continue;
371
(void) sprintf(buf, FILEPREFIX, collname);
372
if ((f = fopen(buf, "r")) != NULL) {
373
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
377
if (index("#;:", *p))
351
380
if (chdir(prefix) < 0) {
352
fprintf (stderr,"supscan: can't chdir to %s from base directory %s for %s\n",
353
prefix,basedir,collname);
381
fprintf(stderr, "supscan: can't chdir to %s from base directory %s for %s\n",
382
prefix, basedir, collname);
360
if ((c = (COLLECTION *) malloc (sizeof(COLLECTION))) == NULL)
361
quit (1,"supscan: can't malloc collection structure\n");
391
if ((c = (SCAN_COLLECTION *) malloc(sizeof(SCAN_COLLECTION))) == NULL)
392
quit(1, "supscan: can't malloc collection structure\n");
362
393
c->Cname = collname;
363
394
c->Cbase = basedir;
364
395
c->Cprefix = prefix;
369
goaway (char *fmt,...)
371
/*VARARGS*//*ARGSUSED*/
401
goaway(char *fmt, ...)
385
fmt = va_arg(ap,char *);
388
406
vfprintf(stderr, fmt, ap);
390
(void) putc ('\n',stderr);
391
(void) fflush (stderr);
392
longjmp (sjbuf,TRUE);
408
(void) putc('\n', stderr);
409
(void) fflush(stderr);
410
longjmp(sjbuf, TRUE);
414
localhost(char *host)
398
static char myhost[STRINGLENGTH];
399
static int myhostlen;
400
register int hostlen;
416
static char myhost[MAXHOSTNAMELEN + 1];
417
static unsigned int myhostlen;
418
unsigned int hostlen;
402
420
if (*myhost == '\0') {
404
422
* We assume that the host name in the kernel is the
405
423
* fully qualified form.
407
if (gethostname (myhost,sizeof (myhost)) < 0) {
408
quit (1,"supscan: can't get kernel host name\n");
425
if (gethostname(myhost, sizeof(myhost)) < 0) {
426
quit(1, "supscan: can't get kernel host name\n");
428
myhost[sizeof(myhost) - 1] = '\0';
410
429
myhostlen = strlen(myhost);
414
432
* Here, we assume that the 'host' parameter from the
415
433
* coll.host file is at least a prefix of the fully qualified