-/* $Header$
+/* $Id$
*
* Log and send a zephyrgram about any critical errors.
*
- * (c) Copyright 1988 by the Massachusetts Institute of Technology.
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
+ * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
-#include <mit-copyright.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/file.h>
-#include <moira_site.h>
-#ifdef ZEPHYR
+
+#ifdef HAVE_ZEPHYR
+/* need to include before moira.h, which includes krb_et.h, because
+ zephyr.h is broken */
#include <zephyr/zephyr.h>
+/* zephyr.h doesn't prototype this */
+extern Code_t ZSendNotice(ZNotice_t *notice, Z_AuthProc cert_routine);
#endif
-#ifdef SYSLOG
+
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_site.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifndef HAVE_ZEPHYR
#include <syslog.h>
#endif
-#include <string.h>
#include <time.h>
-#include <com_err.h>
+
+RCSID("$Header$");
/* mode to create the file with */
#define LOGFILEMODE 0644
-extern char *whoami;
-
-
/* This routine sends a class MOIRA zephyrgram of specified instance
* and logs to a special logfile the message passed to it via msg
* and args in printf format. *** It expects the global variable
* whoami to be defined and contain the name of the calling program.
- * It's a kludge that it takes a max of 8 arguments in a way that
- * isn't necessarily portable, but varargs doesn't work here and we
- * don't necessarily have vsprintf().
*/
-void critical_alert(char *instance, char *msg, char *arg1, char *arg2,
- char *arg3, char *arg4, char *arg5, char *arg6,
- char *arg7, char *arg8)
+void critical_alert(char *whoami, char *instance, char *msg, ...)
{
- FILE *crit; /* FILE for critical log file */
- char buf[BUFSIZ]; /* Holds the formatted message */
-
- sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
-
- /* Send zephyr notice */
- send_zgram(instance, buf);
+ FILE *crit;
+ char *buf;
+ va_list ap;
+ long start;
/* Log message to critical file */
if ((crit = fopen(CRITERRLOG, "a")))
time_s = ctime(&t) + 4;
time_s[strlen(time_s) - 6] = '\0';
- fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
+ fprintf(crit, "%s <%ld>", time_s, (long)getpid());
+ start = ftell(crit);
+ va_start(ap, msg);
+ vfprintf(crit, msg, ap);
+ va_end(ap);
+ fprintf(crit, "\n");
+
+ buf = malloc(ftell(crit) - start);
fclose(crit);
+
+ if (buf)
+ {
+ va_start(ap, msg);
+ vsprintf(buf, msg, ap);
+ va_end(ap);
+
+ send_zgram(instance, buf);
+ com_err(whoami, 0, buf);
+
+ free(buf);
+ }
}
- com_err(whoami, 0, buf);
+ if (!crit || !buf)
+ {
+ send_zgram(instance, "Couldn't format critical syslog!");
+ com_err(whoami, 0, "Couldn't format critical syslog!");
+ }
}
-
/* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores
* errors while sending message.
*/
-send_zgram(char *inst, char *msg)
+void send_zgram(char *inst, char *msg)
{
-#ifdef ZEPHYR
+#ifdef HAVE_ZEPHYR
ZNotice_t znotice;
memset(&znotice, 0, sizeof(znotice));
znotice.z_opcode = "";
znotice.z_recipient = "";
ZSendNotice(&znotice, ZNOAUTH);
-#endif
-#ifdef SYSLOG
- {
- char buf[512];
- sprintf(buf, "MOIRA: %s %s", inst, msg);
- syslog(LOG_ERR, buf);
- }
+#else
+ char *buf;
+
+ buf = malloc(9 + strlen(inst) + strlen(msg));
+ if (buf)
+ {
+ sprintf(buf, "MOIRA: %s %s", inst, msg);
+ syslog(LOG_ERR, "%s", buf);
+ free(buf);
+ }
#endif
}