1 /* 2 * Copyright (c) 1986 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #ifndef lint 8 static char sccsid[] = "@(#)process.c 5.2 (Berkeley) 87/01/28"; 9 #endif not lint 10 11 #include <bug.h> 12 #include <sys/file.h> 13 #include <sys/dir.h> 14 #include <sys/time.h> 15 #include <stdio.h> 16 17 extern HEADER mailhead[]; /* mail headers */ 18 extern int lfd; /* lock file descriptor */ 19 extern char dir[], /* directory */ 20 folder[]; /* sub-directory */ 21 22 char pfile[MAXPATHLEN]; /* permanent file name */ 23 24 /* 25 * process -- 26 * process a bug report 27 */ 28 process() 29 { 30 register int rval; /* read return value */ 31 struct timeval tp; /* time of day */ 32 struct timezone tzp; 33 char *ctime(); 34 35 /* copy report to permanent file */ 36 sprintf(pfile,"%s/%s/%d",dir,folder,getnext()); 37 fprintf(stderr,"\t%s\n",pfile); 38 if (!(freopen(pfile,"w",stdout))) 39 error("unable to create permanent bug file %s.",pfile); 40 rewind(stdin); 41 while ((rval = read(fileno(stdin),bfr,sizeof(bfr))) != ERR && rval) 42 write(fileno(stdout),bfr,rval); 43 REL_LOCK; 44 45 /* append information to the summary file */ 46 sprintf(bfr,"%s/%s",dir,SUMMARY_FILE); 47 GET_LOCK; 48 if (!(freopen(bfr,"a",stdout))) 49 error("unable to append to summary file %s.",bfr); 50 else { 51 if (gettimeofday(&tp,&tzp)) 52 error("unable to get time of day.",CHN); 53 printf("\n%s\t\t%s\t%s\t%s\tOwner: Bugs Bunny\n\tComment: Received\n",pfile,ctime(&tp.tv_sec),mailhead[INDX_TAG].line,mailhead[SUBJ_TAG].found ? mailhead[SUBJ_TAG].line : "Subject:\n"); 54 } 55 REL_LOCK; 56 fclose(stdout); 57 } 58 59 /* 60 * getnext -- 61 * get next file name (number) 62 */ 63 static 64 getnext() 65 { 66 register struct direct *d; /* directory structure */ 67 register DIR *dirp; /* directory pointer */ 68 register int n; /* number values */ 69 70 GET_LOCK; 71 sprintf(bfr,"%s/%s",dir,folder); 72 if (!(dirp = opendir(bfr))) { 73 REL_LOCK; 74 error("unable to read folder directory %s.",bfr); 75 } 76 for (n = 0;d = readdir(dirp);) 77 n = MAX(n,atoi(d->d_name)); 78 closedir(dirp); 79 return(++n); 80 } 81