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 /* At Athena, we use zephyr & not syslog. Change the following line
15 #include <mit-copyright.h>
19 #include <zephyr/zephyr.h>
27 /* mode to create the file with */
28 #define LOGFILEMODE 0644
33 void critical_alert(instance, msg, args)
34 char *instance; /* Instance for zephyr gram */
35 char *msg; /* printf format message */
36 /* args = arguements, printf style */
37 /* This routine sends a class SMS zephyrgram of specified instance
38 and logs to a special logfile the message passed to it via msg
39 and args in printf format. *** It expects the global variable
40 whoami to be defined and contain the name of the calling program. */
41 /* Note: The part of this code that process the variable arguements
42 was stolen from sprintf(). */
44 FILE _bufstr; /* For _doprnt() */
45 FILE *crit; /* FILE for critical log file */
46 char buf[BUFSIZ]; /* Holds the formatted message */
48 /* Put the fully formatted message into buf */
49 _bufstr._flag = _IOWRT + _IOSTRG;
51 _bufstr._cnt = BUFSIZ;
52 _doprnt(msg, &args, &_bufstr);
55 /* Send zephyr notice */
56 send_zgram(instance, buf);
58 /* Log message to critical file */
59 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
65 time_s = ctime(&t) + 4;
66 time_s[strlen(time_s)-6] = '\0';
68 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
72 com_err(whoami, 0, buf);
77 /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
78 * errors while sending message.
88 bzero (&znotice, sizeof (znotice));
89 znotice.z_kind = UNSAFE;
90 znotice.z_class = "SMS";
91 znotice.z_class_inst = inst;
92 znotice.z_default_format = "SMS $instance:\n $message\n";
93 (void) ZInitialize ();
94 znotice.z_message = msg;
95 znotice.z_message_len = strlen(msg) + 1;
96 znotice.z_opcode = "";
97 znotice.z_recipient = "";
98 ZSendNotice(&znotice, ZNOAUTH);
103 sprintf(buf, "SMS: %s %s", inst, msg);
104 syslog(LOG_ERR, buf);