]> andersk Git - moira.git/blame_incremental - lib/critical.c
Change group security when renaming groups.
[moira.git] / lib / critical.c
... / ...
CommitLineData
1/* $Id$
2 *
3 * Log and send a zephyrgram about any critical errors.
4 *
5 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 */
9
10
11#ifdef HAVE_ZEPHYR
12/* need to include before moira.h, which includes krb_et.h, because
13 zephyr.h is broken */
14#include <zephyr/zephyr.h>
15/* zephyr.h doesn't prototype this */
16extern Code_t ZSendNotice(ZNotice_t *notice, Z_AuthProc cert_routine);
17#endif
18
19#include <mit-copyright.h>
20#include <moira.h>
21#include <moira_site.h>
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#ifndef HAVE_ZEPHYR
27#include <syslog.h>
28#endif
29#include <time.h>
30
31RCSID("$Header$");
32
33/* mode to create the file with */
34#define LOGFILEMODE 0644
35
36extern char *whoami;
37
38/* This routine sends a class MOIRA zephyrgram of specified instance
39 * and logs to a special logfile the message passed to it via msg
40 * and args in printf format. *** It expects the global variable
41 * whoami to be defined and contain the name of the calling program.
42 */
43
44void critical_alert(char *instance, char *msg, ...)
45{
46 FILE *crit;
47 char *buf;
48 va_list ap;
49 long start;
50
51 /* Log message to critical file */
52 if ((crit = fopen(CRITERRLOG, "a")))
53 {
54 time_t t;
55 char *time_s;
56
57 time(&t);
58 time_s = ctime(&t) + 4;
59 time_s[strlen(time_s) - 6] = '\0';
60
61 fprintf(crit, "%s <%ld>", time_s, (long)getpid());
62 start = ftell(crit);
63 va_start(ap, msg);
64 vfprintf(crit, msg, ap);
65 va_end(ap);
66 fprintf(crit, "\n");
67
68 buf = malloc(ftell(crit) - start);
69 fclose(crit);
70
71 if (buf)
72 {
73 va_start(ap, msg);
74 vsprintf(buf, msg, ap);
75 va_end(ap);
76
77 send_zgram(instance, buf);
78 com_err(whoami, 0, buf);
79
80 free(buf);
81 }
82 }
83
84 if (!crit || !buf)
85 {
86 send_zgram(instance, "Couldn't format critical syslog!");
87 com_err(whoami, 0, "Couldn't format critical syslog!");
88 }
89}
90
91
92/* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
93 * errors while sending message.
94 */
95
96void send_zgram(char *inst, char *msg)
97{
98#ifdef HAVE_ZEPHYR
99 ZNotice_t znotice;
100
101 memset(&znotice, 0, sizeof(znotice));
102 znotice.z_kind = UNSAFE;
103 znotice.z_class = "MOIRA";
104 znotice.z_class_inst = inst;
105 znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n";
106 ZInitialize();
107 znotice.z_message = msg;
108 znotice.z_message_len = strlen(msg) + 1;
109 znotice.z_opcode = "";
110 znotice.z_recipient = "";
111 ZSendNotice(&znotice, ZNOAUTH);
112#else
113 char *buf;
114
115 buf = malloc(9 + strlen(inst) + strlen(msg));
116 if (buf)
117 {
118 sprintf(buf, "MOIRA: %s %s", inst, msg);
119 syslog(LOG_ERR, "%s", buf);
120 free(buf);
121 }
122#endif
123}
This page took 0.273289 seconds and 5 git commands to generate.