From 0c7bb45c91cee0d47fa0263831f7d22889153a36 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 10 Jul 2009 16:13:09 +0100 Subject: [PATCH] Make afs_warn() and afs_warnuser() va_args The afs_warn() and afs_warnuser() functions take a variable number of arguments. Historically, we've handled this by just not prototyping them. This change builds on the work done a while back to get a prototyped osi_Panic() working in the kernel, and contains the same work arounds for platforms with no usable va_args support (HPUX) and those where support is limited (some Darwin, some Linux) Reviewed-on: http://gerrit.openafs.org/27 Reviewed-by: Russ Allbery Verified-by: Russ Allbery Verified-by: Derrick Brashear Reviewed-by: Derrick Brashear --- src/afs/afs_prototypes.h | 19 ++++++------- src/afs/afs_warn.c | 60 +++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index e67f2362a..836c6d4eb 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -924,22 +924,21 @@ extern void print_internet_address(char *preamble, struct srvAddr *sa, char *postamble, int flag); extern afs_int32 afs_data_pointer_to_int32(const void *p); -#if 0 /* problems - need to change to varargs, right now is incorrect usage - * throughout code */ -extern void afs_warn(char *a, long b, long c, long d, long e, long f, long g, - long h, long i, long j); -extern void afs_warnuser(char *a, long b, long c, long d, long e, long f, - long g, long h, long i, long j); -#else -extern void afs_warn(); -extern void afs_warnuser(); -#endif extern void afs_CheckLocks(void); extern int afs_badop(void); extern int afs_noop(void); extern afs_int32 afs_data_pointer_to_int32(const void *p); +/* afs_warn.c */ +#ifdef AFS_AIX_ENV +/* AIX doesn't have usable va_args support in its kernel */ +extern void afs_warn(); +extern void afs_warnuser(); +#else +extern void afs_warn(char *fmt, ...); +extern void afs_warnuser(char *fmt, ...); +#endif /* afs_vcache.c */ extern int afs_ShakeLooseVCaches(afs_int32 anumber); diff --git a/src/afs/afs_warn.c b/src/afs/afs_warn.c index bdccf5fca..1c5f2df13 100644 --- a/src/afs/afs_warn.c +++ b/src/afs/afs_warn.c @@ -22,6 +22,7 @@ #if !defined(UKERNEL) #if !defined(AFS_LINUX20_ENV) #include +#include "stdarg.h" #endif #include @@ -49,25 +50,27 @@ #include #endif +#if defined(AFS_LINUX26_ENV) +# define afs_vprintf(fmt, ap) vprintk(fmt, ap) +#elif (defined(AFS_DARWIN80_ENV) && !defined(AFS_DARWIN90_ENV)) || (defined(AFS_LINUX22_ENV)) +static_inline void afs_vprintf(const char *fmt, va_list ap) { + char buf[256]; + vsnprintf(buf, sizeof(buf), fmt, ap); + printf(buf); +} +#else +# define afs_vprintf(fmt, ap) vprintf(fmt, ap) +#endif -/* * * * * * * - * this code badly needs to be cleaned up... too many ugly ifdefs. - * XXX - */ -#if 0 +#ifdef AFS_AIX_ENV void -afs_warn(char *a, long b, long c, long d, long e, long f, long g, long h, - long i, long j) +afs_warn(fmt, a, b, c, d, e, f, g, h, i) + char *fmt; + void *a, *b, *c, *d, *e, *f, *g, *h, *i; #else void -afs_warn(a, b, c, d, e, f, g, h, i, j) - char *a; -#if defined( AFS_USE_VOID_PTR) - void *b, *c, *d, *e, *f, *g, *h, *i, *j; -#else - long b, c, d, e, f, g, h, i, j; -#endif +afs_warn(char *fmt, ...) #endif { AFS_STATCNT(afs_warn); @@ -84,26 +87,29 @@ afs_warn(a, b, c, d, e, f, g, h, i, j) ssize_t len; ssize_t count; - sprintf(buf, a, b, c, d, e, f, g, h, i, j); + sprintf(buf, fmt, a, b, c, d, e, f, g, h, i); len = strlen(buf); fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count); fp_close(fd); } #else - printf(a, b, c, d, e, f, g, h, i, j); + va_list ap; + + va_start(ap, fmt); + afs_vprintf(fmt, ap); + va_end(ap); #endif } } -#if 0 +#ifdef AFS_AIX_ENV void -afs_warnuser(char *a, long b, long c, long d, long e, long f, long g, long h, - long i, long j) +afs_warnuser(fmt, a, b, c, d, e, f, g, h, i) + char *fmt; + void *a, *b, *c, *d, *e, *f, *g, *h, *i; #else void -afs_warnuser(a, b, c, d, e, f, g, h, i, j) - char *a; - long b, c, d, e, f, g, h, i, j; +afs_warnuser(char *fmt, ...) #endif { AFS_STATCNT(afs_warnuser); @@ -114,7 +120,15 @@ afs_warnuser(a, b, c, d, e, f, g, h, i, j) AFS_GUNLOCK(); #endif /* AFS_GLOBAL_SUNLOCK */ - uprintf(a, b, c, d, e, f, g, h, i, j); +#if defined(AFS_AIX_ENV) + uprintf(fmt, a, b, c, d, e, f, g, h, i); +#else + va_list ap; + + va_start(ap, fmt); + afs_vprintf(fmt, ap); + va_end(ap); +#endif #ifdef AFS_GLOBAL_SUNLOCK if (haveGlock) -- 2.39.5