130161Sbostic /* 230161Sbostic * Copyright (c) 1986 Regents of the University of California. 330161Sbostic * All rights reserved. The Berkeley software License Agreement 430161Sbostic * specifies the terms and conditions for redistribution. 530161Sbostic */ 630161Sbostic 730161Sbostic #ifndef lint 830161Sbostic static char sccsid[] = "@(#)error.c 5.1 (Berkeley) 86/11/25"; 930161Sbostic #endif not lint 1030161Sbostic 11*30890Sbostic #include <bug.h> 1230161Sbostic #include <syslog.h> 1330161Sbostic #include <stdio.h> 1430161Sbostic 1530161Sbostic static short err_redir; /* stderr redirected */ 1630161Sbostic 1730161Sbostic /* 1830161Sbostic * seterr -- 1930161Sbostic * redirect stderr for error processing 2030161Sbostic */ 2130161Sbostic seterr() 2230161Sbostic { 23*30890Sbostic if (!freopen(ERROR_FILE, "a", stderr)) 24*30890Sbostic error("can't open error file %s.\n", ERROR_FILE); 2530161Sbostic err_redir = YES; 2630161Sbostic } 2730161Sbostic 2830161Sbostic /* 2930161Sbostic * error -- 3030161Sbostic * write errors to log file and die 3130161Sbostic */ 32*30890Sbostic error(fmt, arg) 33*30890Sbostic register char *fmt, 34*30890Sbostic *arg; 3530161Sbostic { 3630161Sbostic static char logmsg[MAXLINELEN]; /* syslog message */ 3730161Sbostic char *strcpy(), *strcat(); 3830161Sbostic 3930161Sbostic if (err_redir) { 4030161Sbostic /* don't combine these, "fmt" may not require "arg" */ 41*30890Sbostic fputc('\t', stderr); 42*30890Sbostic fprintf(stderr, fmt, arg); 43*30890Sbostic fprintf(stderr, "\n\ttemporary file is %s.\n", tmpname); 4430161Sbostic } 4530161Sbostic else { 46*30890Sbostic sprintf(logmsg, "bugfiler: %s", fmt); 47*30890Sbostic syslog(LOG_ERR, logmsg, arg); 4830161Sbostic } 4930161Sbostic #ifdef METOO 5030161Sbostic exit(ERR); 51*30890Sbostic #else 5230161Sbostic exit(OK); 53*30890Sbostic #endif 5430161Sbostic } 55