]> andersk Git - moira.git/blob - lib/critical.c
moved the #define of ZEPHYR to sms_app.h
[moira.git] / lib / critical.c
1 /* $Header$
2  *
3  * Log and send a zephyrgram about any critical errors.
4  *
5  *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
6  *  For copying and distribution information, please see the file
7  *  <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <stdio.h>
12 #include <sys/file.h>
13 #include <sms_app.h>
14 #ifdef ZEPHYR
15 #include <zephyr/zephyr.h>
16 #endif
17 #ifdef SYSLOG
18 #include <syslog.h>
19 #endif
20
21
22 /* mode to create the file with */
23 #define LOGFILEMODE     0644
24
25 extern char *whoami;
26
27
28 /* This routine sends a class SMS zephyrgram of specified instance
29  * and logs to a special logfile the message passed to it via msg
30  * and args in printf format.  *** It expects the global variable
31  * whoami to be defined and contain the name of the calling program.
32  * It's a kludge that it takes a max of 8 arguments in a way that
33  * isn't necessarily portable, but varargs doesn't work here and we
34  * don't have vsprintf().
35  */
36
37 void critical_alert(instance, msg, arg1, arg2, arg3, arg4,
38                     arg5, arg6, arg7, arg8)
39   char *instance;               /* Instance for zephyr gram */
40   char *msg;                    /* printf format message */
41   char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8;
42 {
43     FILE *crit;                 /* FILE for critical log file */
44     char buf[BUFSIZ];           /* Holds the formatted message */
45
46     sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
47
48     /* Send zephyr notice */
49     send_zgram(instance, buf);
50
51     /* Log message to critical file */
52     if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) 
53     {
54         long t;
55         char  *time_s;
56
57         time(&t);
58         time_s = ctime(&t) + 4;
59         time_s[strlen(time_s)-6] = '\0';
60
61         fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
62         fclose(crit);
63     }
64
65     com_err(whoami, 0, buf);
66 }
67
68
69
70 /* Sends a zephyrgram of class "SMS", instance as a parameter.  Ignores
71  * errors while sending message.
72  */
73
74 send_zgram(inst, msg)
75 char *inst;
76 char *msg;
77 {
78 #ifdef ZEPHYR
79     ZNotice_t znotice;
80
81     bzero (&znotice, sizeof (znotice));
82     znotice.z_kind = UNSAFE;
83     znotice.z_class = "SMS";
84     znotice.z_class_inst = inst;
85     znotice.z_default_format = "SMS $instance:\n $message\n";
86     (void) ZInitialize ();
87     znotice.z_message = msg;
88     znotice.z_message_len = strlen(msg) + 1;
89     znotice.z_opcode = "";
90     znotice.z_recipient = "";
91     ZSendNotice(&znotice, ZNOAUTH);
92 #endif
93 #ifdef SYSLOG
94     {
95         char buf[512];
96         sprintf(buf, "SMS: %s %s", inst, msg);
97         syslog(LOG_ERR, buf);
98     }
99 #endif
100 }
This page took 0.041033 seconds and 5 git commands to generate.