xref: /csrg-svn/libexec/bugfiler/process.c (revision 30425)
130163Sbostic /*
230163Sbostic  * Copyright (c) 1986 Regents of the University of California.
330163Sbostic  * All rights reserved.  The Berkeley software License Agreement
430163Sbostic  * specifies the terms and conditions for redistribution.
530163Sbostic  */
630163Sbostic 
730163Sbostic #ifndef lint
8*30425Sbostic static char sccsid[] = "@(#)process.c	5.2 (Berkeley) 87/01/28";
930163Sbostic #endif not lint
1030163Sbostic 
1130163Sbostic #include <bug.h>
1230163Sbostic #include <sys/file.h>
1330163Sbostic #include <sys/dir.h>
14*30425Sbostic #include <sys/time.h>
1530163Sbostic #include <stdio.h>
1630163Sbostic 
1730163Sbostic extern HEADER	mailhead[];			/* mail headers */
1830163Sbostic extern int	lfd;				/* lock file descriptor */
1930163Sbostic extern char	dir[],				/* directory */
2030163Sbostic 		folder[];			/* sub-directory */
2130163Sbostic 
2230163Sbostic char	pfile[MAXPATHLEN];			/* permanent file name */
2330163Sbostic 
2430163Sbostic /*
2530163Sbostic  * process --
2630163Sbostic  *	process a bug report
2730163Sbostic  */
2830163Sbostic process()
2930163Sbostic {
3030163Sbostic 	register int	rval;			/* read return value */
31*30425Sbostic 	struct timeval	tp;			/* time of day */
32*30425Sbostic 	struct timezone	tzp;
33*30425Sbostic 	char	*ctime();
3430163Sbostic 
3530163Sbostic 	/* copy report to permanent file */
3630163Sbostic 	sprintf(pfile,"%s/%s/%d",dir,folder,getnext());
3730163Sbostic 	fprintf(stderr,"\t%s\n",pfile);
3830163Sbostic 	if (!(freopen(pfile,"w",stdout)))
3930163Sbostic 		error("unable to create permanent bug file %s.",pfile);
4030163Sbostic 	rewind(stdin);
4130163Sbostic 	while ((rval = read(fileno(stdin),bfr,sizeof(bfr))) != ERR && rval)
4230163Sbostic 		write(fileno(stdout),bfr,rval);
4330163Sbostic 	REL_LOCK;
4430163Sbostic 
4530163Sbostic 	/* append information to the summary file */
4630163Sbostic 	sprintf(bfr,"%s/%s",dir,SUMMARY_FILE);
4730163Sbostic 	GET_LOCK;
4830163Sbostic 	if (!(freopen(bfr,"a",stdout)))
4930163Sbostic 		error("unable to append to summary file %s.",bfr);
50*30425Sbostic 	else {
51*30425Sbostic 		if (gettimeofday(&tp,&tzp))
52*30425Sbostic 			error("unable to get time of day.",CHN);
53*30425Sbostic 		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*30425Sbostic 	}
5530163Sbostic 	REL_LOCK;
5630163Sbostic 	fclose(stdout);
5730163Sbostic }
5830163Sbostic 
5930163Sbostic /*
6030163Sbostic  * getnext --
6130163Sbostic  *	get next file name (number)
6230163Sbostic  */
6330163Sbostic static
6430163Sbostic getnext()
6530163Sbostic {
6630163Sbostic 	register struct direct	*d;		/* directory structure */
6730163Sbostic 	register DIR	*dirp;			/* directory pointer */
6830163Sbostic 	register int	n;			/* number values */
6930163Sbostic 
7030163Sbostic 	GET_LOCK;
7130163Sbostic 	sprintf(bfr,"%s/%s",dir,folder);
7230163Sbostic 	if (!(dirp = opendir(bfr))) {
7330163Sbostic 		REL_LOCK;
7430163Sbostic 		error("unable to read folder directory %s.",bfr);
7530163Sbostic 	}
7630163Sbostic 	for (n = 0;d = readdir(dirp);)
7730163Sbostic 		n = MAX(n,atoi(d->d_name));
7830163Sbostic 	closedir(dirp);
7930163Sbostic 	return(++n);
8030163Sbostic }
81