xref: /original-bsd/libexec/bugfiler/error.c (revision 92e05a12)
1c5dbc634Sbostic /*
2*92e05a12Sbostic  * Copyright (c) 1986, 1987, 1993
3*92e05a12Sbostic  *	The Regents of the University of California.  All rights reserved.
437c8c8e2Sbostic  *
56472dbc6Sbostic  * %sccs.include.redist.c%
6c5dbc634Sbostic  */
7c5dbc634Sbostic 
8c5dbc634Sbostic #ifndef lint
9*92e05a12Sbostic static char sccsid[] = "@(#)error.c	8.1 (Berkeley) 06/04/93";
1037c8c8e2Sbostic #endif /* not lint */
11c5dbc634Sbostic 
12054717d4Sbostic #include <sys/param.h>
13c48498dbSbostic 
14054717d4Sbostic #include <dirent.h>
15c5dbc634Sbostic #include <stdio.h>
16054717d4Sbostic #include <stdlib.h>
17c48498dbSbostic #include <string.h>
18c48498dbSbostic #include <syslog.h>
19c48498dbSbostic 
20054717d4Sbostic #include "bug.h"
21c48498dbSbostic #include "extern.h"
22c5dbc634Sbostic 
23c5dbc634Sbostic static short	err_redir;			/* stderr redirected */
24c5dbc634Sbostic 
25c5dbc634Sbostic /*
26c5dbc634Sbostic  * seterr --
27c5dbc634Sbostic  *	redirect stderr for error processing
28c5dbc634Sbostic  */
29c48498dbSbostic void
seterr()30c5dbc634Sbostic seterr()
31c5dbc634Sbostic {
32c5dbc634Sbostic 	if (!freopen(ERROR_FILE, "a", stderr))
33c6ed2341Sbostic 		error("can't open error file %s.", ERROR_FILE);
34c5dbc634Sbostic 	err_redir = YES;
35c5dbc634Sbostic }
36c5dbc634Sbostic 
37c5dbc634Sbostic /*
38c5dbc634Sbostic  * error --
39c5dbc634Sbostic  *	write errors to log file and die
40c5dbc634Sbostic  */
41c48498dbSbostic void
error(fmt,arg)42c5dbc634Sbostic error(fmt, arg)
43c5dbc634Sbostic 	register char	*fmt,
44c5dbc634Sbostic 			*arg;
45c5dbc634Sbostic {
46c5dbc634Sbostic 	static char	logmsg[MAXLINELEN];	/* syslog message */
47c5dbc634Sbostic 
48c5dbc634Sbostic 	if (err_redir) {
49c5dbc634Sbostic 		/* don't combine these, "fmt" may not require "arg" */
50c6ed2341Sbostic 		fprintf(stderr, "\t%s\n\t", tmpname);
51c5dbc634Sbostic 		fprintf(stderr, fmt, arg);
52c6ed2341Sbostic 		fputc('\n', stderr);
53c5dbc634Sbostic 	}
54c5dbc634Sbostic 	else {
553212f6deSbostic 		sprintf(logmsg, "bugfiler: %s", fmt);
56c5dbc634Sbostic 		syslog(LOG_ERR, logmsg, arg);
57c5dbc634Sbostic 	}
58c5dbc634Sbostic #ifdef METOO
59c5dbc634Sbostic 	exit(ERR);
603212f6deSbostic #else
61c5dbc634Sbostic 	exit(OK);
623212f6deSbostic #endif
63c5dbc634Sbostic }
64