]> andersk Git - moira.git/blame_incremental - lib/critical.c
remove non-portable code stolen from sprintf()
[moira.git] / lib / critical.c
... / ...
CommitLineData
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/* At Athena, we use zephyr & not syslog. Change the following line
11 * if necessary */
12#define ZEPHYR
13
14
15#include <mit-copyright.h>
16#include <stdio.h>
17#include <sys/file.h>
18#ifdef ZEPHYR
19#include <zephyr/zephyr.h>
20#endif
21#ifdef SYSLOG
22#include <syslog.h>
23#endif
24#include <sms_app.h>
25
26
27/* mode to create the file with */
28#define LOGFILEMODE 0644
29
30extern char *whoami;
31
32
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)
44 char *instance; /* Instance for zephyr gram */
45 char *msg; /* printf format message */
46 char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8;
47{
48 FILE *crit; /* FILE for critical log file */
49 char buf[BUFSIZ]; /* Holds the formatted message */
50
51 sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
52
53 /* Send zephyr notice */
54 send_zgram(instance, buf);
55
56 /* Log message to critical file */
57 if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL)
58 {
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);
68 }
69
70 com_err(whoami, 0, buf);
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{
83#ifdef ZEPHYR
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);
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
105}
This page took 0.032389 seconds and 5 git commands to generate.