]>
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 | ||
babbc197 | 10 | #include <mit-copyright.h> |
96d806a4 | 11 | #include <stdio.h> |
12 | #include <sys/file.h> | |
6afba035 | 13 | #include <sms_app.h> |
2f4a1cd0 | 14 | #ifdef ZEPHYR |
96d806a4 | 15 | #include <zephyr/zephyr.h> |
2f4a1cd0 | 16 | #endif |
17 | #ifdef SYSLOG | |
18 | #include <syslog.h> | |
19 | #endif | |
96d806a4 | 20 | |
21 | ||
96d806a4 | 22 | /* mode to create the file with */ |
23 | #define LOGFILEMODE 0644 | |
24 | ||
5a77c71e | 25 | extern char *whoami; |
26 | ||
96d806a4 | 27 | |
955e02e2 | 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) | |
96d806a4 | 39 | char *instance; /* Instance for zephyr gram */ |
40 | char *msg; /* printf format message */ | |
955e02e2 | 41 | char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8; |
96d806a4 | 42 | { |
3f6b08ec | 43 | FILE *crit; /* FILE for critical log file */ |
96d806a4 | 44 | char buf[BUFSIZ]; /* Holds the formatted message */ |
45 | ||
955e02e2 | 46 | sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); |
96d806a4 | 47 | |
48 | /* Send zephyr notice */ | |
49 | send_zgram(instance, buf); | |
50 | ||
51 | /* Log message to critical file */ | |
3f6b08ec | 52 | if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) |
96d806a4 | 53 | { |
3f6b08ec | 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); | |
96d806a4 | 63 | } |
923cef2a | 64 | |
65 | com_err(whoami, 0, buf); | |
96d806a4 | 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 | { | |
2f4a1cd0 | 78 | #ifdef ZEPHYR |
96d806a4 | 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); | |
2f4a1cd0 | 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 | |
96d806a4 | 100 | } |