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