added multiple file version of bugfiler
[unix-history] / usr / src / libexec / bugfiler / error.c
CommitLineData
ecee9486
KB
1/*
2 * Copyright (c) 1986 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8static char sccsid[] = "@(#)error.c 5.1 (Berkeley) 86/11/25";
9#endif not lint
10
11#include <syslog.h>
12#include <stdio.h>
13#include <bug.h>
14
15extern char *distf, /* redist temp file */
16 tmpname[]; /* temporary file used */
17
18short made_dist; /* if dist file made */
19
20static short err_redir; /* stderr redirected */
21
22/*
23 * seterr --
24 * redirect stderr for error processing
25 */
26seterr()
27{
28 if (!freopen(ERROR_FILE,"a",stderr))
29 error("unable to open error file %s.\n",ERROR_FILE);
30 err_redir = YES;
31}
32
33/*
34 * error --
35 * write errors to log file and die
36 */
37error(fmt,arg)
38register char *fmt,
39 *arg;
40{
41 static char logmsg[MAXLINELEN]; /* syslog message */
42 char *strcpy(), *strcat();
43
44 if (err_redir) {
45 /* don't combine these, "fmt" may not require "arg" */
46 fputc('\t',stderr);
47 fprintf(stderr,fmt,arg);
48 fprintf(stderr,"\n\ttemporary file is %s.\n",tmpname);
49 }
50 else {
51 strcat(strcpy(logmsg,"bugfiler: "),fmt);
52 syslog(LOG_ERR,logmsg,arg);
53 }
54 if (made_dist) /* unlink redist file if necessary */
55 unlink(distf);
56#ifdef METOO
57 exit(ERR);
58#else !METOO
59 exit(OK);
60#endif METOO
61}