]> andersk Git - moira.git/blame - lib/critical.c
use CODE=ANSI_C option to proc
[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
5eaef520 40void critical_alert(char *instance, char *msg, char *arg1, char *arg2,
41 char *arg3, char *arg4, char *arg5, char *arg6,
42 char *arg7, char *arg8)
96d806a4 43{
5eaef520 44 FILE *crit; /* FILE for critical log file */
45 char buf[BUFSIZ]; /* Holds the formatted message */
96d806a4 46
5eaef520 47 sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
96d806a4 48
5eaef520 49 /* Send zephyr notice */
50 send_zgram(instance, buf);
96d806a4 51
5eaef520 52 /* Log message to critical file */
53 if ((crit = fopen(CRITERRLOG, "a")))
96d806a4 54 {
5eaef520 55 time_t t;
56 char *time_s;
3f6b08ec 57
5eaef520 58 time(&t);
59 time_s = ctime(&t) + 4;
60 time_s[strlen(time_s) - 6] = '\0';
3f6b08ec 61
5eaef520 62 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
63 fclose(crit);
96d806a4 64 }
923cef2a 65
5eaef520 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
5eaef520 75send_zgram(char *inst, char *msg)
96d806a4 76{
2f4a1cd0 77#ifdef ZEPHYR
5eaef520 78 ZNotice_t znotice;
79
80 memset(&znotice, 0, sizeof(znotice));
81 znotice.z_kind = UNSAFE;
82 znotice.z_class = "MOIRA";
83 znotice.z_class_inst = inst;
84 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
85 ZInitialize();
86 znotice.z_message = msg;
87 znotice.z_message_len = strlen(msg) + 1;
88 znotice.z_opcode = "";
89 znotice.z_recipient = "";
90 ZSendNotice(&znotice, ZNOAUTH);
2f4a1cd0 91#endif
92#ifdef SYSLOG
5eaef520 93 {
94 char buf[512];
95 sprintf(buf, "MOIRA: %s %s", inst, msg);
96 syslog(LOG_ERR, buf);
97 }
2f4a1cd0 98#endif
96d806a4 99}
This page took 0.095251 seconds and 5 git commands to generate.