SOLARIS: Include sys/varargs.h for kernel stdarg
[openafs.git] / src / afs / afs_warn.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * afs_warn.c - afs_warn
12  *
13  * Implements: afs_warn, afs_warnuser
14  */
15 #include <afsconfig.h>
16 #include "afs/param.h"
17
18
19 #include "afs/stds.h"
20 #include "afs/sysincludes.h"    /* Standard vendor system headers */
21
22 #if !defined(UKERNEL)
23
24 #if !defined(AFS_LINUX20_ENV)
25 # include <net/if.h>
26 # if defined(AFS_SUN58_ENV)
27 #  include <sys/varargs.h>
28 # else
29 #  include <stdarg.h>
30 # endif
31 #endif
32 #include <netinet/in.h>
33
34 #ifdef AFS_SGI62_ENV
35 #include "h/hashing.h"
36 #endif
37 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
38 #include <netinet/in_var.h>
39 #endif /* ! AFS_HPUX110_ENV */
40 #endif /* !defined(UKERNEL) */
41
42 #include "afsincludes.h"        /* Afs-based standard headers */
43 #include "afs/afs_stats.h"      /* afs statistics */
44
45 #if     defined(AFS_SUN56_ENV)
46 #include <inet/led.h>
47 #include <inet/common.h>
48 #if     defined(AFS_SUN58_ENV)
49 #include <netinet/ip6.h>
50 #endif
51 #include <inet/ip.h>
52 #endif
53
54 #if     defined(AFS_AIX_ENV)
55 #include <sys/fp_io.h>
56 #endif
57
58 #if defined(AFS_LINUX26_ENV)
59 # define afs_vprintf(fmt, ap) vprintk(fmt, ap)
60 #elif defined(AFS_SGI_ENV)
61 # define afs_vprintf(fmt, ap) icmn_err(CE_WARN, fmt, ap)
62 #elif (defined(AFS_DARWIN80_ENV) && !defined(AFS_DARWIN90_ENV)) || (defined(AFS_LINUX22_ENV))
63 static_inline void
64 afs_vprintf(const char *fmt, va_list ap)
65 {
66     char buf[256];
67
68     vsnprintf(buf, sizeof(buf), fmt, ap);
69     printf(buf);
70 }
71 #else
72 # define afs_vprintf(fmt, ap) vprintf(fmt, ap)
73 #endif
74
75 #ifdef AFS_AIX_ENV
76 void
77 afs_warn(fmt, a, b, c, d, e, f, g, h, i)
78     char *fmt;
79     void *a, *b, *c, *d, *e, *f, *g, *h, *i;
80 #else
81 void
82 afs_warn(char *fmt, ...)
83 #endif
84 {
85     AFS_STATCNT(afs_warn);
86
87     if (afs_showflags & GAGCONSOLE) {
88 #if defined(AFS_AIX_ENV)
89         struct file *fd;
90
91         /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
92         if (fp_open
93             ("/dev/console", O_WRONLY | O_NOCTTY | O_NDELAY, 0666, 0, FP_SYS,
94              &fd) == 0) {
95             char buf[1024];
96             ssize_t len;
97             ssize_t count;
98
99             sprintf(buf, fmt, a, b, c, d, e, f, g, h, i);
100             len = strlen(buf);
101             fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
102             fp_close(fd);
103         }
104 #else
105         va_list ap;
106
107         va_start(ap, fmt);
108         afs_vprintf(fmt, ap);
109         va_end(ap);
110 #endif
111     }
112 }
113
114 #ifdef AFS_AIX_ENV
115 void
116 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i)
117     char *fmt;
118     void *a, *b, *c, *d, *e, *f, *g, *h, *i;
119 #else
120 void
121 afs_warnuser(char *fmt, ...)
122 #endif
123 {
124 #if defined(AFS_WARNUSER_MARINER_ENV)
125     char buf[256];
126 #endif
127     AFS_STATCNT(afs_warnuser);
128     if (afs_showflags & GAGUSER) {
129 #if !defined(AFS_AIX_ENV)
130         va_list ap;
131 #endif
132 #ifdef AFS_GLOBAL_SUNLOCK
133         int haveGlock = ISAFS_GLOCK();
134 #if defined(AFS_WARNUSER_MARINER_ENV)
135         /* gain GLOCK for mariner */
136         if (!haveGlock)
137             AFS_GLOCK();
138 #else
139         /* drop GLOCK for uprintf */
140         if (haveGlock)
141             AFS_GUNLOCK();
142 #endif
143 #endif /* AFS_GLOBAL_SUNLOCK */
144
145 #if defined(AFS_AIX_ENV)
146         uprintf(fmt, a, b, c, d, e, f, g, h, i);
147 #else
148         va_start(ap, fmt);
149 #if defined(AFS_WARNUSER_MARINER_ENV)
150         /* mariner log the warning */
151         snprintf(buf, sizeof(buf), "warn$");
152         vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
153         afs_MarinerLog(buf, NULL);
154         va_end(ap);
155         va_start(ap, fmt);
156         vprintf(fmt, ap);
157 #else
158         afs_vprintf(fmt, ap);
159 #endif
160         va_end(ap);
161 #endif
162
163 #ifdef AFS_GLOBAL_SUNLOCK
164 #if defined(AFS_WARNUSER_MARINER_ENV)
165         /* drop GLOCK we got for mariner */
166         if (!haveGlock)
167             AFS_GUNLOCK();
168 #else
169         /* regain GLOCK we dropped for uprintf */
170         if (haveGlock)
171             AFS_GLOCK();
172 #endif
173 #endif /* AFS_GLOBAL_SUNLOCK */
174     }
175 }