xref: /csrg-svn/libexec/bugfiler/error.c (revision 33416)
130161Sbostic /*
2*33416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
3*33416Sbostic  * All rights reserved.
4*33416Sbostic  *
5*33416Sbostic  * Redistribution and use in source and binary forms are permitted
6*33416Sbostic  * provided that this notice is preserved and that due credit is given
7*33416Sbostic  * to the University of California at Berkeley. The name of the University
8*33416Sbostic  * may not be used to endorse or promote products derived from this
9*33416Sbostic  * software without specific prior written permission. This software
10*33416Sbostic  * is provided ``as is'' without express or implied warranty.
1130161Sbostic  */
1230161Sbostic 
1330161Sbostic #ifndef lint
14*33416Sbostic static char sccsid[] = "@(#)error.c	5.5 (Berkeley) 02/01/88";
15*33416Sbostic #endif /* not lint */
1630161Sbostic 
1730890Sbostic #include <bug.h>
1830161Sbostic #include <syslog.h>
1930161Sbostic #include <stdio.h>
2030161Sbostic 
2130161Sbostic static short	err_redir;			/* stderr redirected */
2230161Sbostic 
2330161Sbostic /*
2430161Sbostic  * seterr --
2530161Sbostic  *	redirect stderr for error processing
2630161Sbostic  */
2730161Sbostic seterr()
2830161Sbostic {
2930890Sbostic 	if (!freopen(ERROR_FILE, "a", stderr))
3031918Sbostic 		error("can't open error file %s.", ERROR_FILE);
3130161Sbostic 	err_redir = YES;
3230161Sbostic }
3330161Sbostic 
3430161Sbostic /*
3530161Sbostic  * error --
3630161Sbostic  *	write errors to log file and die
3730161Sbostic  */
3830890Sbostic error(fmt, arg)
3930890Sbostic 	register char	*fmt,
4030890Sbostic 			*arg;
4130161Sbostic {
4230161Sbostic 	static char	logmsg[MAXLINELEN];	/* syslog message */
4330161Sbostic 	char	*strcpy(), *strcat();
4430161Sbostic 
4530161Sbostic 	if (err_redir) {
4630161Sbostic 		/* don't combine these, "fmt" may not require "arg" */
4731918Sbostic 		fprintf(stderr, "\t%s\n\t", tmpname);
4830890Sbostic 		fprintf(stderr, fmt, arg);
4931918Sbostic 		fputc('\n', stderr);
5030161Sbostic 	}
5130161Sbostic 	else {
5230890Sbostic 		sprintf(logmsg, "bugfiler: %s", fmt);
5330890Sbostic 		syslog(LOG_ERR, logmsg, arg);
5430161Sbostic 	}
5530161Sbostic #ifdef METOO
5630161Sbostic 	exit(ERR);
5730890Sbostic #else
5830161Sbostic 	exit(OK);
5930890Sbostic #endif
6030161Sbostic }
61