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>
13 #include <zephyr/zephyr.h>
16 /* log file for critical events that require human intervention */
17 #define CRITERRLOG "/u1/sms/critical.log"
19 /* mode to create the file with */
20 #define LOGFILEMODE 0644
25 void critical_alert(instance, msg, args)
26 char *instance; /* Instance for zephyr gram */
27 char *msg; /* printf format message */
28 /* args = arguements, printf style */
29 /* This routine sends a class SMS zephyrgram of specified instance
30 and logs to a special logfile the message passed to it via msg
31 and args in printf format. *** It expects the global variable
32 whoami to be defined and contain the name of the calling program. */
33 /* Note: The part of this code that process the variable arguements
34 was stolen from sprintf(). */
36 FILE _bufstr; /* For _doprnt() */
37 FILE *crit; /* FILE for critical log file */
38 char buf[BUFSIZ]; /* Holds the formatted message */
40 /* Put the fully formatted message into buf */
41 _bufstr._flag = _IOWRT + _IOSTRG;
43 _bufstr._cnt = BUFSIZ;
44 _doprnt(msg, &args, &_bufstr);
47 /* Send zephyr notice */
48 send_zgram(instance, buf);
50 /* Log message to critical file */
51 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
57 time_s = ctime(&t) + 4;
58 time_s[strlen(time_s)-6] = '\0';
60 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
64 com_err(whoami, 0, buf);
69 /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
70 * errors while sending message.
79 bzero (&znotice, sizeof (znotice));
80 znotice.z_kind = UNSAFE;
81 znotice.z_class = "SMS";
82 znotice.z_class_inst = inst;
83 znotice.z_default_format = "SMS $instance:\n $message\n";
84 (void) ZInitialize ();
85 znotice.z_message = msg;
86 znotice.z_message_len = strlen(msg) + 1;
87 znotice.z_opcode = "";
88 znotice.z_recipient = "";
89 ZSendNotice(&znotice, ZNOAUTH);