xref: /csrg-svn/libexec/bugfiler/error.c (revision 30891)
1 /*
2  * Copyright (c) 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)error.c	5.3 (Berkeley) 87/04/11";
9 #endif not lint
10 
11 #include <bug.h>
12 #include <syslog.h>
13 #include <stdio.h>
14 
15 static short	err_redir;			/* stderr redirected */
16 
17 /*
18  * seterr --
19  *	redirect stderr for error processing
20  */
21 seterr()
22 {
23 	if (!freopen(ERROR_FILE, "a", stderr))
24 		error("can't open error file %s.\n", ERROR_FILE);
25 	err_redir = YES;
26 }
27 
28 /*
29  * error --
30  *	write errors to log file and die
31  */
32 error(fmt, arg)
33 	register char	*fmt,
34 			*arg;
35 {
36 	static char	logmsg[MAXLINELEN];	/* syslog message */
37 	char	*strcpy(), *strcat();
38 
39 	if (err_redir) {
40 		/* don't combine these, "fmt" may not require "arg" */
41 		fputc('\t', stderr);
42 		fprintf(stderr, fmt, arg);
43 		fprintf(stderr, "\n\ttemporary file is %s.\n", tmpname);
44 	}
45 	else {
46 		sprintf(logmsg, "bugfiler: %s", fmt);
47 		syslog(LOG_ERR, logmsg, arg);
48 	}
49 #ifdef METOO
50 	exit(ERR);
51 #else
52 	exit(OK);
53 #endif
54 }
55