]>
Commit | Line | Data |
---|---|---|
96d806a4 | 1 | /* $Header$ |
2 | * | |
3 | * Log and send a zephyrgram about any critical errors. | |
babbc197 | 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>. | |
96d806a4 | 8 | */ |
9 | ||
2f4a1cd0 | 10 | /* At Athena, we use zephyr & not syslog. Change the following line |
11 | * if necessary */ | |
12 | #define ZEPHYR | |
13 | ||
14 | ||
babbc197 | 15 | #include <mit-copyright.h> |
96d806a4 | 16 | #include <stdio.h> |
17 | #include <sys/file.h> | |
2f4a1cd0 | 18 | #ifdef ZEPHYR |
96d806a4 | 19 | #include <zephyr/zephyr.h> |
2f4a1cd0 | 20 | #endif |
21 | #ifdef SYSLOG | |
22 | #include <syslog.h> | |
23 | #endif | |
b1a67c82 | 24 | #include <sms_app.h> |
96d806a4 | 25 | |
26 | ||
96d806a4 | 27 | /* mode to create the file with */ |
28 | #define LOGFILEMODE 0644 | |
29 | ||
5a77c71e | 30 | extern char *whoami; |
31 | ||
96d806a4 | 32 | |
33 | void critical_alert(instance, msg, args) | |
34 | char *instance; /* Instance for zephyr gram */ | |
35 | char *msg; /* printf format message */ | |
36 | /* args = arguements, printf style */ | |
37 | /* This routine sends a class SMS zephyrgram of specified instance | |
38 | and logs to a special logfile the message passed to it via msg | |
923cef2a | 39 | and args in printf format. *** It expects the global variable |
40 | whoami to be defined and contain the name of the calling program. */ | |
96d806a4 | 41 | /* Note: The part of this code that process the variable arguements |
42 | was stolen from sprintf(). */ | |
43 | { | |
44 | FILE _bufstr; /* For _doprnt() */ | |
3f6b08ec | 45 | FILE *crit; /* FILE for critical log file */ |
96d806a4 | 46 | char buf[BUFSIZ]; /* Holds the formatted message */ |
47 | ||
48 | /* Put the fully formatted message into buf */ | |
49 | _bufstr._flag = _IOWRT + _IOSTRG; | |
50 | _bufstr._ptr = buf; | |
51 | _bufstr._cnt = BUFSIZ; | |
52 | _doprnt(msg, &args, &_bufstr); | |
53 | putc('\0', &_bufstr); | |
54 | ||
55 | /* Send zephyr notice */ | |
56 | send_zgram(instance, buf); | |
57 | ||
58 | /* Log message to critical file */ | |
3f6b08ec | 59 | if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) |
96d806a4 | 60 | { |
3f6b08ec | 61 | long t; |
62 | char *time_s; | |
63 | ||
64 | time(&t); | |
65 | time_s = ctime(&t) + 4; | |
66 | time_s[strlen(time_s)-6] = '\0'; | |
67 | ||
68 | fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf); | |
69 | fclose(crit); | |
96d806a4 | 70 | } |
923cef2a | 71 | |
72 | com_err(whoami, 0, buf); | |
96d806a4 | 73 | } |
74 | ||
75 | ||
76 | ||
77 | /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores | |
78 | * errors while sending message. | |
79 | */ | |
80 | ||
81 | send_zgram(inst, msg) | |
82 | char *inst; | |
83 | char *msg; | |
84 | { | |
2f4a1cd0 | 85 | #ifdef ZEPHYR |
96d806a4 | 86 | ZNotice_t znotice; |
87 | ||
88 | bzero (&znotice, sizeof (znotice)); | |
89 | znotice.z_kind = UNSAFE; | |
90 | znotice.z_class = "SMS"; | |
91 | znotice.z_class_inst = inst; | |
92 | znotice.z_default_format = "SMS $instance:\n $message\n"; | |
93 | (void) ZInitialize (); | |
94 | znotice.z_message = msg; | |
95 | znotice.z_message_len = strlen(msg) + 1; | |
96 | znotice.z_opcode = ""; | |
97 | znotice.z_recipient = ""; | |
98 | ZSendNotice(&znotice, ZNOAUTH); | |
2f4a1cd0 | 99 | #endif |
100 | #ifdef SYSLOG | |
101 | { | |
102 | char buf[512]; | |
103 | sprintf(buf, "SMS: %s %s", inst, msg); | |
104 | syslog(LOG_ERR, buf); | |
105 | } | |
106 | #endif | |
96d806a4 | 107 | } |