130161Sbostic /* 233416Sbostic * Copyright (c) 1986, 1987 Regents of the University of California. 333416Sbostic * All rights reserved. 433416Sbostic * 542663Sbostic * %sccs.include.redist.c% 630161Sbostic */ 730161Sbostic 830161Sbostic #ifndef lint 9*46667Sbostic static char sccsid[] = "@(#)error.c 5.8 (Berkeley) 02/25/91"; 1033416Sbostic #endif /* not lint */ 1130161Sbostic 12*46667Sbostic #include <sys/param.h> 13*46667Sbostic #include <dirent.h> 1430161Sbostic #include <syslog.h> 1530161Sbostic #include <stdio.h> 16*46667Sbostic #include <stdlib.h> 17*46667Sbostic #include "bug.h" 1830161Sbostic 1930161Sbostic static short err_redir; /* stderr redirected */ 2030161Sbostic 2130161Sbostic /* 2230161Sbostic * seterr -- 2330161Sbostic * redirect stderr for error processing 2430161Sbostic */ 2530161Sbostic seterr() 2630161Sbostic { 2730890Sbostic if (!freopen(ERROR_FILE, "a", stderr)) 2831918Sbostic error("can't open error file %s.", ERROR_FILE); 2930161Sbostic err_redir = YES; 3030161Sbostic } 3130161Sbostic 3230161Sbostic /* 3330161Sbostic * error -- 3430161Sbostic * write errors to log file and die 3530161Sbostic */ 3630890Sbostic error(fmt, arg) 3730890Sbostic register char *fmt, 3830890Sbostic *arg; 3930161Sbostic { 4030161Sbostic static char logmsg[MAXLINELEN]; /* syslog message */ 4130161Sbostic char *strcpy(), *strcat(); 4230161Sbostic 4330161Sbostic if (err_redir) { 4430161Sbostic /* don't combine these, "fmt" may not require "arg" */ 4531918Sbostic fprintf(stderr, "\t%s\n\t", tmpname); 4630890Sbostic fprintf(stderr, fmt, arg); 4731918Sbostic fputc('\n', stderr); 4830161Sbostic } 4930161Sbostic else { 5030890Sbostic sprintf(logmsg, "bugfiler: %s", fmt); 5130890Sbostic syslog(LOG_ERR, logmsg, arg); 5230161Sbostic } 5330161Sbostic #ifdef METOO 5430161Sbostic exit(ERR); 5530890Sbostic #else 5630161Sbostic exit(OK); 5730890Sbostic #endif 5830161Sbostic } 59