3 * Log and send a zephyrgram about any critical errors.
5 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
12 /* need to include before moira.h, which includes krb_et.h, because
14 #include <zephyr/zephyr.h>
15 /* zephyr.h doesn't prototype this */
16 extern Code_t ZSendNotice(ZNotice_t *notice, Z_AuthProc cert_routine);
19 #include <mit-copyright.h>
21 #include <moira_site.h>
33 /* mode to create the file with */
34 #define LOGFILEMODE 0644
38 /* This routine sends a class MOIRA zephyrgram of specified instance
39 * and logs to a special logfile the message passed to it via msg
40 * and args in printf format. *** It expects the global variable
41 * whoami to be defined and contain the name of the calling program.
44 void critical_alert(char *instance, char *msg, ...)
51 /* Log message to critical file */
52 if ((crit = fopen(CRITERRLOG, "a")))
58 time_s = ctime(&t) + 4;
59 time_s[strlen(time_s) - 6] = '\0';
61 fprintf(crit, "%s <%ld>", time_s, (long)getpid());
64 vfprintf(crit, msg, ap);
68 buf = malloc(ftell(crit) - start);
74 vsprintf(buf, msg, ap);
77 send_zgram(instance, buf);
78 com_err(whoami, 0, buf);
86 send_zgram(instance, "Couldn't format critical syslog!");
87 com_err(whoami, 0, "Couldn't format critical syslog!");
92 /* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
93 * errors while sending message.
96 void send_zgram(char *inst, char *msg)
101 memset(&znotice, 0, sizeof(znotice));
102 znotice.z_kind = UNSAFE;
103 znotice.z_class = "MOIRA";
104 znotice.z_class_inst = inst;
105 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
107 znotice.z_message = msg;
108 znotice.z_message_len = strlen(msg) + 1;
109 znotice.z_opcode = "";
110 znotice.z_recipient = "";
111 ZSendNotice(&znotice, ZNOAUTH);
115 buf = malloc(9 + strlen(inst) + strlen(msg));
118 sprintf(buf, "MOIRA: %s %s", inst, msg);
119 syslog(LOG_ERR, buf);