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