Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / afs / afs_warn.c
blob289593d6baf0d784133d64b08c7fafff7bf5856e
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
11 * afs_warn.c - afs_warn
13 * Implements: afs_warn, afs_warnuser
15 #include <afsconfig.h>
16 #include "afs/param.h"
19 #include "afs/stds.h"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
22 #if !defined(UKERNEL)
24 #if !defined(AFS_LINUX20_ENV)
25 # include <net/if.h>
26 # if defined(AFS_SUN5_ENV)
27 # include <sys/varargs.h>
28 # elif defined(AFS_FBSD_ENV)
29 # include <machine/stdarg.h>
30 # else
31 # include <stdarg.h>
32 # endif
33 #endif
34 #include <netinet/in.h>
36 #ifdef AFS_SGI62_ENV
37 #include "h/hashing.h"
38 #endif
39 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
40 #include <netinet/in_var.h>
41 #endif /* ! AFS_HPUX110_ENV */
42 #endif /* !defined(UKERNEL) */
44 #include "afsincludes.h" /* Afs-based standard headers */
45 #include "afs/afs_stats.h" /* afs statistics */
47 #if defined(AFS_SUN5_ENV)
48 #include <inet/led.h>
49 #include <inet/common.h>
50 #include <netinet/ip6.h>
51 #include <inet/ip.h>
52 #endif
54 #if defined(AFS_AIX_ENV)
55 #include <sys/fp_io.h>
56 #endif
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)
66 char buf[256];
68 vsnprintf(buf, sizeof(buf), fmt, ap);
69 printf(buf);
71 #else
72 # define afs_vprintf(fmt, ap) vprintf(fmt, ap)
73 #endif
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;
81 AFS_STATCNT(afs_warn);
83 if (afs_showflags & GAGCONSOLE) {
84 struct file *fd;
86 /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
87 if (fp_open
88 ("/dev/console", O_WRONLY | O_NOCTTY | O_NDELAY, 0666, 0, FP_SYS,
89 &fd) == 0) {
90 char buf[1024];
91 ssize_t len;
92 ssize_t count;
94 sprintf(buf, fmt, a, b, c, d, e, f, g, h, i);
95 len = strlen(buf);
96 fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
97 fp_close(fd);
101 #else /* AFS_AIX_ENV */
102 static_inline void
103 afs_vwarn(char *fmt, va_list ap)
105 afs_vprintf(fmt, ap);
109 void
110 afs_warn(char *fmt, ...)
112 AFS_STATCNT(afs_warn);
114 if (afs_showflags & GAGCONSOLE) {
115 va_list ap;
117 va_start(ap, fmt);
118 afs_vwarn(fmt, ap);
119 va_end(ap);
122 #endif /* AFS_AIX_ENV */
125 #ifdef AFS_AIX_ENV
126 void
127 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i)
128 char *fmt;
129 void *a, *b, *c, *d, *e, *f, *g, *h, *i;
131 AFS_STATCNT(afs_warnuser);
132 if (afs_showflags & GAGUSER) {
133 # ifdef AFS_GLOBAL_SUNLOCK
134 int haveGlock = ISAFS_GLOCK();
135 /* drop GLOCK for uprintf */
136 if (haveGlock)
137 AFS_GUNLOCK();
138 # endif /* AFS_GLOBAL_SUNLOCK */
139 uprintf(fmt, a, b, c, d, e, f, g, h, i);
140 # ifdef AFS_GLOBAL_SUNLOCK
141 /* regain GLOCK we dropped for uprintf */
142 if (haveGlock)
143 AFS_GLOCK();
144 # endif /* AFS_GLOBAL_SUNLOCK */
147 #else /* AFS_AIX_ENV */
148 # ifdef AFS_WARNUSER_MARINER_ENV
149 static void
150 afs_vwarnuser (char *fmt, va_list ap)
152 # ifdef AFS_GLOBAL_SUNLOCK
153 int haveGlock = ISAFS_GLOCK();
154 /* gain GLOCK for mariner */
155 if (!haveGlock)
156 AFS_GLOCK();
157 # endif /* AFS_GLOBAL_SUNLOCK */
159 if (afs_mariner) {
160 char buf[256];
161 va_list aq;
162 va_copy(aq, ap);
163 /* mariner log the warning */
164 snprintf(buf, sizeof(buf), "warn$");
165 vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, aq);
166 afs_MarinerLog(buf, NULL);
168 vprintf(fmt, ap);
170 # ifdef AFS_GLOBAL_SUNLOCK
171 /* drop GLOCK we got for mariner */
172 if (!haveGlock)
173 AFS_GUNLOCK();
174 # endif /* AFS_GLOBAL_SUNLOCK */
176 # else /* AFS_WARNUSER_MARINER_ENV */
177 static void
178 afs_vwarnuser (char *fmt, va_list ap)
180 # ifdef AFS_GLOBAL_SUNLOCK
181 int haveGlock = ISAFS_GLOCK();
182 /* drop GLOCK */
183 if (haveGlock)
184 AFS_GUNLOCK();
185 # endif /* AFS_GLOBAL_SUNLOCK */
187 afs_vprintf(fmt, ap);
189 # ifdef AFS_GLOBAL_SUNLOCK
190 /* regain GLOCK we dropped */
191 if (haveGlock)
192 AFS_GLOCK();
193 # endif /* AFS_GLOBAL_SUNLOCK */
195 # endif /* AFS_WARNUSER_MARINER_ENV */
197 void
198 afs_warnuser(char *fmt, ...)
200 AFS_STATCNT(afs_warnuser);
201 if (afs_showflags & GAGUSER) {
202 va_list ap;
204 va_start(ap, fmt);
205 afs_vwarnuser(fmt, ap);
206 va_end(ap);
210 #endif /* AFS_AIX_ENV */
213 #ifdef AFS_AIX_ENV
214 void
215 afs_warnall(fmt, a, b, c, d, e, f, g, h, i)
216 char *fmt;
217 void *a, *b, *c, *d, *e, *f, *g, *h, *i;
219 afs_warn(fmt, a, b, c, d, e, f, g, h, i);
220 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i);
223 #else /* AFS_AIX_ENV */
224 /* On Linux both afs_warn and afs_warnuser go to the same
225 * place. Suppress one of them if we're running on Linux.
227 void
228 afs_warnall(char *fmt, ...)
230 va_list ap;
232 # ifdef AFS_LINUX20_ENV
233 AFS_STATCNT(afs_warn);
234 if ((afs_showflags & GAGCONSOLE) || (afs_showflags & GAGUSER)) {
235 va_start(ap, fmt);
236 afs_vwarn(fmt, ap);
237 va_end(ap);
239 # else /* AFS_LINUX20_ENV */
240 AFS_STATCNT(afs_warn);
241 if (afs_showflags & GAGCONSOLE) {
242 va_start(ap, fmt);
243 afs_vwarn(fmt, ap);
244 va_end(ap);
247 AFS_STATCNT(afs_warnuser);
248 if (afs_showflags & GAGUSER) {
249 va_start(ap, fmt);
250 afs_vwarnuser(fmt, ap);
251 va_end(ap);
253 # endif /* AFS_LINUX20_ENV */
255 #endif /* AFS_AIX_ENV */