From 01aa7055142936f73919c48468707ee90df73dbd Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Mon, 28 Sep 2009 10:43:24 +0200 Subject: [PATCH] Make butc logging use va_args Change the logging functions in butc so that they use va_args. This means that we can prototype the logging functions, and kill a bunch more compiler warnings. Reviewed-on: http://gerrit.openafs.org/509 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear --- src/butc/error_macros.h | 10 +++-- src/butc/lwps.c | 85 ++++++++++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/butc/error_macros.h b/src/butc/error_macros.h index 26e8d2bf5..5f6c760ca 100644 --- a/src/butc/error_macros.h +++ b/src/butc/error_macros.h @@ -25,10 +25,12 @@ goto abort_exit; \ } -/*need conversion to varargs*//*extern void ELog(afs_int32 task, char *str, char *a, char *b, char *c, char *d, char *e, char *f, char *g, char *h, char *i, char *j); -extern void ErrorLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, char *str, char *a, char *b, char *c, char *d, char *e, char *f, char *g, char *h, char *i, char *j); -extern void TLog(afs_int32 task, char *str, char *a, char *b, char *c, char *d, char *e, char *f, char *g, char *h, char *i, char *j); -extern void TapeLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, char *str, char *a, char *b, char *c, char *d, char *e, char *f, char *g, char *h, char *i, char *j);*/ +extern void ErrorLog(int debug, afs_int32 task, afs_int32 error1, + afs_int32 error2, char *fmt, ...); +extern void TapeLog(int debug, afs_int32 task, afs_int32 error1, + afs_int32 error2, char *fmt, ...); +extern void TLog(afs_int32 task, char *fmt, ...); + extern void FreeNode(afs_int32 taskID); extern void CreateNode(struct dumpNode **newNode); diff --git a/src/butc/lwps.c b/src/butc/lwps.c index c4fded6cb..3639f74d7 100644 --- a/src/butc/lwps.c +++ b/src/butc/lwps.c @@ -138,14 +138,11 @@ static struct TapeBlock tapeBlock; char tapeVolumeHT[sizeof(struct volumeHeader) + 2 * sizeof(char)]; void -PrintLog(log, error1, error2, str, a, b, c, d, e, f, g, h, i, j) - FILE *log; - afs_int32 error1, error2; - char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +PrintLogStr(FILE *log, afs_int32 error1, afs_int32 error2, char *str) { char *err1, *err2; - fprintf(log, str, a, b, c, d, e, f, g, h, i, j); + fprintf(log, str); if (error1) { err2 = "vols"; switch (error1) { @@ -199,10 +196,8 @@ PrintLog(log, error1, error2, str, a, b, c, d, e, f, g, h, i, j) } void -TapeLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j) - int debug; - afs_int32 task, error1, error2; - char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +TapeLogStr(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, + char *str) { time_t now; char tbuffer[32], *timestr; @@ -214,35 +209,51 @@ TapeLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j) fprintf(logIO, "%s: ", timestr); if (task) fprintf(logIO, "Task %u: ", task); - PrintLog(logIO, error1, error2, str, a, b, c, d, e, f, g, h, i, j); + PrintLogStr(logIO, error1, error2, str); if (lastPass && lastLogIO) { fprintf(lastLogIO, "%s: ", timestr); if (task) fprintf(lastLogIO, "Task %u: ", task); - PrintLog(lastLogIO, error1, error2, str, a, b, c, d, e, f, g, h, i, - j); + PrintLogStr(lastLogIO, error1, error2, str); } /* Now print to the screen if debug level requires */ if (debug <= debugLevel) - PrintLog(stdout, error1, error2, str, a, b, c, d, e, f, g, h, i, j); + PrintLogStr(stdout, error1, error2, str); } void -TLog(task, str, a, b, c, d, e, f, g, h, i, j) - afs_int32 task; - char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +TapeLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, + char *fmt, ...) { + char tmp[1024]; + va_list ap; + + va_start(ap, fmt); + afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + va_end(ap); + + TapeLogStr(debug, task, error1, error2, tmp); +} + +void +TLog(afs_int32 task, char *fmt, ...) +{ + char tmp[1024]; + va_list ap; + + va_start(ap, fmt); + afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + va_end(ap); + /* Sends message to TapeLog and stdout */ - TapeLog(0, task, 0, 0, str, a, b, c, d, e, f, g, h, i, j); + TapeLogStr(0, task, 0, 0, tmp); } void -ErrorLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j) - int debug; - afs_int32 task, error1, error2; - char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +ErrorLogStr(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, + char *errStr) { time_t now; char tbuffer[32], *timestr; @@ -255,18 +266,38 @@ ErrorLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j) /* Print the time and task number */ if (task) fprintf(ErrorlogIO, "Task %u: ", task); - PrintLog(ErrorlogIO, error1, error2, str, a, b, c, d, e, f, g, h, i, j); - TapeLog(debug, task, error1, error2, str, a, b, c, d, e, f, g, h, i, j); + PrintLogStr(ErrorlogIO, error1, error2, errStr); + TapeLogStr(debug, task, error1, error2, errStr); } void -ELog(task, str, a, b, c, d, e, f, g, h, i, j) - afs_int32 task; - char *str, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j; +ErrorLog(int debug, afs_int32 task, afs_int32 error1, afs_int32 error2, + char *fmt, ...) { + char tmp[1024]; + va_list ap; + + va_start(ap, fmt); + afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + va_end(ap); + + ErrorLogStr(debug, task, error1, error2, tmp); + +} + +void +ELog(afs_int32 task, char *fmt, ...) +{ + char tmp[1024]; + va_list ap; + + va_start(ap, fmt); + afs_vsnprintf(tmp, sizeof(tmp), fmt, ap); + va_end(ap); + /* Sends message to ErrorLog, TapeLog and stdout */ - ErrorLog(0, task, 0, 0, str, a, b, c, d, e, f, g, h, i, j); + ErrorLog(0, task, 0, 0, tmp); } /* first proc called by anybody who intends to use the device */ -- 2.39.5