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.8 (Berkeley) 02/25/91"; 10 #endif /* not lint */ 11 12 #include <sys/param.h> 13 #include <dirent.h> 14 #include <syslog.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include "bug.h" 18 19 static short err_redir; /* stderr redirected */ 20 21 /* 22 * seterr -- 23 * redirect stderr for error processing 24 */ 25 seterr() 26 { 27 if (!freopen(ERROR_FILE, "a", stderr)) 28 error("can't open error file %s.", ERROR_FILE); 29 err_redir = YES; 30 } 31 32 /* 33 * error -- 34 * write errors to log file and die 35 */ 36 error(fmt, arg) 37 register char *fmt, 38 *arg; 39 { 40 static char logmsg[MAXLINELEN]; /* syslog message */ 41 char *strcpy(), *strcat(); 42 43 if (err_redir) { 44 /* don't combine these, "fmt" may not require "arg" */ 45 fprintf(stderr, "\t%s\n\t", tmpname); 46 fprintf(stderr, fmt, arg); 47 fputc('\n', stderr); 48 } 49 else { 50 sprintf(logmsg, "bugfiler: %s", fmt); 51 syslog(LOG_ERR, logmsg, arg); 52 } 53 #ifdef METOO 54 exit(ERR); 55 #else 56 exit(OK); 57 #endif 58 } 59