X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/5a77c71e72ded0898773c291b8e17b8bcbf089e7..50a232a9d445d62f4b7a8847a638ba2fb553a421:/lib/critical.c diff --git a/lib/critical.c b/lib/critical.c index dbfde118..27913d2e 100644 --- a/lib/critical.c +++ b/lib/critical.c @@ -1,15 +1,26 @@ /* $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 + * . */ +#include #include +#include #include +#include +#ifdef ZEPHYR #include - - -/* log file for critical events that require human intervention */ -#define CRITERRLOG "/u1/sms/critical.log" +#endif +#ifdef SYSLOG +#include +#endif +#include +#include +#include /* mode to create the file with */ #define LOGFILEMODE 0644 @@ -17,27 +28,25 @@ extern char *whoami; -void critical_alert(instance, msg, args) +/* 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(instance, msg, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8) char *instance; /* Instance for zephyr gram */ char *msg; /* printf format message */ - /* 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. *** 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(). */ + char *arg1, *arg2, *arg3, *arg4, *arg5, *arg6, *arg7, *arg8; { - FILE _bufstr; /* For _doprnt() */ FILE *crit; /* FILE for critical log file */ char buf[BUFSIZ]; /* Holds the formatted message */ - /* Put the fully formatted message into buf */ - _bufstr._flag = _IOWRT + _IOSTRG; - _bufstr._ptr = buf; - _bufstr._cnt = BUFSIZ; - _doprnt(msg, &args, &_bufstr); - putc('\0', &_bufstr); + sprintf(buf, msg, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); /* Send zephyr notice */ send_zgram(instance, buf); @@ -45,7 +54,7 @@ void critical_alert(instance, msg, args) /* Log message to critical file */ if ((crit = fopen(CRITERRLOG, "a")) != (FILE *)NULL) { - long t; + time_t t; char *time_s; time(&t); @@ -61,7 +70,7 @@ void critical_alert(instance, msg, args) -/* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores +/* Sends a zephyrgram of class "MOIRA", instance as a parameter. Ignores * errors while sending message. */ @@ -69,17 +78,30 @@ send_zgram(inst, msg) char *inst; char *msg; { +#ifdef ZEPHYR ZNotice_t znotice; +#ifdef POSIX + memset (&znotice, 0, sizeof (znotice)); +#else bzero (&znotice, sizeof (znotice)); +#endif znotice.z_kind = UNSAFE; - znotice.z_class = "SMS"; + znotice.z_class = "MOIRA"; znotice.z_class_inst = inst; - znotice.z_default_format = "SMS $instance:\n $message\n"; + znotice.z_default_format = "MOIRA $instance on $fromhost:\n $message\n"; (void) ZInitialize (); znotice.z_message = msg; znotice.z_message_len = strlen(msg) + 1; 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); + } +#endif }