xref: /csrg-svn/libexec/bugfiler/error.c (revision 31918)
130161Sbostic /*
230161Sbostic  * Copyright (c) 1986 Regents of the University of California.
330161Sbostic  * All rights reserved.  The Berkeley software License Agreement
430161Sbostic  * specifies the terms and conditions for redistribution.
530161Sbostic  */
630161Sbostic 
730161Sbostic #ifndef lint
8*31918Sbostic static char sccsid[] = "@(#)error.c	5.4 (Berkeley) 87/07/21";
930161Sbostic #endif not lint
1030161Sbostic 
1130890Sbostic #include <bug.h>
1230161Sbostic #include <syslog.h>
1330161Sbostic #include <stdio.h>
1430161Sbostic 
1530161Sbostic static short	err_redir;			/* stderr redirected */
1630161Sbostic 
1730161Sbostic /*
1830161Sbostic  * seterr --
1930161Sbostic  *	redirect stderr for error processing
2030161Sbostic  */
2130161Sbostic seterr()
2230161Sbostic {
2330890Sbostic 	if (!freopen(ERROR_FILE, "a", stderr))
24*31918Sbostic 		error("can't open error file %s.", ERROR_FILE);
2530161Sbostic 	err_redir = YES;
2630161Sbostic }
2730161Sbostic 
2830161Sbostic /*
2930161Sbostic  * error --
3030161Sbostic  *	write errors to log file and die
3130161Sbostic  */
3230890Sbostic error(fmt, arg)
3330890Sbostic 	register char	*fmt,
3430890Sbostic 			*arg;
3530161Sbostic {
3630161Sbostic 	static char	logmsg[MAXLINELEN];	/* syslog message */
3730161Sbostic 	char	*strcpy(), *strcat();
3830161Sbostic 
3930161Sbostic 	if (err_redir) {
4030161Sbostic 		/* don't combine these, "fmt" may not require "arg" */
41*31918Sbostic 		fprintf(stderr, "\t%s\n\t", tmpname);
4230890Sbostic 		fprintf(stderr, fmt, arg);
43*31918Sbostic 		fputc('\n', stderr);
4430161Sbostic 	}
4530161Sbostic 	else {
4630890Sbostic 		sprintf(logmsg, "bugfiler: %s", fmt);
4730890Sbostic 		syslog(LOG_ERR, logmsg, arg);
4830161Sbostic 	}
4930161Sbostic #ifdef METOO
5030161Sbostic 	exit(ERR);
5130890Sbostic #else
5230161Sbostic 	exit(OK);
5330890Sbostic #endif
5430161Sbostic }
55