]> andersk Git - moira.git/blame - lib/critical.c
remove dependancy on resolver internals
[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>
24582af9 12#include <sys/types.h>
96d806a4 13#include <sys/file.h>
8defc06b 14#include <moira_site.h>
2f4a1cd0 15#ifdef ZEPHYR
96d806a4 16#include <zephyr/zephyr.h>
2f4a1cd0 17#endif
18#ifdef SYSLOG
19#include <syslog.h>
20#endif
96d806a4 21
22
96d806a4 23/* mode to create the file with */
24#define LOGFILEMODE 0644
25
5a77c71e 26extern char *whoami;
27
96d806a4 28
8defc06b 29/* This routine sends a class MOIRA zephyrgram of specified instance
955e02e2 30 * and logs to a special logfile the message passed to it via msg
31 * and args in printf format. *** It expects the global variable
32 * whoami to be defined and contain the name of the calling program.
33 * It's a kludge that it takes a max of 8 arguments in a way that
34 * isn't necessarily portable, but varargs doesn't work here and we
35 * don't have vsprintf().
36 */
37
38void critical_alert(instance, msg, arg1, arg2, arg3, arg4,
39 arg5, arg6, arg7, arg8)
96d806a4 40 char *instance; /* Instance for zephyr gram */
41 char *msg; /* printf format message */
955e02e2 42 char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8;
96d806a4 43{
3f6b08ec 44 FILE *crit; /* FILE for critical log file */
96d806a4 45 char buf[BUFSIZ]; /* Holds the formatted message */
46
955e02e2 47 sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
96d806a4 48
49 /* Send zephyr notice */
50 send_zgram(instance, buf);
51
52 /* Log message to critical file */
3f6b08ec 53 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
96d806a4 54 {
24582af9 55 long t, time();
3f6b08ec 56 char *time_s;
57
58 time(&t);
59 time_s = ctime(&t) + 4;
60 time_s[strlen(time_s)-6] = '\0';
61
62 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
63 fclose(crit);
96d806a4 64 }
923cef2a 65
66 com_err(whoami, 0, buf);
96d806a4 67}
68
69
70
8defc06b 71/* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
96d806a4 72 * errors while sending message.
73 */
74
75send_zgram(inst, msg)
76char *inst;
77char *msg;
78{
2f4a1cd0 79#ifdef ZEPHYR
96d806a4 80 ZNotice_t znotice;
81
82 bzero (&znotice, sizeof (znotice));
83 znotice.z_kind = UNSAFE;
8defc06b 84 znotice.z_class = "MOIRA";
96d806a4 85 znotice.z_class_inst = inst;
e8377789 86 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
96d806a4 87 (void) ZInitialize ();
88 znotice.z_message = msg;
89 znotice.z_message_len = strlen(msg) + 1;
90 znotice.z_opcode = "";
91 znotice.z_recipient = "";
92 ZSendNotice(&znotice, ZNOAUTH);
2f4a1cd0 93#endif
94#ifdef SYSLOG
95 {
96 char buf[512];
8defc06b 97 sprintf(buf, "MOIRA: %s %s", inst, msg);
2f4a1cd0 98 syslog(LOG_ERR, buf);
99 }
100#endif
96d806a4 101}
This page took 0.076537 seconds and 5 git commands to generate.