afs: Fix some afs_conn overcounts
[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_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>
35
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) */
43
44 #include "afsincludes.h"        /* Afs-based standard headers */
45 #include "afs/afs_stats.h"      /* afs statistics */
46
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
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 {
81     AFS_STATCNT(afs_warn);
82
83     if (afs_showflags & GAGCONSOLE) {
84         struct file *fd;
85
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;
93
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);
98         }
99     }
100 }
101 #else /* AFS_AIX_ENV */
102 static_inline void
103 afs_vwarn(char *fmt, va_list ap)
104 {
105     afs_vprintf(fmt, ap);
106 }
107
108
109 void
110 afs_warn(char *fmt, ...)
111 {
112     AFS_STATCNT(afs_warn);
113
114     if (afs_showflags & GAGCONSOLE) {
115         va_list ap;
116
117         va_start(ap, fmt);
118         afs_vwarn(fmt, ap);
119         va_end(ap);
120     }
121 }
122 #endif /* AFS_AIX_ENV */
123
124
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;
130 {
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 */
145     }
146 }
147 #else  /* AFS_AIX_ENV */
148 # ifdef AFS_WARNUSER_MARINER_ENV
149 static void
150 afs_vwarnuser (char *fmt, va_list ap)
151 {
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 */
158
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);
167     }
168     vprintf(fmt, ap);
169
170 #  ifdef AFS_GLOBAL_SUNLOCK
171     /* drop GLOCK we got for mariner */
172     if (!haveGlock)
173         AFS_GUNLOCK();
174 #  endif /* AFS_GLOBAL_SUNLOCK */
175 }
176 # else /* AFS_WARNUSER_MARINER_ENV */
177 static void
178 afs_vwarnuser (char *fmt, va_list ap)
179 {
180 #  ifdef AFS_GLOBAL_SUNLOCK
181     int haveGlock = ISAFS_GLOCK();
182     /* drop GLOCK */
183     if (haveGlock)
184         AFS_GUNLOCK();
185 #  endif /* AFS_GLOBAL_SUNLOCK */
186
187     afs_vprintf(fmt, ap);
188
189 #  ifdef AFS_GLOBAL_SUNLOCK
190     /* regain GLOCK we dropped */
191     if (haveGlock)
192         AFS_GLOCK();
193 #  endif /* AFS_GLOBAL_SUNLOCK */
194 }
195 # endif /* AFS_WARNUSER_MARINER_ENV */
196
197 void
198 afs_warnuser(char *fmt, ...)
199 {
200     AFS_STATCNT(afs_warnuser);
201     if (afs_showflags & GAGUSER) {
202         va_list ap;
203
204         va_start(ap, fmt);
205         afs_vwarnuser(fmt, ap);
206         va_end(ap);
207     }
208 }
209
210 #endif /* AFS_AIX_ENV */
211
212
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;
218 {
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);
221
222 }
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.
226  */
227 void
228 afs_warnall(char *fmt, ...)
229 {
230     va_list ap;
231
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);
238     }
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);
245     }
246
247     AFS_STATCNT(afs_warnuser);
248     if (afs_showflags & GAGUSER) {
249         va_start(ap, fmt);
250         afs_vwarnuser(fmt, ap);
251         va_end(ap);
252     }
253 # endif /* AFS_LINUX20_ENV */
254 }
255 #endif /* AFS_AIX_ENV */