3 * Log and send a zephyrgram about any critical errors.
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include <sys/types.h>
14 #include <moira_site.h>
16 #include <zephyr/zephyr.h>
25 /* mode to create the file with */
26 #define LOGFILEMODE 0644
31 /* This routine sends a class MOIRA zephyrgram of specified instance
32 * and logs to a special logfile the message passed to it via msg
33 * and args in printf format. *** It expects the global variable
34 * whoami to be defined and contain the name of the calling program.
35 * It's a kludge that it takes a max of 8 arguments in a way that
36 * isn't necessarily portable, but varargs doesn't work here and we
37 * don't necessarily have vsprintf().
40 void critical_alert(char *instance, char *msg, char *arg1, char *arg2,
41 char *arg3, char *arg4, char *arg5, char *arg6,
42 char *arg7, char *arg8)
44 FILE *crit; /* FILE for critical log file */
45 char buf[BUFSIZ]; /* Holds the formatted message */
47 sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
49 /* Send zephyr notice */
50 send_zgram(instance, buf);
52 /* Log message to critical file */
53 if ((crit = fopen(CRITERRLOG, "a")))
59 time_s = ctime(&t) + 4;
60 time_s[strlen(time_s) - 6] = '\0';
62 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
66 com_err(whoami, 0, buf);
71 /* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
72 * errors while sending message.
75 send_zgram(char *inst, char *msg)
80 memset(&znotice, 0, sizeof(znotice));
81 znotice.z_kind = UNSAFE;
82 znotice.z_class = "MOIRA";
83 znotice.z_class_inst = inst;
84 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
86 znotice.z_message = msg;
87 znotice.z_message_len = strlen(msg) + 1;
88 znotice.z_opcode = "";
89 znotice.z_recipient = "";
90 ZSendNotice(&znotice, ZNOAUTH);
95 sprintf(buf, "MOIRA: %s %s", inst, msg);