]> andersk Git - moira.git/blame - lib/critical.c
s/strsave/strdup
[moira.git] / lib / critical.c
CommitLineData
7ac48069 1/* $Id $
96d806a4 2 *
3 * Log and send a zephyrgram about any critical errors.
babbc197 4 *
7ac48069 5 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
96d806a4 8 */
9
7ac48069 10
2f4a1cd0 11#ifdef ZEPHYR
7ac48069 12/* need to include before moira.h, which includes krb_et.h, because
13 zephyr.h is broken */
96d806a4 14#include <zephyr/zephyr.h>
7ac48069 15/* zephyr.h doesn't prototype this */
16extern Code_t ZSendNotice(ZNotice_t *notice, Z_AuthProc cert_routine);
2f4a1cd0 17#endif
7ac48069 18
19#include <mit-copyright.h>
20#include <moira.h>
21#include <moira_site.h>
22
23#include <string.h>
2f4a1cd0 24#ifdef SYSLOG
25#include <syslog.h>
26#endif
7ac48069 27
28RCSID("$Header$");
96d806a4 29
96d806a4 30/* mode to create the file with */
31#define LOGFILEMODE 0644
32
5a77c71e 33extern char *whoami;
34
8defc06b 35/* This routine sends a class MOIRA zephyrgram of specified instance
955e02e2 36 * and logs to a special logfile the message passed to it via msg
37 * and args in printf format. *** It expects the global variable
38 * whoami to be defined and contain the name of the calling program.
955e02e2 39 */
40
7ac48069 41void critical_alert(char *instance, char *msg, ...)
96d806a4 42{
5eaef520 43 FILE *crit; /* FILE for critical log file */
44 char buf[BUFSIZ]; /* Holds the formatted message */
7ac48069 45 va_list ap;
96d806a4 46
7ac48069 47 va_start(ap, msg);
48 vsprintf(buf, msg, ap);
49 va_end(ap);
96d806a4 50
5eaef520 51 /* Send zephyr notice */
52 send_zgram(instance, buf);
96d806a4 53
5eaef520 54 /* Log message to critical file */
55 if ((crit = fopen(CRITERRLOG, "a")))
96d806a4 56 {
5eaef520 57 time_t t;
58 char *time_s;
3f6b08ec 59
5eaef520 60 time(&t);
61 time_s = ctime(&t) + 4;
62 time_s[strlen(time_s) - 6] = '\0';
3f6b08ec 63
7ac48069 64 fprintf(crit, "%s <%ld> %s\n", time_s, (long)getpid(), buf);
5eaef520 65 fclose(crit);
96d806a4 66 }
923cef2a 67
5eaef520 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
7ac48069 77void send_zgram(char *inst, char *msg)
96d806a4 78{
2f4a1cd0 79#ifdef ZEPHYR
5eaef520 80 ZNotice_t znotice;
81
82 memset(&znotice, 0, sizeof(znotice));
83 znotice.z_kind = UNSAFE;
84 znotice.z_class = "MOIRA";
85 znotice.z_class_inst = inst;
86 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
87 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
5eaef520 95 {
96 char buf[512];
97 sprintf(buf, "MOIRA: %s %s", inst, msg);
98 syslog(LOG_ERR, buf);
99 }
2f4a1cd0 100#endif
96d806a4 101}
This page took 0.101597 seconds and 5 git commands to generate.