]> andersk Git - moira.git/blame - lib/critical.c
remove non-portable code stolen from sprintf()
[moira.git] / lib / critical.c
CommitLineData
96d806a4 1/* $Header$
2 *
3 * Log and send a zephyrgram about any critical errors.
babbc197 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>.
96d806a4 8 */
9
2f4a1cd0 10/* At Athena, we use zephyr & not syslog. Change the following line
11 * if necessary */
12#define ZEPHYR
13
14
babbc197 15#include <mit-copyright.h>
96d806a4 16#include <stdio.h>
17#include <sys/file.h>
2f4a1cd0 18#ifdef ZEPHYR
96d806a4 19#include <zephyr/zephyr.h>
2f4a1cd0 20#endif
21#ifdef SYSLOG
22#include <syslog.h>
23#endif
b1a67c82 24#include <sms_app.h>
96d806a4 25
26
96d806a4 27/* mode to create the file with */
28#define LOGFILEMODE 0644
29
5a77c71e 30extern char *whoami;
31
96d806a4 32
955e02e2 33/* This routine sends a class SMS zephyrgram of specified instance
34 * and logs to a special logfile the message passed to it via msg
35 * and args in printf format. *** It expects the global variable
36 * whoami to be defined and contain the name of the calling program.
37 * It's a kludge that it takes a max of 8 arguments in a way that
38 * isn't necessarily portable, but varargs doesn't work here and we
39 * don't have vsprintf().
40 */
41
42void critical_alert(instance, msg, arg1, arg2, arg3, arg4,
43 arg5, arg6, arg7, arg8)
96d806a4 44 char *instance; /* Instance for zephyr gram */
45 char *msg; /* printf format message */
955e02e2 46 char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8;
96d806a4 47{
3f6b08ec 48 FILE *crit; /* FILE for critical log file */
96d806a4 49 char buf[BUFSIZ]; /* Holds the formatted message */
50
955e02e2 51 sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
96d806a4 52
53 /* Send zephyr notice */
54 send_zgram(instance, buf);
55
56 /* Log message to critical file */
3f6b08ec 57 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
96d806a4 58 {
3f6b08ec 59 long t;
60 char *time_s;
61
62 time(&t);
63 time_s = ctime(&t) + 4;
64 time_s[strlen(time_s)-6] = '\0';
65
66 fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
67 fclose(crit);
96d806a4 68 }
923cef2a 69
70 com_err(whoami, 0, buf);
96d806a4 71}
72
73
74
75/* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores
76 * errors while sending message.
77 */
78
79send_zgram(inst, msg)
80char *inst;
81char *msg;
82{
2f4a1cd0 83#ifdef ZEPHYR
96d806a4 84 ZNotice_t znotice;
85
86 bzero (&znotice, sizeof (znotice));
87 znotice.z_kind = UNSAFE;
88 znotice.z_class = "SMS";
89 znotice.z_class_inst = inst;
90 znotice.z_default_format = "SMS $instance:\n $message\n";
91 (void) ZInitialize ();
92 znotice.z_message = msg;
93 znotice.z_message_len = strlen(msg) + 1;
94 znotice.z_opcode = "";
95 znotice.z_recipient = "";
96 ZSendNotice(&znotice, ZNOAUTH);
2f4a1cd0 97#endif
98#ifdef SYSLOG
99 {
100 char buf[512];
101 sprintf(buf, "SMS: %s %s", inst, msg);
102 syslog(LOG_ERR, buf);
103 }
104#endif
96d806a4 105}
This page took 0.174931 seconds and 5 git commands to generate.