]> andersk Git - moira.git/blame - lib/critical.c
return MR_ARG_TOO_LONG rather than silently truncating long inputs
[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
d5aa7842 23#include <stdio.h>
7ac48069 24#include <string.h>
2f4a1cd0 25#ifdef SYSLOG
26#include <syslog.h>
27#endif
7ac48069 28
29RCSID("$Header$");
96d806a4 30
96d806a4 31/* mode to create the file with */
32#define LOGFILEMODE 0644
33
5a77c71e 34extern char *whoami;
35
8defc06b 36/* This routine sends a class MOIRA zephyrgram of specified instance
955e02e2 37 * and logs to a special logfile the message passed to it via msg
38 * and args in printf format. *** It expects the global variable
39 * whoami to be defined and contain the name of the calling program.
955e02e2 40 */
41
7ac48069 42void critical_alert(char *instance, char *msg, ...)
96d806a4 43{
5eaef520 44 FILE *crit; /* FILE for critical log file */
45 char buf[BUFSIZ]; /* Holds the formatted message */
7ac48069 46 va_list ap;
96d806a4 47
7ac48069 48 va_start(ap, msg);
49 vsprintf(buf, msg, ap);
50 va_end(ap);
96d806a4 51
5eaef520 52 /* Send zephyr notice */
53 send_zgram(instance, buf);
96d806a4 54
5eaef520 55 /* Log message to critical file */
56 if ((crit = fopen(CRITERRLOG, "a")))
96d806a4 57 {
5eaef520 58 time_t t;
59 char *time_s;
3f6b08ec 60
5eaef520 61 time(&t);
62 time_s = ctime(&t) + 4;
63 time_s[strlen(time_s) - 6] = '\0';
3f6b08ec 64
7ac48069 65 fprintf(crit, "%s <%ld> %s\n", time_s, (long)getpid(), buf);
5eaef520 66 fclose(crit);
96d806a4 67 }
923cef2a 68
5eaef520 69 com_err(whoami, 0, buf);
96d806a4 70}
71
72
73
8defc06b 74/* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
96d806a4 75 * errors while sending message.
76 */
77
7ac48069 78void send_zgram(char *inst, char *msg)
96d806a4 79{
2f4a1cd0 80#ifdef ZEPHYR
5eaef520 81 ZNotice_t znotice;
82
83 memset(&znotice, 0, sizeof(znotice));
84 znotice.z_kind = UNSAFE;
85 znotice.z_class = "MOIRA";
86 znotice.z_class_inst = inst;
87 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
88 ZInitialize();
89 znotice.z_message = msg;
90 znotice.z_message_len = strlen(msg) + 1;
91 znotice.z_opcode = "";
92 znotice.z_recipient = "";
93 ZSendNotice(&znotice, ZNOAUTH);
2f4a1cd0 94#endif
95#ifdef SYSLOG
5eaef520 96 {
97 char buf[512];
98 sprintf(buf, "MOIRA: %s %s", inst, msg);
99 syslog(LOG_ERR, buf);
100 }
2f4a1cd0 101#endif
96d806a4 102}
This page took 0.084338 seconds and 5 git commands to generate.