6beca876c791dc677fd373b6c388cd727ca9ef21
[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 #if !defined(AFS_LINUX20_ENV)
24 #include <net/if.h>
25 #include "stdarg.h"
26 #endif
27 #include <netinet/in.h>
28
29 #ifdef AFS_SGI62_ENV
30 #include "h/hashing.h"
31 #endif
32 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
33 #include <netinet/in_var.h>
34 #endif /* ! AFS_HPUX110_ENV */
35 #endif /* !defined(UKERNEL) */
36
37 #include "afsincludes.h"        /* Afs-based standard headers */
38 #include "afs/afs_stats.h"      /* afs statistics */
39
40 #if     defined(AFS_SUN56_ENV)
41 #include <inet/led.h>
42 #include <inet/common.h>
43 #if     defined(AFS_SUN58_ENV)
44 #include <netinet/ip6.h>
45 #endif
46 #include <inet/ip.h>
47 #endif
48
49 #if     defined(AFS_AIX_ENV)
50 #include <sys/fp_io.h>
51 #endif
52
53 #if defined(AFS_LINUX26_ENV)
54 # define afs_vprintf(fmt, ap) vprintk(fmt, ap)
55 #elif defined(AFS_SGI_ENV)
56 # define afs_vprintf(fmt, ap) icmn_err(CE_WARN, fmt, ap)
57 #elif (defined(AFS_DARWIN80_ENV) && !defined(AFS_DARWIN90_ENV)) || (defined(AFS_LINUX22_ENV))
58 static_inline void
59 afs_vprintf(const char *fmt, va_list ap)
60 {
61     char buf[256];
62
63     vsnprintf(buf, sizeof(buf), fmt, ap);
64     printf(buf);
65 }
66 #else
67 # define afs_vprintf(fmt, ap) vprintf(fmt, ap)
68 #endif
69
70 #ifdef AFS_AIX_ENV
71 void
72 afs_warn(fmt, a, b, c, d, e, f, g, h, i)
73     char *fmt;
74     void *a, *b, *c, *d, *e, *f, *g, *h, *i;
75 #else
76 void
77 afs_warn(char *fmt, ...)
78 #endif
79 {
80     AFS_STATCNT(afs_warn);
81
82     if (afs_showflags & GAGCONSOLE) {
83 #if defined(AFS_AIX_ENV)
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 #else
100         va_list ap;
101
102         va_start(ap, fmt);
103         afs_vprintf(fmt, ap);
104         va_end(ap);
105 #endif
106     }
107 }
108
109 #ifdef AFS_AIX_ENV
110 void
111 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i)
112     char *fmt;
113     void *a, *b, *c, *d, *e, *f, *g, *h, *i;
114 #else
115 void
116 afs_warnuser(char *fmt, ...)
117 #endif
118 {
119 #if defined(AFS_WARNUSER_MARINER_ENV)
120     char buf[256];
121 #endif
122     AFS_STATCNT(afs_warnuser);
123     if (afs_showflags & GAGUSER) {
124 #if !defined(AFS_AIX_ENV)
125         va_list ap;
126 #endif
127 #ifdef AFS_GLOBAL_SUNLOCK
128         int haveGlock = ISAFS_GLOCK();
129 #if defined(AFS_WARNUSER_MARINER_ENV)
130         /* gain GLOCK for mariner */
131         if (!haveGlock)
132             AFS_GLOCK();
133 #else
134         /* drop GLOCK for uprintf */
135         if (haveGlock)
136             AFS_GUNLOCK();
137 #endif
138 #endif /* AFS_GLOBAL_SUNLOCK */
139
140 #if defined(AFS_AIX_ENV)
141         uprintf(fmt, a, b, c, d, e, f, g, h, i);
142 #else
143         va_start(ap, fmt);
144 #if defined(AFS_WARNUSER_MARINER_ENV)
145         /* mariner log the warning */
146         snprintf(buf, sizeof(buf), "warn$");
147         vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
148         afs_MarinerLog(buf, NULL);
149         va_end(ap);
150         va_start(ap, fmt);
151         vprintf(fmt, ap);
152 #else
153         afs_vprintf(fmt, ap);
154 #endif
155         va_end(ap);
156 #endif
157
158 #ifdef AFS_GLOBAL_SUNLOCK
159 #if defined(AFS_WARNUSER_MARINER_ENV)
160         /* drop GLOCK we got for mariner */
161         if (!haveGlock)
162             AFS_GUNLOCK();
163 #else
164         /* regain GLOCK we dropped for uprintf */
165         if (haveGlock)
166             AFS_GLOCK();
167 #endif
168 #endif /* AFS_GLOBAL_SUNLOCK */
169     }
170 }