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