source: trunk/third/transcript/src/milan/errors.c @ 9090

Revision 9090, 3.1 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9089, which included commits to RCS files with non-trunk default branches.
Line 
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"
10extern s_options g_opt;
11extern char *g_filter_name; /* The name by which this program was invoked */
12extern 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
21void Send_to_file(char* string)
22#else
23void Send_to_file(string)
24char *string;
25#endif
26{
27   if (g_opt.notify_type.file)
28      fprintf(g_errorLog, "%s\n", string);
29}
30
31#ifdef ANSI
32void Send_to_syslog(char* string, int type)
33#else
34void Send_to_syslog(string, type)
35char *string;
36int type;
37#endif
38{
39    if (g_opt.notify_type.syslog)
40       syslog(type, "%s", string);
41}
42
43#ifdef ANSI
44void Send_to_tty(char *string)
45#else
46void Send_to_tty(string)
47char *string;
48#endif
49{
50      fprintf(stderr,"%s \n", string);
51      fflush(stderr);
52}
53
54#ifdef ANSI
55void Send_to_mail(char* string)
56#else
57void Send_to_mail(string)
58char *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
75void Send_to_program(char* string)
76#else
77void Send_to_program(string)
78char *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
99void error_notify(int err_no, char* generic_message)
100#else
101void error_notify(err_no, generic_message)
102int err_no;
103char *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
142void error_protect(int err_no)
143#else
144void error_protect(err_no)
145int 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}
Note: See TracBrowser for help on using the repository browser.