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