Make afs_warn() and afs_warnuser() va_args
authorSimon Wilkinson <sxw@inf.ed.ac.uk>
Fri, 10 Jul 2009 15:13:09 +0000 (16:13 +0100)
committerDerrick Brashear <shadow@dementia.org>
Thu, 16 Jul 2009 18:04:39 +0000 (12:04 -0600)
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 <rra@stanford.edu>
Verified-by: Russ Allbery <rra@stanford.edu>
Verified-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/afs/afs_prototypes.h
src/afs/afs_warn.c

index e67f236..836c6d4 100644 (file)
@@ -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);
index bdccf5f..1c5f2df 100644 (file)
@@ -22,6 +22,7 @@
 #if !defined(UKERNEL)
 #if !defined(AFS_LINUX20_ENV)
 #include <net/if.h>
+#include "stdarg.h"
 #endif
 #include <netinet/in.h>
 
 #include <sys/fp_io.h>
 #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)