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