]> andersk Git - moira.git/blob - lib/critical.c
fix prototyping problems
[moira.git] / lib / critical.c
1 /* $Id $
2  *
3  * Log and send a zephyrgram about any critical errors.
4  *
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>.
8  */
9
10
11 #ifdef ZEPHYR
12 /* need to include before moira.h, which includes krb_et.h, because
13    zephyr.h is broken */
14 #include <zephyr/zephyr.h>
15 /* zephyr.h doesn't prototype this */
16 extern Code_t ZSendNotice(ZNotice_t *notice, Z_AuthProc cert_routine);
17 #endif
18
19 #include <mit-copyright.h>
20 #include <moira.h>
21 #include <moira_site.h>
22
23 #include <stdio.h>
24 #include <string.h>
25 #ifdef SYSLOG
26 #include <syslog.h>
27 #endif
28
29 RCSID("$Header$");
30
31 /* mode to create the file with */
32 #define LOGFILEMODE     0644
33
34 extern char *whoami;
35
36 /* This routine sends a class MOIRA zephyrgram of specified instance
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.
40  */
41
42 void critical_alert(char *instance, char *msg, ...)
43 {
44   FILE *crit;                   /* FILE for critical log file */
45   char buf[BUFSIZ];             /* Holds the formatted message */
46   va_list ap;
47
48   va_start(ap, msg);
49   vsprintf(buf, msg, ap);
50   va_end(ap);
51
52   /* Send zephyr notice */
53   send_zgram(instance, buf);
54
55   /* Log message to critical file */
56   if ((crit = fopen(CRITERRLOG, "a")))
57     {
58       time_t t;
59       char *time_s;
60
61       time(&t);
62       time_s = ctime(&t) + 4;
63       time_s[strlen(time_s) - 6] = '\0';
64
65       fprintf(crit, "%s <%ld> %s\n", time_s, (long)getpid(), buf);
66       fclose(crit);
67     }
68
69   com_err(whoami, 0, buf);
70 }
71
72
73
74 /* Sends a zephyrgram of class "MOIRA", instance as a parameter.  Ignores
75  * errors while sending message.
76  */
77
78 void send_zgram(char *inst, char *msg)
79 {
80 #ifdef ZEPHYR
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);
94 #endif
95 #ifdef SYSLOG
96   {
97     char buf[512];
98     sprintf(buf, "MOIRA: %s %s", inst, msg);
99     syslog(LOG_ERR, buf);
100   }
101 #endif
102 }
This page took 0.039864 seconds and 5 git commands to generate.