]> andersk Git - moira.git/blobdiff - lib/critical.c
make it work with negative keys
[moira.git] / lib / critical.c
index 583d3de532ad0af9775e925e5ea871c74a78fc4a..c3502e036d4e73db9f2c06c89e305c246627e7af 100644 (file)
@@ -1,19 +1,34 @@
 /* $Header$
  *
  * 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>.
  */
 
+/* At Athena, we use zephyr & not syslog.  Change the following line 
+ * if necessary */
+#define ZEPHYR
+
+
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <sys/file.h>
+#ifdef ZEPHYR
 #include <zephyr/zephyr.h>
+#endif
+#ifdef SYSLOG
+#include <syslog.h>
+#endif
+#include <sms_app.h>
 
 
-/* log file for critical events that require human intervention */
-#define CRITERRLOG     "/u1/sms/critical.log"
-
 /* mode to create the file with */
 #define LOGFILEMODE    0644
 
+extern char *whoami;
+
 
 void critical_alert(instance, msg, args)
   char *instance;              /* Instance for zephyr gram */
@@ -21,12 +36,13 @@ void critical_alert(instance, msg, args)
                                /* args = arguements, printf style */
   /* This routine sends a class SMS zephyrgram of specified instance
      and logs to a special logfile the message passed to it via msg
-     and args in printf format. */
+     and args in printf format.  *** It expects the global variable
+     whoami to be defined and contain the name of the calling program. */
   /* Note: The part of this code that process the variable arguements
      was stolen from sprintf(). */
 {
     FILE _bufstr;              /* For _doprnt() */
-    int crit;                  /* File descriptor for critical log file */
+    FILE *crit;                        /* FILE for critical log file */
     char buf[BUFSIZ];          /* Holds the formatted message */
 
     /* Put the fully formatted message into buf */
@@ -40,12 +56,20 @@ void critical_alert(instance, msg, args)
     send_zgram(instance, buf);
 
     /* Log message to critical file */
-    if ((crit = open(CRITERRLOG, 
-                    O_WRONLY | O_APPEND | O_CREAT, LOGFILEMODE)) >= 0)
+    if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) 
     {
-       write(crit,buf,strlen(buf));
-       close(crit);
+       long t;
+       char  *time_s;
+
+       time(&t);
+       time_s = ctime(&t) + 4;
+       time_s[strlen(time_s)-6] = '\0';
+
+       fprintf(crit, "%s <%d> %s\n", time_s, getpid(), buf);
+       fclose(crit);
     }
+
+    com_err(whoami, 0, buf);
 }
 
 
@@ -58,6 +82,7 @@ send_zgram(inst, msg)
 char *inst;
 char *msg;
 {
+#ifdef ZEPHYR
     ZNotice_t znotice;
 
     bzero (&znotice, sizeof (znotice));
@@ -71,4 +96,12 @@ char *msg;
     znotice.z_opcode = "";
     znotice.z_recipient = "";
     ZSendNotice(&znotice, ZNOAUTH);
+#endif
+#ifdef SYSLOG
+    {
+       char buf[512];
+       sprintf(buf, "SMS: %s %s", inst, msg);
+       syslog(LOG_ERR, buf);
+    }
+#endif
 }
This page took 0.041606 seconds and 4 git commands to generate.