]> andersk Git - moira.git/blame - lib/critical.c
backed out a couple of changes (to 1.21) and then put back in
[moira.git] / lib / critical.c
CommitLineData
96d806a4 1/* $Header$
2 *
3 * Log and send a zephyrgram about any critical errors.
4 */
5
6#include <stdio.h>
7#include <sys/file.h>
8#include <zephyr/zephyr.h>
9
10
11/* log file for critical events that require human intervention */
12#define CRITERRLOG "/u1/sms/critical.log"
13
14/* mode to create the file with */
15#define LOGFILEMODE 0644
16
5a77c71e 17extern char *whoami;
18
96d806a4 19
20void critical_alert(instance, msg, args)
21 char *instance; /* Instance for zephyr gram */
22 char *msg; /* printf format message */
23 /* args = arguements, printf style */
24 /* This routine sends a class SMS zephyrgram of specified instance
25 and logs to a special logfile the message passed to it via msg
923cef2a 26 and args in printf format. *** It expects the global variable
27 whoami to be defined and contain the name of the calling program. */
96d806a4 28 /* Note: The part of this code that process the variable arguements
29 was stolen from sprintf(). */
30{
31 FILE _bufstr; /* For _doprnt() */
3f6b08ec 32 FILE *crit; /* FILE for critical log file */
96d806a4 33 char buf[BUFSIZ]; /* Holds the formatted message */
34
35 /* Put the fully formatted message into buf */
36 _bufstr._flag = _IOWRT + _IOSTRG;
37 _bufstr._ptr = buf;
38 _bufstr._cnt = BUFSIZ;
39 _doprnt(msg, &args, &_bufstr);
40 putc('\0', &_bufstr);
41
42 /* Send zephyr notice */
43 send_zgram(instance, buf);
44
45 /* Log message to critical file */
3f6b08ec 46 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
96d806a4 47 {
3f6b08ec 48 long t;
49 char *time_s;
50
51 time(&t);
52 time_s = ctime(&t) + 4;
53 time_s[strlen(time_s)-6] = '\0';
54
55 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
56 fclose(crit);
96d806a4 57 }
923cef2a 58
59 com_err(whoami, 0, buf);
96d806a4 60}
61
62
63
64/* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
65 * errors while sending message.
66 */
67
68send_zgram(inst, msg)
69char *inst;
70char *msg;
71{
72 ZNotice_t znotice;
73
74 bzero (&znotice, sizeof (znotice));
75 znotice.z_kind = UNSAFE;
76 znotice.z_class = "SMS";
77 znotice.z_class_inst = inst;
78 znotice.z_default_format = "SMS $instance:\n $message\n";
79 (void) ZInitialize ();
80 znotice.z_message = msg;
81 znotice.z_message_len = strlen(msg) + 1;
82 znotice.z_opcode = "";
83 znotice.z_recipient = "";
84 ZSendNotice(&znotice, ZNOAUTH);
85}
This page took 0.060886 seconds and 5 git commands to generate.