|
|
1.1 ! root 1: /* ! 2: * $Source: /usr/src/kerberosIV/krb/RCS/log.c,v $ ! 3: * $Author: kfall $ ! 4: * ! 5: * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute ! 6: * of Technology. ! 7: * ! 8: * For copying and distribution information, please see the file ! 9: * <mit-copyright.h>. ! 10: */ ! 11: ! 12: #ifndef lint ! 13: static char *rcsid_log_c = ! 14: "$Header: /usr/src/kerberosIV/krb/RCS/log.c,v 4.8 90/06/25 20:56:49 kfall Exp $"; ! 15: #endif /* lint */ ! 16: ! 17: #include <mit-copyright.h> ! 18: #include <sys/time.h> ! 19: #include <stdio.h> ! 20: ! 21: #include <des.h> ! 22: #include <krb.h> ! 23: #include <klog.h> ! 24: ! 25: static char *log_name = KRBLOG; ! 26: static is_open; ! 27: ! 28: /* ! 29: * This file contains three logging routines: set_logfile() ! 30: * to determine the file that log entries should be written to; ! 31: * and log() and new_log() to write log entries to the file. ! 32: */ ! 33: ! 34: /* ! 35: * log() is used to add entries to the logfile (see set_logfile() ! 36: * below). Note that it is probably not portable since it makes ! 37: * assumptions about what the compiler will do when it is called ! 38: * with less than the correct number of arguments which is the ! 39: * way it is usually called. ! 40: * ! 41: * The log entry consists of a timestamp and the given arguments ! 42: * printed according to the given "format". ! 43: * ! 44: * The log file is opened and closed for each log entry. ! 45: * ! 46: * The return value is undefined. ! 47: */ ! 48: ! 49: /*VARARGS1 */ ! 50: void log(format,a1,a2,a3,a4,a5,a6,a7,a8,a9,a0) ! 51: char *format; ! 52: int a1,a2,a3,a4,a5,a6,a7,a8,a9,a0; ! 53: { ! 54: FILE *logfile, *fopen(); ! 55: long time(),now; ! 56: struct tm *tm; ! 57: char *month_sname(); ! 58: ! 59: if ((logfile = fopen(log_name,"a")) == NULL) ! 60: return; ! 61: ! 62: (void) time(&now); ! 63: tm = localtime(&now); ! 64: ! 65: fprintf(logfile,"%2d-%s-%02d %02d:%02d:%02d ",tm->tm_mday, ! 66: month_sname(tm->tm_mon + 1),tm->tm_year, ! 67: tm->tm_hour, tm->tm_min, tm->tm_sec); ! 68: fprintf(logfile,format,a1,a2,a3,a4,a5,a6,a7,a8,a9,a0); ! 69: fprintf(logfile,"\n"); ! 70: (void) fclose(logfile); ! 71: return; ! 72: } ! 73: ! 74: /* ! 75: * set_logfile() changes the name of the file to which ! 76: * messages are logged. If set_logfile() is not called, ! 77: * the logfile defaults to KRBLOG, defined in "krb.h". ! 78: */ ! 79: ! 80: set_logfile(filename) ! 81: char *filename; ! 82: { ! 83: log_name = filename; ! 84: is_open = 0; ! 85: } ! 86: ! 87: /* ! 88: * new_log() appends a log entry containing the give time "t" and the ! 89: * string "string" to the logfile (see set_logfile() above). The file ! 90: * is opened once and left open. The routine returns 1 on failure, 0 ! 91: * on success. ! 92: */ ! 93: ! 94: new_log(t,string) ! 95: long t; ! 96: char *string; ! 97: { ! 98: static FILE *logfile; ! 99: ! 100: long time(); ! 101: struct tm *tm; ! 102: ! 103: if (!is_open) { ! 104: if ((logfile = fopen(log_name,"a")) == NULL) return(1); ! 105: is_open = 1; ! 106: } ! 107: ! 108: if (t) { ! 109: tm = localtime(&t); ! 110: ! 111: fprintf(logfile,"\n%2d-%s-%02d %02d:%02d:%02d %s",tm->tm_mday, ! 112: month_sname(tm->tm_mon + 1),tm->tm_year, ! 113: tm->tm_hour, tm->tm_min, tm->tm_sec, string); ! 114: } ! 115: else { ! 116: fprintf(logfile,"\n%20s%s","",string); ! 117: } ! 118: ! 119: (void) fflush(logfile); ! 120: return(0); ! 121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.