[9089] | 1 | /* |
---|
| 2 | * Copyright Milan Technology Inc. 1991, 1992 |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | /* @(#)errors.c 2.0 10/9/92 */ |
---|
| 6 | |
---|
| 7 | #include "dp.h" |
---|
| 8 | #define G_ERRORS |
---|
| 9 | #include "errors.h" |
---|
| 10 | extern s_options g_opt; |
---|
| 11 | extern char *g_filter_name; /* The name by which this program was invoked */ |
---|
| 12 | extern FILE *g_errorLog; /* The fd for the error file */ |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | /* Error handling routines. |
---|
| 16 | * |
---|
| 17 | * 7/04/92 Stripped from fpfilter.c |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #ifdef ANSI |
---|
| 21 | void Send_to_file(char* string) |
---|
| 22 | #else |
---|
| 23 | void Send_to_file(string) |
---|
| 24 | char *string; |
---|
| 25 | #endif |
---|
| 26 | { |
---|
| 27 | if (g_opt.notify_type.file) |
---|
| 28 | fprintf(g_errorLog, "%s\n", string); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | #ifdef ANSI |
---|
| 32 | void Send_to_syslog(char* string, int type) |
---|
| 33 | #else |
---|
| 34 | void Send_to_syslog(string, type) |
---|
| 35 | char *string; |
---|
| 36 | int type; |
---|
| 37 | #endif |
---|
| 38 | { |
---|
| 39 | if (g_opt.notify_type.syslog) |
---|
| 40 | syslog(type, "%s", string); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | #ifdef ANSI |
---|
| 44 | void Send_to_tty(char *string) |
---|
| 45 | #else |
---|
| 46 | void Send_to_tty(string) |
---|
| 47 | char *string; |
---|
| 48 | #endif |
---|
| 49 | { |
---|
| 50 | fprintf(stderr,"%s \n", string); |
---|
| 51 | fflush(stderr); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | #ifdef ANSI |
---|
| 55 | void Send_to_mail(char* string) |
---|
| 56 | #else |
---|
| 57 | void Send_to_mail(string) |
---|
| 58 | char *string; |
---|
| 59 | #endif |
---|
| 60 | { |
---|
| 61 | char cmd[MAXSTRNGLEN]; |
---|
| 62 | static int inited = 0, fd_write; |
---|
| 63 | |
---|
| 64 | if (g_opt.notify_type.mail) { |
---|
| 65 | if (!inited) { |
---|
| 66 | sprintf(cmd, "mail %s", g_opt.notify_type.user); |
---|
| 67 | fd_write = initPipes(cmd); |
---|
| 68 | inited = 1; |
---|
| 69 | } |
---|
| 70 | write(fd_write, string, strlen(string)); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | #ifdef ANSI |
---|
| 75 | void Send_to_program(char* string) |
---|
| 76 | #else |
---|
| 77 | void Send_to_program(string) |
---|
| 78 | char *string; |
---|
| 79 | #endif |
---|
| 80 | { |
---|
| 81 | static int inited = 0, fd_write; |
---|
| 82 | |
---|
| 83 | if (g_opt.notify_type.program) { |
---|
| 84 | if (!inited) { |
---|
| 85 | fd_write = initPipes(g_opt.notify_type.prog_name); |
---|
| 86 | inited = 1; |
---|
| 87 | } |
---|
| 88 | write(fd_write, string, strlen(string)); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /* error_notify sends the error message to the appropriate place. |
---|
| 93 | * Then it exits unless err_no is 12 or 14 (ERR_GENERIC or ERR_ASCII). |
---|
| 94 | * ERR_GENERIC means print a generic message (passed down), ERR_ASCII |
---|
| 95 | * indicates that the user has not specified ascii -> ps conversion. |
---|
| 96 | */ |
---|
| 97 | |
---|
| 98 | #ifdef ANSI |
---|
| 99 | void error_notify(int err_no, char* generic_message) |
---|
| 100 | #else |
---|
| 101 | void error_notify(err_no, generic_message) |
---|
| 102 | int err_no; |
---|
| 103 | char *generic_message; |
---|
| 104 | #endif |
---|
| 105 | { |
---|
| 106 | if (err_no == ERR_GENERIC) { |
---|
| 107 | Send_to_file(generic_message); |
---|
| 108 | Send_to_syslog(generic_message, LOG_INFO); |
---|
| 109 | Send_to_mail(generic_message); |
---|
| 110 | Send_to_tty(generic_message); |
---|
| 111 | Send_to_program(generic_message); |
---|
| 112 | } |
---|
| 113 | else { |
---|
| 114 | Send_to_file(g_errors[err_no]); |
---|
| 115 | Send_to_syslog(g_errors[err_no], LOG_ERR); |
---|
| 116 | Send_to_mail(g_errors[err_no]); |
---|
| 117 | Send_to_tty(g_errors[err_no]); |
---|
| 118 | Send_to_program(g_errors[err_no]); |
---|
| 119 | |
---|
| 120 | if (err_no == ERR_READING) { |
---|
| 121 | char usage[MAXSTRNGLEN]; |
---|
| 122 | |
---|
| 123 | sprintf(usage, |
---|
| 124 | "usage: %s -P <hostname> [-s] [-m] [-SS] [-ES] [-A] [-SF] [-EF] [-p] [-b] files \n", |
---|
| 125 | g_filter_name); |
---|
| 126 | Send_to_file(usage); |
---|
| 127 | Send_to_syslog(usage, LOG_ERR); |
---|
| 128 | Send_to_mail(usage); |
---|
| 129 | Send_to_tty(usage); |
---|
| 130 | Send_to_program(usage); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | if ((err_no == ERR_GENERIC ) || (err_no == ERR_ASCII)) return; |
---|
| 135 | |
---|
| 136 | exit(12); /* What does 12 mean? */ |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | /* Trys to report an error, but turns off the mail and program options */ |
---|
| 140 | |
---|
| 141 | #ifdef ANSI |
---|
| 142 | void error_protect(int err_no) |
---|
| 143 | #else |
---|
| 144 | void error_protect(err_no) |
---|
| 145 | int err_no; |
---|
| 146 | #endif |
---|
| 147 | { |
---|
| 148 | g_opt.notify_type.program = 0; |
---|
| 149 | g_opt.notify_type.mail = 0; |
---|
| 150 | error_notify(errno, (char*)0); |
---|
| 151 | } |
---|