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>
15 #include <zephyr/zephyr.h>
22 /* mode to create the file with */
23 #define LOGFILEMODE 0644
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().
37 void critical_alert(instance, msg, arg1, arg2, arg3, arg4,
38 arg5, arg6, arg7, arg8)
39 char *instance; /* Instance for zephyr gram */
40 char *msg; /* printf format message */
41 char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8;
43 FILE *crit; /* FILE for critical log file */
44 char buf[BUFSIZ]; /* Holds the formatted message */
46 sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
48 /* Send zephyr notice */
49 send_zgram(instance, buf);
51 /* Log message to critical file */
52 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
58 time_s = ctime(&t) + 4;
59 time_s[strlen(time_s)-6] = '\0';
61 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
65 com_err(whoami, 0, buf);
70 /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
71 * errors while sending message.
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);
96 sprintf(buf, "SMS: %s %s", inst, msg);