]> andersk Git - moira.git/blame - lib/critical.c
allow compilation on the Sun
[moira.git] / lib / critical.c
CommitLineData
96d806a4 1/* $Header$
2 *
3 * Log and send a zephyrgram about any critical errors.
babbc197 4 *
5 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
96d806a4 8 */
9
babbc197 10#include <mit-copyright.h>
96d806a4 11#include <stdio.h>
12#include <sys/file.h>
13#include <zephyr/zephyr.h>
b1a67c82 14#include <sms_app.h>
96d806a4 15
16
96d806a4 17/* mode to create the file with */
18#define LOGFILEMODE 0644
19
5a77c71e 20extern char *whoami;
21
96d806a4 22
23void 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
923cef2a 29 and args in printf format. *** It expects the global variable
30 whoami to be defined and contain the name of the calling program. */
96d806a4 31 /* Note: The part of this code that process the variable arguements
32 was stolen from sprintf(). */
33{
34 FILE _bufstr; /* For _doprnt() */
3f6b08ec 35 FILE *crit; /* FILE for critical log file */
96d806a4 36 char buf[BUFSIZ]; /* Holds the formatted message */
37
38 /* Put the fully formatted message into buf */
39 _bufstr._flag = _IOWRT + _IOSTRG;
40 _bufstr._ptr = buf;
41 _bufstr._cnt = BUFSIZ;
42 _doprnt(msg, &args, &_bufstr);
43 putc('\0', &_bufstr);
44
45 /* Send zephyr notice */
46 send_zgram(instance, buf);
47
48 /* Log message to critical file */
3f6b08ec 49 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
96d806a4 50 {
3f6b08ec 51 long t;
52 char *time_s;
53
54 time(&t);
55 time_s = ctime(&t) + 4;
56 time_s[strlen(time_s)-6] = '\0';
57
58 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
59 fclose(crit);
96d806a4 60 }
923cef2a 61
62 com_err(whoami, 0, buf);
96d806a4 63}
64
65
66
67/* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
68 * errors while sending message.
69 */
70
71send_zgram(inst, msg)
72char *inst;
73char *msg;
74{
75 ZNotice_t znotice;
76
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);
88}
This page took 0.070848 seconds and 5 git commands to generate.