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>
30 /* mode to create the file with */
31 #define LOGFILEMODE 0644
35 /* This routine sends a class MOIRA zephyrgram of specified instance
36 * and logs to a special logfile the message passed to it via msg
37 * and args in printf format. *** It expects the global variable
38 * whoami to be defined and contain the name of the calling program.
41 void critical_alert(char *instance, char *msg, ...)
43 FILE *crit; /* FILE for critical log file */
44 char buf[BUFSIZ]; /* Holds the formatted message */
48 vsprintf(buf, msg, ap);
51 /* Send zephyr notice */
52 send_zgram(instance, buf);
54 /* Log message to critical file */
55 if ((crit = fopen(CRITERRLOG, "a")))
61 time_s = ctime(&t) + 4;
62 time_s[strlen(time_s) - 6] = '\0';
64 fprintf(crit, "%s <%ld> %s\n", time_s, (long)getpid(), buf);
68 com_err(whoami, 0, buf);
73 /* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
74 * errors while sending message.
77 void send_zgram(char *inst, char *msg)
82 memset(&znotice, 0, sizeof(znotice));
83 znotice.z_kind = UNSAFE;
84 znotice.z_class = "MOIRA";
85 znotice.z_class_inst = inst;
86 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
88 znotice.z_message = msg;
89 znotice.z_message_len = strlen(msg) + 1;
90 znotice.z_opcode = "";
91 znotice.z_recipient = "";
92 ZSendNotice(&znotice, ZNOAUTH);
97 sprintf(buf, "MOIRA: %s %s", inst, msg);