xref: /csrg-svn/libexec/bugfiler/error.c (revision 30161)
1*30161Sbostic /*
2*30161Sbostic  * Copyright (c) 1986 Regents of the University of California.
3*30161Sbostic  * All rights reserved.  The Berkeley software License Agreement
4*30161Sbostic  * specifies the terms and conditions for redistribution.
5*30161Sbostic  */
6*30161Sbostic 
7*30161Sbostic #ifndef lint
8*30161Sbostic static char sccsid[] = "@(#)error.c	5.1 (Berkeley) 86/11/25";
9*30161Sbostic #endif not lint
10*30161Sbostic 
11*30161Sbostic #include <syslog.h>
12*30161Sbostic #include <stdio.h>
13*30161Sbostic #include <bug.h>
14*30161Sbostic 
15*30161Sbostic extern char	*distf,				/* redist temp file */
16*30161Sbostic 		tmpname[];			/* temporary file used */
17*30161Sbostic 
18*30161Sbostic short	made_dist;				/* if dist file made */
19*30161Sbostic 
20*30161Sbostic static short	err_redir;			/* stderr redirected */
21*30161Sbostic 
22*30161Sbostic /*
23*30161Sbostic  * seterr --
24*30161Sbostic  *	redirect stderr for error processing
25*30161Sbostic  */
26*30161Sbostic seterr()
27*30161Sbostic {
28*30161Sbostic 	if (!freopen(ERROR_FILE,"a",stderr))
29*30161Sbostic 		error("unable to open error file %s.\n",ERROR_FILE);
30*30161Sbostic 	err_redir = YES;
31*30161Sbostic }
32*30161Sbostic 
33*30161Sbostic /*
34*30161Sbostic  * error --
35*30161Sbostic  *	write errors to log file and die
36*30161Sbostic  */
37*30161Sbostic error(fmt,arg)
38*30161Sbostic register char	*fmt,
39*30161Sbostic 		*arg;
40*30161Sbostic {
41*30161Sbostic 	static char	logmsg[MAXLINELEN];	/* syslog message */
42*30161Sbostic 	char	*strcpy(), *strcat();
43*30161Sbostic 
44*30161Sbostic 	if (err_redir) {
45*30161Sbostic 		/* don't combine these, "fmt" may not require "arg" */
46*30161Sbostic 		fputc('\t',stderr);
47*30161Sbostic 		fprintf(stderr,fmt,arg);
48*30161Sbostic 		fprintf(stderr,"\n\ttemporary file is %s.\n",tmpname);
49*30161Sbostic 	}
50*30161Sbostic 	else {
51*30161Sbostic 		strcat(strcpy(logmsg,"bugfiler: "),fmt);
52*30161Sbostic 		syslog(LOG_ERR,logmsg,arg);
53*30161Sbostic 	}
54*30161Sbostic 	if (made_dist)		/* unlink redist file if necessary */
55*30161Sbostic 		unlink(distf);
56*30161Sbostic #ifdef METOO
57*30161Sbostic 	exit(ERR);
58*30161Sbostic #else !METOO
59*30161Sbostic 	exit(OK);
60*30161Sbostic #endif METOO
61*30161Sbostic }
62