xref: /csrg-svn/libexec/bugfiler/error.c (revision 61420)
130161Sbostic /*
2*61420Sbostic  * Copyright (c) 1986, 1987, 1993
3*61420Sbostic  *	The Regents of the University of California.  All rights reserved.
433416Sbostic  *
542663Sbostic  * %sccs.include.redist.c%
630161Sbostic  */
730161Sbostic 
830161Sbostic #ifndef lint
9*61420Sbostic static char sccsid[] = "@(#)error.c	8.1 (Berkeley) 06/04/93";
1033416Sbostic #endif /* not lint */
1130161Sbostic 
1246667Sbostic #include <sys/param.h>
1360083Sbostic 
1446667Sbostic #include <dirent.h>
1530161Sbostic #include <stdio.h>
1646667Sbostic #include <stdlib.h>
1760083Sbostic #include <string.h>
1860083Sbostic #include <syslog.h>
1960083Sbostic 
2046667Sbostic #include "bug.h"
2160083Sbostic #include "extern.h"
2230161Sbostic 
2330161Sbostic static short	err_redir;			/* stderr redirected */
2430161Sbostic 
2530161Sbostic /*
2630161Sbostic  * seterr --
2730161Sbostic  *	redirect stderr for error processing
2830161Sbostic  */
2960083Sbostic void
seterr()3030161Sbostic seterr()
3130161Sbostic {
3230890Sbostic 	if (!freopen(ERROR_FILE, "a", stderr))
3331918Sbostic 		error("can't open error file %s.", ERROR_FILE);
3430161Sbostic 	err_redir = YES;
3530161Sbostic }
3630161Sbostic 
3730161Sbostic /*
3830161Sbostic  * error --
3930161Sbostic  *	write errors to log file and die
4030161Sbostic  */
4160083Sbostic void
error(fmt,arg)4230890Sbostic error(fmt, arg)
4330890Sbostic 	register char	*fmt,
4430890Sbostic 			*arg;
4530161Sbostic {
4630161Sbostic 	static char	logmsg[MAXLINELEN];	/* syslog message */
4730161Sbostic 
4830161Sbostic 	if (err_redir) {
4930161Sbostic 		/* don't combine these, "fmt" may not require "arg" */
5031918Sbostic 		fprintf(stderr, "\t%s\n\t", tmpname);
5130890Sbostic 		fprintf(stderr, fmt, arg);
5231918Sbostic 		fputc('\n', stderr);
5330161Sbostic 	}
5430161Sbostic 	else {
5530890Sbostic 		sprintf(logmsg, "bugfiler: %s", fmt);
5630890Sbostic 		syslog(LOG_ERR, logmsg, arg);
5730161Sbostic 	}
5830161Sbostic #ifdef METOO
5930161Sbostic 	exit(ERR);
6030890Sbostic #else
6130161Sbostic 	exit(OK);
6230890Sbostic #endif
6330161Sbostic }
64