Remove the RCSID macro
[openafs.git] / src / afs / afs_osi.c
1 /*
2  * Copyrigh 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 #include <afsconfig.h>
11 #include "afs/param.h"
12
13
14 #include "afs/sysincludes.h"    /* Standard vendor system headers */
15 #include "afsincludes.h"        /* Afs-based standard headers */
16 #include "afs/afs_stats.h"      /* afs statistics */
17 #ifdef AFS_AIX_ENV
18 #include <sys/adspace.h>        /* for vm_att(), vm_det() */
19 #endif
20
21 /* osi_Init -- do once per kernel installation initialization.
22  *     -- On Solaris this is called from modload initialization.
23  *     -- On AIX called from afs_config.
24  *     -- On HP called from afsc_link.
25  *     -- On SGI called from afs_init. */
26
27 afs_lock_t afs_ftf;             /* flush text lock */
28
29 #ifdef AFS_SGI53_ENV
30 lock_t afs_event_lock;
31 #endif
32
33 #ifdef AFS_SGI64_ENV
34 flid_t osi_flid;
35 #endif
36
37 struct AFS_UCRED *afs_osi_credp;
38
39 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
40 kmutex_t afs_global_lock;
41 kmutex_t afs_rxglobal_lock;
42 #endif
43
44 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
45 long afs_global_owner;
46 #endif
47
48 #if defined(AFS_OSF_ENV)
49 simple_lock_data_t afs_global_lock;
50 #endif
51
52 #if defined(AFS_DARWIN_ENV) 
53 #ifdef AFS_DARWIN80_ENV
54 lck_mtx_t  *afs_global_lock;
55 #else
56 struct lock__bsd__ afs_global_lock;
57 #endif
58 #endif
59
60 #if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD50_ENV)
61 struct lock afs_global_lock;
62 struct proc *afs_global_owner;
63 #endif
64 #ifdef AFS_FBSD50_ENV
65 struct mtx afs_global_mtx;
66 #endif
67
68 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
69 thread_t afs_global_owner;
70 #endif /* AFS_OSF_ENV */
71
72 #if defined(AFS_AIX41_ENV)
73 simple_lock_data afs_global_lock;
74 #endif
75
76 void
77 osi_Init(void)
78 {
79     static int once = 0;
80     if (once++ > 0)             /* just in case */
81         return;
82 #if     defined(AFS_HPUX_ENV)
83     osi_InitGlock();
84 #else /* AFS_HPUX_ENV */
85 #if defined(AFS_GLOBAL_SUNLOCK)
86 #if defined(AFS_SGI62_ENV)
87     mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock");
88 #elif defined(AFS_OSF_ENV)
89     usimple_lock_init(&afs_global_lock);
90     afs_global_owner = (thread_t) 0;
91 #elif defined(AFS_FBSD50_ENV)
92 #if defined(AFS_FBSD80_ENV) && defined(WITNESS)
93     /* "lock_initalized" (sic) can panic, checks a flag bit
94      * is unset _before_ init */
95     memset(&afs_global_mtx, 0, sizeof(struct mtx));
96 #endif
97     mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF);
98 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
99 #if !defined(AFS_DARWIN80_ENV)
100     lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0);
101 #endif
102     afs_global_owner = 0;
103 #elif defined(AFS_AIX41_ENV)
104     lock_alloc((void *)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1);
105     simple_lock_init((void *)&afs_global_lock);
106 #elif !defined(AFS_LINUX22_ENV)
107     /* Linux initialization in osi directory. Should move the others. */
108     mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
109 #endif
110 #endif /* AFS_GLOBAL_SUNLOCK */
111 #endif /* AFS_HPUX_ENV */
112
113     if (!afs_osicred_initialized) {
114 #if defined(AFS_DARWIN80_ENV)
115         afs_osi_ctxtp_initialized = 0;
116         afs_osi_ctxtp = NULL; /* initialized in afs_Daemon since it has
117                                   a proc reference that cannot be changed */
118 #endif
119 #if defined(AFS_XBSD_ENV)
120         /* Can't just invent one, must use crget() because of mutex */
121         afs_osi_credp = crdup(osi_curcred());
122 #else
123         memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
124 #if defined(AFS_LINUX26_ENV)
125         afs_osi_cred.cr_group_info = groups_alloc(0);
126 #endif
127 #if defined(AFS_DARWIN80_ENV)
128         afs_osi_cred.cr_ref = 1; /* kauth_cred_get_ref needs 1 existing ref */
129 #else
130         crhold(&afs_osi_cred);  /* don't let it evaporate */
131 #endif
132
133         afs_osi_credp = &afs_osi_cred;
134 #endif
135         afs_osicred_initialized = 1;
136     }
137 #ifdef AFS_SGI64_ENV
138     osi_flid.fl_pid = osi_flid.fl_sysid = 0;
139 #endif
140
141     init_et_to_sys_error();
142 }
143
144 /* mask signals in afsds */
145 void
146 afs_osi_MaskSignals(void)
147 {
148 #ifdef AFS_LINUX22_ENV
149     osi_linux_mask();
150 #endif
151 }
152
153 /* unmask signals in rxk listener */
154 void
155 afs_osi_UnmaskRxkSignals(void)
156 {
157 }
158
159 /* Two hacks to try and fix afsdb */
160 void 
161 afs_osi_MaskUserLoop()
162 {
163 #ifdef AFS_DARWIN_ENV
164     afs_osi_Invisible();
165     afs_osi_fullSigMask();
166 #else
167     afs_osi_MaskSignals();
168 #endif
169 }
170
171 void 
172 afs_osi_UnmaskUserLoop(void)
173 {
174 #ifdef AFS_DARWIN_ENV
175     afs_osi_fullSigRestore();
176 #endif
177 }
178
179 /* register rxk listener proc info */
180 void
181 afs_osi_RxkRegister(void)
182 {
183 }
184
185 /* procedure for making our processes as invisible as we can */
186 void
187 afs_osi_Invisible(void)
188 {
189 #ifdef AFS_LINUX22_ENV
190     afs_osi_MaskSignals();
191 #elif defined(AFS_SUN5_ENV)
192     curproc->p_flag |= SSYS;
193 #elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV)
194     set_system_proc(u.u_procp);
195 #elif defined(AFS_DARWIN80_ENV)
196 #elif defined(AFS_DARWIN_ENV)
197     /* maybe call init_process instead? */
198     current_proc()->p_flag |= P_SYSTEM;
199 #elif defined(AFS_XBSD_ENV)
200     curproc->p_flag |= P_SYSTEM;
201 #elif defined(AFS_SGI_ENV)
202     vrelvm();
203 #endif
204
205     AFS_STATCNT(osi_Invisible);
206 }
207
208 void
209 afs_osi_Visible(void)
210 {
211 #if defined(AFS_SUN5_ENV)
212     curproc->p_flag &= ~SSYS;
213 #elif defined(AFS_DARWIN80_ENV)
214 #elif defined(AFS_DARWIN_ENV)
215     /* maybe call init_process instead? */
216     current_proc()->p_flag &= ~P_SYSTEM;
217 #elif defined(AFS_XBSD_ENV)
218     curproc->p_flag &= ~P_SYSTEM;
219 #endif
220 }
221
222 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
223 /* set the real time */
224 void
225 afs_osi_SetTime(osi_timeval_t * atv)
226 {
227 #if defined(AFS_AIX32_ENV)
228     struct timestruc_t t;
229
230     t.tv_sec = atv->tv_sec;
231     t.tv_nsec = atv->tv_usec * 1000;
232     ksettimer(&t);              /*  Was -> settimer(TIMEOFDAY, &t); */
233 #elif defined(AFS_SUN55_ENV)
234     stime(atv->tv_sec);
235 #elif defined(AFS_SUN5_ENV)
236     /*
237      * To get more than second resolution we can use adjtime. The problem
238      * is that the usecs from the server are wrong (by now) so it isn't
239      * worth complicating the following code.
240      */
241     struct stimea {
242         time_t time;
243     } sta;
244
245     sta.time = atv->tv_sec;
246
247     stime(&sta, NULL);
248 #elif defined(AFS_SGI_ENV)
249     struct stimea {
250         sysarg_t time;
251     } sta;
252
253     AFS_GUNLOCK();
254     sta.time = atv->tv_sec;
255     stime(&sta);
256     AFS_GLOCK();
257 #elif defined(AFS_DARWIN_ENV)
258 #ifndef AFS_DARWIN80_ENV
259     AFS_GUNLOCK();
260     setthetime(atv);
261     AFS_GLOCK();
262 #endif
263 #else
264     /* stolen from kern_time.c */
265 #ifndef AFS_AUX_ENV
266     boottime.tv_sec += atv->tv_sec - time.tv_sec;
267 #endif
268 #ifdef AFS_HPUX_ENV
269     {
270 #if !defined(AFS_HPUX1122_ENV)
271         /* drop the setting of the clock for now. spl7 is not
272          * known on hpux11.22
273          */
274         register ulong_t s;
275         struct timeval t;
276         t.tv_sec = atv->tv_sec;
277         t.tv_usec = atv->tv_usec;
278         s = spl7();
279         time = t;
280         (void)splx(s);
281         resettodr(atv);
282 #endif
283     }
284 #else
285     {
286         register int s;
287         s = splclock();
288         time = *atv;
289         (void)splx(s);
290     }
291     resettodr();
292 #endif
293 #ifdef  AFS_AUX_ENV
294     logtchg(atv->tv_sec);
295 #endif
296 #endif /* AFS_DARWIN_ENV */
297     AFS_STATCNT(osi_SetTime);
298 }
299 #endif /* AFS_LINUX20_ENV */
300
301
302 void
303 shutdown_osi(void)
304 {
305     AFS_STATCNT(shutdown_osi);
306 #ifdef AFS_DARWIN80_ENV
307     if (afs_osi_ctxtp_initialized && afs_osi_ctxtp) {
308        vfs_context_rele(afs_osi_ctxtp);
309        afs_osi_ctxtp = NULL;
310        afs_osi_ctxtp_initialized = 0;
311     }
312     shutdown_osisleep();
313 #endif
314     if (afs_cold_shutdown) {
315         LOCK_INIT(&afs_ftf, "afs_ftf");
316     }
317 }
318
319 #ifndef AFS_OBSD_ENV
320 int
321 afs_osi_suser(void *cr)
322 {
323 #if defined(AFS_SUN510_ENV)
324     return (priv_policy(cr, PRIV_SYS_SUSER_COMPAT, B_FALSE, EPERM, NULL) == 0);
325 #elif defined(AFS_SUN5_ENV)
326     return afs_suser(cr);
327 #else
328     return afs_suser(NULL);
329 #endif
330 }
331 #endif