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*60083Sbostic static char sccsid[] = "@(#)error.c 5.9 (Berkeley) 05/17/93"; 1033416Sbostic #endif /* not lint */ 1130161Sbostic 1246667Sbostic #include <sys/param.h> 13*60083Sbostic 1446667Sbostic #include <dirent.h> 1530161Sbostic #include <stdio.h> 1646667Sbostic #include <stdlib.h> 17*60083Sbostic #include <string.h> 18*60083Sbostic #include <syslog.h> 19*60083Sbostic 2046667Sbostic #include "bug.h" 21*60083Sbostic #include "extern.h" 2230161Sbostic 2330161Sbostic static short err_redir; /* stderr redirected */ 2430161Sbostic 2530161Sbostic /* 2630161Sbostic * seterr -- 2730161Sbostic * redirect stderr for error processing 2830161Sbostic */ 29*60083Sbostic void 3030161Sbostic seterr() 3130161Sbostic { 3230890Sbostic if (!freopen(ERROR_FILE, "a", stderr)) 3331918Sbostic error("can't open error file %s.", ERROR_FILE); 3430161Sbostic err_redir = YES; 3530161Sbostic } 3630161Sbostic 3730161Sbostic /* 3830161Sbostic * error -- 3930161Sbostic * write errors to log file and die 4030161Sbostic */ 41*60083Sbostic void 4230890Sbostic error(fmt, arg) 4330890Sbostic register char *fmt, 4430890Sbostic *arg; 4530161Sbostic { 4630161Sbostic static char logmsg[MAXLINELEN]; /* syslog message */ 4730161Sbostic 4830161Sbostic if (err_redir) { 4930161Sbostic /* don't combine these, "fmt" may not require "arg" */ 5031918Sbostic fprintf(stderr, "\t%s\n\t", tmpname); 5130890Sbostic fprintf(stderr, fmt, arg); 5231918Sbostic fputc('\n', stderr); 5330161Sbostic } 5430161Sbostic else { 5530890Sbostic sprintf(logmsg, "bugfiler: %s", fmt); 5630890Sbostic syslog(LOG_ERR, logmsg, arg); 5730161Sbostic } 5830161Sbostic #ifdef METOO 5930161Sbostic exit(ERR); 6030890Sbostic #else 6130161Sbostic exit(OK); 6230890Sbostic #endif 6330161Sbostic } 64