Commit | Line | Data |
---|---|---|
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 | |
5f8a7189 | 8 | static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 87/04/11"; |
ecee9486 KB |
9 | #endif not lint |
10 | ||
d8336336 | 11 | #include <bug.h> |
ecee9486 KB |
12 | #include <syslog.h> |
13 | #include <stdio.h> | |
ecee9486 KB |
14 | |
15 | static short err_redir; /* stderr redirected */ | |
16 | ||
17 | /* | |
18 | * seterr -- | |
19 | * redirect stderr for error processing | |
20 | */ | |
21 | seterr() | |
22 | { | |
d8336336 KB |
23 | if (!freopen(ERROR_FILE, "a", stderr)) |
24 | error("can't open error file %s.\n", ERROR_FILE); | |
ecee9486 KB |
25 | err_redir = YES; |
26 | } | |
27 | ||
28 | /* | |
29 | * error -- | |
30 | * write errors to log file and die | |
31 | */ | |
d8336336 KB |
32 | error(fmt, arg) |
33 | register char *fmt, | |
34 | *arg; | |
ecee9486 KB |
35 | { |
36 | static char logmsg[MAXLINELEN]; /* syslog message */ | |
37 | char *strcpy(), *strcat(); | |
38 | ||
39 | if (err_redir) { | |
40 | /* don't combine these, "fmt" may not require "arg" */ | |
d8336336 KB |
41 | fputc('\t', stderr); |
42 | fprintf(stderr, fmt, arg); | |
43 | fprintf(stderr, "\n\ttemporary file is %s.\n", tmpname); | |
ecee9486 KB |
44 | } |
45 | else { | |
d8336336 KB |
46 | sprintf(logmsg, "bugfiler: %s", fmt); |
47 | syslog(LOG_ERR, logmsg, arg); | |
ecee9486 | 48 | } |
ecee9486 KB |
49 | #ifdef METOO |
50 | exit(ERR); | |
d8336336 | 51 | #else |
ecee9486 | 52 | exit(OK); |
d8336336 | 53 | #endif |
ecee9486 | 54 | } |