]> andersk Git - moira.git/blobdiff - lib/critical.c
Build shared libmoira via libtool.
[moira.git] / lib / critical.c
index 4cbb12d5dff2fb60a6437e993f31ce49044e3500..f4ef4b2d90af3b0bd853ef4412daa0961484198b 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 
-#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>
@@ -21,36 +21,30 @@ extern Code_t ZSendNotice(ZNotice_t *notice, Z_AuthProc cert_routine);
 #include <moira_site.h>
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#ifdef SYSLOG
+#ifndef HAVE_ZEPHYR
 #include <syslog.h>
 #endif
+#include <time.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.
  */
 
-void critical_alert(char *instance, char *msg, ...)
+void critical_alert(char *whoami, char *instance, char *msg, ...)
 {
-  FILE *crit;                  /* FILE for critical log file */
-  char buf[BUFSIZ];            /* Holds the formatted message */
+  FILE *crit;
+  char *buf;
   va_list ap;
-
-  va_start(ap, msg);
-  vsprintf(buf, msg, ap);
-  va_end(ap);
-
-  /* Send zephyr notice */
-  send_zgram(instance, buf);
+  long start;
 
   /* Log message to critical file */
   if ((crit = fopen(CRITERRLOG, "a")))
@@ -62,22 +56,44 @@ void critical_alert(char *instance, char *msg, ...)
       time_s = ctime(&t) + 4;
       time_s[strlen(time_s) - 6] = '\0';
 
-      fprintf(crit, "%s <%ld> %s\n", time_s, (long)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.
  */
 
 void send_zgram(char *inst, char *msg)
 {
-#ifdef ZEPHYR
+#ifdef HAVE_ZEPHYR
   ZNotice_t znotice;
 
   memset(&znotice, 0, sizeof(znotice));
@@ -91,12 +107,15 @@ void send_zgram(char *inst, char *msg)
   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
 }
This page took 0.359526 seconds and 4 git commands to generate.