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