]> andersk Git - moira.git/blob - lib/critical.c
mentioned extra non-GECOS info
[moira.git] / lib / critical.c
1 /* $Header$
2  *
3  * Log and send a zephyrgram about any critical errors.
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>.
8  */
9
10 #include <mit-copyright.h>
11 #include <stdio.h>
12 #include <sys/file.h>
13 #include <zephyr/zephyr.h>
14
15
16 /* log file for critical events that require human intervention */
17 #define CRITERRLOG      "/u1/sms/critical.log"
18
19 /* mode to create the file with */
20 #define LOGFILEMODE     0644
21
22 extern char *whoami;
23
24
25 void critical_alert(instance, msg, args)
26   char *instance;               /* Instance for zephyr gram */
27   char *msg;                    /* printf format message */
28                                 /* args = arguements, printf style */
29   /* This routine sends a class SMS zephyrgram of specified instance
30      and logs to a special logfile the message passed to it via msg
31      and args in printf format.  *** It expects the global variable
32      whoami to be defined and contain the name of the calling program. */
33   /* Note: The part of this code that process the variable arguements
34      was stolen from sprintf(). */
35 {
36     FILE _bufstr;               /* For _doprnt() */
37     FILE *crit;                 /* FILE for critical log file */
38     char buf[BUFSIZ];           /* Holds the formatted message */
39
40     /* Put the fully formatted message into buf */
41     _bufstr._flag = _IOWRT + _IOSTRG;
42     _bufstr._ptr = buf;
43     _bufstr._cnt = BUFSIZ;
44     _doprnt(msg, &args, &_bufstr);
45     putc('\0', &_bufstr);
46
47     /* Send zephyr notice */
48     send_zgram(instance, buf);
49
50     /* Log message to critical file */
51     if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) 
52     {
53         long t;
54         char  *time_s;
55
56         time(&t);
57         time_s = ctime(&t) + 4;
58         time_s[strlen(time_s)-6] = '\0';
59
60         fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
61         fclose(crit);
62     }
63
64     com_err(whoami, 0, buf);
65 }
66
67
68
69 /* Sends a zephyrgram of class "SMS", instance as a parameter.  Ignores
70  * errors while sending message.
71  */
72
73 send_zgram(inst, msg)
74 char *inst;
75 char *msg;
76 {
77     ZNotice_t znotice;
78
79     bzero (&znotice, sizeof (znotice));
80     znotice.z_kind = UNSAFE;
81     znotice.z_class = "SMS";
82     znotice.z_class_inst = inst;
83     znotice.z_default_format = "SMS $instance:\n $message\n";
84     (void) ZInitialize ();
85     znotice.z_message = msg;
86     znotice.z_message_len = strlen(msg) + 1;
87     znotice.z_opcode = "";
88     znotice.z_recipient = "";
89     ZSendNotice(&znotice, ZNOAUTH);
90 }
This page took 0.236668 seconds and 5 git commands to generate.