From 950dec0715de719f90a4cf59293f0c70d42841cc Mon Sep 17 00:00:00 2001 From: Ben Kaduk Date: Thu, 10 Oct 2013 13:50:26 -0400 Subject: [PATCH] Convert buserver to libutil's logging The primary motivation is to get automatic log rotation, but we also get built-in locking for the logging calls. This does have a side effect of changing the format used to print timestamps in the log file. Export WriteLogBuffer from liboafs_util so as to be mostly compatible with the ... idiosyncrasy of LogError()'s previous behavior. Garbage-collect the unused (and un-exported) printHashTable() and LogNetDump(). Change-Id: I860370e60082ea355806b3f1945eee76db7c32e3 Reviewed-on: http://gerrit.openafs.org/10333 Tested-by: BuildBot Reviewed-by: Karl Ramm Reviewed-by: Derrick Brashear --- src/budb/db_hash.c | 2 - src/budb/globals.h | 3 - src/budb/server.c | 106 +++++++---------------------------- src/budb/struct_ops.c | 17 ------ src/util/liboafs_util.la.sym | 1 + 5 files changed, 20 insertions(+), 109 deletions(-) diff --git a/src/budb/db_hash.c b/src/budb/db_hash.c index 445a1a130..7aa2847ad 100644 --- a/src/budb/db_hash.c +++ b/src/budb/db_hash.c @@ -728,8 +728,6 @@ ht_HashInList(struct ubik_trans *ut, struct memoryHashTable *mht, if (dbread(ut, ea, e, e_size)) return BUDB_IO; - /* LogNetDump((struct dump *) e); */ - /* get the address of the next item on the list */ next_ea = ntohl(*(dbadr *) (e + mht->threadOffset)); diff --git a/src/budb/globals.h b/src/budb/globals.h index ed6bfdbb9..b98def316 100644 --- a/src/budb/globals.h +++ b/src/budb/globals.h @@ -29,9 +29,6 @@ struct buServerConfS { char *databaseName; /* database file name */ char *databaseExtension; /* extension (depends on ubik) */ - /* error logging */ - FILE *log; /* log file for status/errors */ - /* ubik and comm. related */ afs_uint32 myHost; afs_uint32 serverList[MAXSERVERS]; /* list of ubik servers */ diff --git a/src/budb/server.c b/src/budb/server.c index bc9281296..3e4bb0150 100644 --- a/src/budb/server.c +++ b/src/budb/server.c @@ -424,16 +424,6 @@ main(int argc, char **argv) strcpy(cellConfDir, AFSDIR_SERVER_ETC_DIRPATH); globalConfPtr->cellConfigdir = cellConfDir; - /* open the log file */ -/* - globalConfPtr->log = fopen(DEFAULT_LOGNAME,"a"); - if ( globalConfPtr->log == NULL ) - { - printf("Can't open log file %s - aborting\n", DEFAULT_LOGNAME); - BUDB_EXIT(-1); - } -*/ - srandom(1); #ifdef AFS_PTHREAD_ENV @@ -451,16 +441,7 @@ main(int argc, char **argv) BUDB_EXIT(0); /* open the log file */ - globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a"); - if (globalConfPtr->log == NULL) { - printf("Can't open log file %s - aborting\n", - AFSDIR_SERVER_BUDBLOG_FILEPATH); - BUDB_EXIT(-1); - } - - /* keep log closed so can remove it */ - - fclose(globalConfPtr->log); + OpenLog(AFSDIR_SERVER_BUDBLOG_FILEPATH); /* open the cell's configuration directory */ LogDebug(4, "opening %s\n", globalConfPtr->cellConfigdir); @@ -622,49 +603,21 @@ consistencyCheckDb(void) void LogDebug(int level, char *fmt, ... ) { - va_list ap; - - va_start(ap, fmt); - if (debugging >= level) { - /* log normally closed so can remove it */ - globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a"); - if (globalConfPtr->log != NULL) { - vfprintf(globalConfPtr->log, fmt, ap); - fflush(globalConfPtr->log); - fclose(globalConfPtr->log); - } + va_list ap; + va_start(ap, fmt); + vFSLog(fmt, ap); + va_end(ap); } - va_end(ap); -} - -static char * -TimeStamp(time_t t) -{ - struct tm *lt; - static char timestamp[20]; - - lt = localtime(&t); - strftime(timestamp, 20, "%m/%d/%Y %H:%M:%S", lt); - return timestamp; } void Log(char *fmt, ...) { va_list ap; - time_t now; va_start(ap, fmt); - globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a"); - if (globalConfPtr->log != NULL) { - now = time(0); - fprintf(globalConfPtr->log, "%s ", TimeStamp(now)); - - vfprintf(globalConfPtr->log, fmt, ap); - fflush(globalConfPtr->log); - fclose(globalConfPtr->log); - } + vFSLog(fmt, ap); va_end(ap); } @@ -672,42 +625,21 @@ void LogError(long code, char *fmt, ... ) { va_list ap; - time_t now; + int len; + char buffer[1024]; va_start(ap, fmt); - globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a"); - - if (globalConfPtr->log != NULL) { - now = time(0); - fprintf(globalConfPtr->log, "%s ", TimeStamp(now)); - - if (code) - fprintf(globalConfPtr->log, "%s: %s\n", afs_error_table_name(code), - afs_error_message(code)); - vfprintf(globalConfPtr->log, fmt, ap ); - fflush(globalConfPtr->log); - fclose(globalConfPtr->log); + len = vsnprintf(buffer, sizeof(buffer), fmt, ap); + va_end(ap); + if (len >= 1024) { + len = 1023; + buffer[1023] = '\0'; } -} - - -/* ---------------- - * debug - * ---------------- - */ - -void -LogNetDump(struct dump *dumpPtr) -{ - struct dump hostDump; - extern buServerConfP globalConfPtr; - - dump_ntoh(dumpPtr, &hostDump); - - globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a"); - if (globalConfPtr->log != NULL) { - printDump(globalConfPtr->log, &hostDump); - fclose(globalConfPtr->log); + /* Be consistent with (unintentional?) historic behavior. */ + if (code) { + FSLog("%s: %s\n", afs_error_table_name(code), afs_error_message(code)); + WriteLogBuffer(buffer, len); + } else { + FSLog("%s", buffer); } } - diff --git a/src/budb/struct_ops.c b/src/budb/struct_ops.c index 367a01766..fbaf14a84 100644 --- a/src/budb/struct_ops.c +++ b/src/budb/struct_ops.c @@ -96,23 +96,6 @@ printDumpEntry(struct budb_dumpEntry *deptr) printPrincipal(&deptr->dumper); } -/* printHashTable - * print the hash table structure, i.e. the header structure. - */ - -void -printHashTable(FILE *fid, struct hashTable *htptr) -{ - fprintf(fid, "functionType = %d\n", htptr->functionType); - fprintf(fid, "threadOffset = %d\n", htptr->threadOffset); - fprintf(fid, "entries = %d\n", htptr->entries); - fprintf(fid, "length = %d\n", htptr->length); - fprintf(fid, "table = %d\n", htptr->table); - fprintf(fid, "progress = %d\n", htptr->progress); - fprintf(fid, "oldLength = %d\n", htptr->oldLength); - fprintf(fid, "oldTable = %d\n", htptr->oldTable); -} - /* printMemoryHashTable * print the hash table structure, i.e. the header structure. */ diff --git a/src/util/liboafs_util.la.sym b/src/util/liboafs_util.la.sym index 730281e52..3642074f6 100644 --- a/src/util/liboafs_util.la.sym +++ b/src/util/liboafs_util.la.sym @@ -12,6 +12,7 @@ OpenLog ReOpenLog SetLogThreadNumProgram SetupLogSignals +WriteLogBuffer afsUUID_from_string afsUUID_to_string afs_htonuuid -- 2.39.5