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