Catch up to FreeBSD non-MPSAFE deorbit
[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 # 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_SUN5_ENV)
46 #include <inet/led.h>
47 #include <inet/common.h>
48 #include <netinet/ip6.h>
49 #include <inet/ip.h>
50 #endif
51
52 #if     defined(AFS_AIX_ENV)
53 #include <sys/fp_io.h>
54 #endif
55
56 #if defined(AFS_LINUX26_ENV)
57 # define afs_vprintf(fmt, ap) vprintk(fmt, ap)
58 #elif defined(AFS_SGI_ENV)
59 # define afs_vprintf(fmt, ap) icmn_err(CE_WARN, fmt, ap)
60 #elif (defined(AFS_DARWIN80_ENV) && !defined(AFS_DARWIN90_ENV)) || (defined(AFS_LINUX22_ENV))
61 static_inline void
62 afs_vprintf(const char *fmt, va_list ap)
63 {
64     char buf[256];
65
66     vsnprintf(buf, sizeof(buf), fmt, ap);
67     printf(buf);
68 }
69 #else
70 # define afs_vprintf(fmt, ap) vprintf(fmt, ap)
71 #endif
72
73 #ifdef AFS_AIX_ENV
74 void
75 afs_warn(fmt, a, b, c, d, e, f, g, h, i)
76     char *fmt;
77     void *a, *b, *c, *d, *e, *f, *g, *h, *i;
78 #else
79 void
80 afs_warn(char *fmt, ...)
81 #endif
82 {
83     AFS_STATCNT(afs_warn);
84
85     if (afs_showflags & GAGCONSOLE) {
86 #if defined(AFS_AIX_ENV)
87         struct file *fd;
88
89         /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
90         if (fp_open
91             ("/dev/console", O_WRONLY | O_NOCTTY | O_NDELAY, 0666, 0, FP_SYS,
92              &fd) == 0) {
93             char buf[1024];
94             ssize_t len;
95             ssize_t count;
96
97             sprintf(buf, fmt, a, b, c, d, e, f, g, h, i);
98             len = strlen(buf);
99             fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
100             fp_close(fd);
101         }
102 #else
103         va_list ap;
104
105         va_start(ap, fmt);
106         afs_vprintf(fmt, ap);
107         va_end(ap);
108 #endif
109     }
110 }
111
112 #ifdef AFS_AIX_ENV
113 void
114 afs_warnuser(fmt, a, b, c, d, e, f, g, h, i)
115     char *fmt;
116     void *a, *b, *c, *d, *e, *f, *g, *h, *i;
117 #else
118 void
119 afs_warnuser(char *fmt, ...)
120 #endif
121 {
122 #if defined(AFS_WARNUSER_MARINER_ENV)
123     char buf[256];
124 #endif
125     AFS_STATCNT(afs_warnuser);
126     if (afs_showflags & GAGUSER) {
127 #if !defined(AFS_AIX_ENV)
128         va_list ap;
129 #endif
130 #ifdef AFS_GLOBAL_SUNLOCK
131         int haveGlock = ISAFS_GLOCK();
132 #if defined(AFS_WARNUSER_MARINER_ENV)
133         /* gain GLOCK for mariner */
134         if (!haveGlock)
135             AFS_GLOCK();
136 #else
137         /* drop GLOCK for uprintf */
138         if (haveGlock)
139             AFS_GUNLOCK();
140 #endif
141 #endif /* AFS_GLOBAL_SUNLOCK */
142
143 #if defined(AFS_AIX_ENV)
144         uprintf(fmt, a, b, c, d, e, f, g, h, i);
145 #else
146         va_start(ap, fmt);
147 #if defined(AFS_WARNUSER_MARINER_ENV)
148         /* mariner log the warning */
149         snprintf(buf, sizeof(buf), "warn$");
150         vsnprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
151         afs_MarinerLog(buf, NULL);
152         va_end(ap);
153         va_start(ap, fmt);
154         vprintf(fmt, ap);
155 #else
156         afs_vprintf(fmt, ap);
157 #endif
158         va_end(ap);
159 #endif
160
161 #ifdef AFS_GLOBAL_SUNLOCK
162 #if defined(AFS_WARNUSER_MARINER_ENV)
163         /* drop GLOCK we got for mariner */
164         if (!haveGlock)
165             AFS_GUNLOCK();
166 #else
167         /* regain GLOCK we dropped for uprintf */
168         if (haveGlock)
169             AFS_GLOCK();
170 #endif
171 #endif /* AFS_GLOBAL_SUNLOCK */
172     }
173 }