Commit | Line | Data |
---|---|---|
ecee9486 | 1 | /* |
aec2eff2 KB |
2 | * Copyright (c) 1986, 1987 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
1343342a | 5 | * %sccs.include.redist.c% |
ecee9486 KB |
6 | */ |
7 | ||
8 | #ifndef lint | |
d0ef4a0d | 9 | static char sccsid[] = "@(#)error.c 5.8 (Berkeley) %G%"; |
aec2eff2 | 10 | #endif /* not lint */ |
ecee9486 | 11 | |
d0ef4a0d KB |
12 | #include <sys/param.h> |
13 | #include <dirent.h> | |
ecee9486 KB |
14 | #include <syslog.h> |
15 | #include <stdio.h> | |
d0ef4a0d KB |
16 | #include <stdlib.h> |
17 | #include "bug.h" | |
ecee9486 KB |
18 | |
19 | static short err_redir; /* stderr redirected */ | |
20 | ||
21 | /* | |
22 | * seterr -- | |
23 | * redirect stderr for error processing | |
24 | */ | |
25 | seterr() | |
26 | { | |
d8336336 | 27 | if (!freopen(ERROR_FILE, "a", stderr)) |
36e21f76 | 28 | error("can't open error file %s.", ERROR_FILE); |
ecee9486 KB |
29 | err_redir = YES; |
30 | } | |
31 | ||
32 | /* | |
33 | * error -- | |
34 | * write errors to log file and die | |
35 | */ | |
d8336336 KB |
36 | error(fmt, arg) |
37 | register char *fmt, | |
38 | *arg; | |
ecee9486 KB |
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" */ | |
36e21f76 | 45 | fprintf(stderr, "\t%s\n\t", tmpname); |
d8336336 | 46 | fprintf(stderr, fmt, arg); |
36e21f76 | 47 | fputc('\n', stderr); |
ecee9486 KB |
48 | } |
49 | else { | |
d8336336 KB |
50 | sprintf(logmsg, "bugfiler: %s", fmt); |
51 | syslog(LOG_ERR, logmsg, arg); | |
ecee9486 | 52 | } |
ecee9486 KB |
53 | #ifdef METOO |
54 | exit(ERR); | |
d8336336 | 55 | #else |
ecee9486 | 56 | exit(OK); |
d8336336 | 57 | #endif |
ecee9486 | 58 | } |