]> andersk Git - moira.git/blame_incremental - lib/critical.c
#define the zephyr stuff & add syslog definitions as well
[moira.git] / lib / critical.c
... / ...
CommitLineData
1/* $Header$
2 *
3 * Log and send a zephyrgram about any critical errors.
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>.
8 */
9
10/* At Athena, we use zephyr & not syslog. Change the following line
11 * if necessary */
12#define ZEPHYR
13
14
15#include <mit-copyright.h>
16#include <stdio.h>
17#include <sys/file.h>
18#ifdef ZEPHYR
19#include <zephyr/zephyr.h>
20#endif
21#ifdef SYSLOG
22#include <syslog.h>
23#endif
24#include <sms_app.h>
25
26
27/* mode to create the file with */
28#define LOGFILEMODE 0644
29
30extern char *whoami;
31
32
33void 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(). */
43{
44 FILE _bufstr; /* For _doprnt() */
45 FILE *crit; /* FILE for critical log file */
46 char buf[BUFSIZ]; /* Holds the formatted message */
47
48 /* Put the fully formatted message into buf */
49 _bufstr._flag = _IOWRT + _IOSTRG;
50 _bufstr._ptr = buf;
51 _bufstr._cnt = BUFSIZ;
52 _doprnt(msg, &args, &_bufstr);
53 putc('\0', &_bufstr);
54
55 /* Send zephyr notice */
56 send_zgram(instance, buf);
57
58 /* Log message to critical file */
59 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
60 {
61 long t;
62 char *time_s;
63
64 time(&t);
65 time_s = ctime(&t) + 4;
66 time_s[strlen(time_s)-6] = '\0';
67
68 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
69 fclose(crit);
70 }
71
72 com_err(whoami, 0, buf);
73}
74
75
76
77/* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
78 * errors while sending message.
79 */
80
81send_zgram(inst, msg)
82char *inst;
83char *msg;
84{
85#ifdef ZEPHYR
86 ZNotice_t znotice;
87
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);
99#endif
100#ifdef SYSLOG
101 {
102 char buf[512];
103 sprintf(buf, "SMS: %s %s", inst, msg);
104 syslog(LOG_ERR, buf);
105 }
106#endif
107}
This page took 0.088772 seconds and 5 git commands to generate.