tviced-log-thread-at-high-loglevel-20050224
[openafs.git] / src / viced / viced.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 /*  viced.c     - File Server main loop                                  */
11 /*                                                                       */
12 /*  Date: 5/1/85                                                         */
13 /*                                                                       */
14 /*  Function    - This routine has the initialization code for           */
15 /*                FileServer II                                          */
16 /*                                                                       */
17 /* ********************************************************************** */
18
19 #include <afsconfig.h>
20 #include <afs/param.h>
21
22 RCSID
23     ("$Header$");
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <sys/types.h>
29 #include <afs/procmgmt.h>       /* signal(), kill(), wait(), etc. */
30 #include <sys/stat.h>
31 #ifdef AFS_NT40_ENV
32 #include <fcntl.h>
33 #include <io.h>
34 #include <windows.h>
35 #include <WINNT/afsevent.h>
36 #else
37 #include <sys/file.h>
38 #include <netinet/in.h>
39 #include <netdb.h>
40 #include <unistd.h>             /* sysconf() */
41
42 #ifdef HAVE_STRING_H
43 #include <string.h>
44 #else
45 #ifdef HAVE_STRINGS_H
46 #include <strings.h>
47 #endif
48 #endif
49
50 #ifndef ITIMER_REAL
51 #include <sys/time.h>
52 #endif /* ITIMER_REAL */
53 #include <sys/resource.h>
54 #endif /* AFS_NT40_ENV */
55 #include <afs/stds.h>
56 #undef SHARED
57 #include <rx/xdr.h>
58 #include <afs/nfs.h>
59 #ifdef AFS_PTHREAD_ENV
60 #include <assert.h>
61 #else /* AFS_PTHREAD_ENV */
62 #include <afs/assert.h>
63 #endif /* AFS_PTHREAD_ENV */
64 #include <lwp.h>
65 #include <lock.h>
66 #include <afs/ptclient.h>
67 #include <afs/afsint.h>
68 #include <afs/vldbint.h>
69 #include <afs/errors.h>
70 #include <afs/ihandle.h>
71 #include <afs/vnode.h>
72 #include <afs/volume.h>
73 #include <afs/auth.h>
74 #include <afs/cellconfig.h>
75 #include <afs/acl.h>
76 #include <afs/prs_fs.h>
77 #include <rx/rx.h>
78 #include <rx/rxkad.h>
79 #include <afs/keys.h>
80 #include <afs/afs_args.h>
81 #include <afs/vlserver.h>
82 #include <afs/afsutil.h>
83 #include <afs/fileutil.h>
84 #ifndef AFS_NT40_ENV
85 #include <afs/netutils.h>
86 #endif
87 #include "viced.h"
88 #include "host.h"
89 #ifdef AFS_PTHREAD_ENV
90 #include "softsig.h"
91 char *(*threadNameProgram) ();
92 #endif
93 #if defined(AFS_SGI_ENV)
94 #include "sys/schedctl.h"
95 #include "sys/lock.h"
96 #endif
97 #include <rx/rx_globals.h>
98
99 #ifdef O_LARGEFILE
100 #define afs_stat        stat64
101 #define afs_fstat       fstat64
102 #define afs_open        open64
103 #define afs_fopen       fopen64
104 #else /* !O_LARGEFILE */
105 #define afs_stat        stat
106 #define afs_fstat       fstat
107 #define afs_open        open
108 #define afs_fopen       fopen
109 #endif /* !O_LARGEFILE */
110
111 extern int BreakVolumeCallBacks(), InitCallBack();
112 extern int BreakVolumeCallBacks(), InitCallBack(), BreakLaterCallBacks();
113 extern int BreakVolumeCallBacksLater();
114 extern int LogLevel, etext;
115 extern afs_int32 BlocksSpare, PctSpare;
116
117 void ShutDown(void);
118 static void ClearXStatValues(), NewParms(), PrintCounters();
119 static void ResetCheckDescriptors(void), ResetCheckSignal(void);
120 static void CheckSignal(void);
121 extern int GetKeysFromToken();
122 extern int RXAFS_ExecuteRequest();
123 extern int RXSTATS_ExecuteRequest();
124 afs_int32 Do_VLRegisterRPC();
125
126 int eventlog = 0, rxlog = 0;
127 FILE *debugFile;
128 FILE *console = NULL;
129
130 #ifdef AFS_PTHREAD_ENV
131 pthread_mutex_t fsync_glock_mutex;
132 pthread_cond_t fsync_cond;
133 #else
134 char fsync_wait[1];
135 #endif /* AFS_PTHREAD_ENV */
136
137 #ifdef AFS_NT40_ENV
138 #define AFS_QUIETFS_ENV 1
139 #define NT_OPEN_MAX    1024     /* This is an arbitrary no. we came up with for 
140                                  * now. We hope this will be replaced by a more
141                                  * intelligent estimate later. */
142 #endif
143
144 int SystemId;                   /* ViceID of "Administrators" */
145 int SystemAnyUser;              /* Viceid of "System:AnyUser" */
146 prlist SystemAnyUserCPS;        /* CPS for "system:AnyUser */
147 int AnonymousID = 0;            /* ViceId of "Anonymous" */
148 prlist AnonCPS;                 /* CPS for "Anonymous" */
149
150 struct afsconf_dir *confDir;    /* Configuration dir object */
151
152 int restartMode = RESTART_ORDINARY;
153
154 int Testing = 0;                /* for ListViceInodes */
155
156 /*
157  * Home for the performance statistics.
158  */
159 struct afs_PerfStats afs_perfstats;
160
161 extern int LogLevel;
162 extern int Statistics;
163
164 int busyonrst = 1;
165 int timeout = 30;
166 int SawSpare;
167 int SawPctSpare;
168 int debuglevel = 0;
169 int printBanner = 0;
170 int rxJumbograms = 1;           /* default is to send and receive jumbograms. */
171 afs_int32 implicitAdminRights = PRSFS_LOOKUP;   /* The ADMINISTER right is 
172                                                  * already implied */
173 afs_int32 readonlyServer = 0;
174
175 int stack = 24;
176 int stackSize = 24000;
177 int fiveminutes = 300;          /* 5 minutes.  Change this for debugging only */
178 int CurrentConnections = 0;
179 int hostaclRefresh = 7200;      /* refresh host clients' acls every 2 hrs */
180 #if defined(AFS_SGI_ENV)
181 int SawLock;
182 #endif
183 time_t StartTime;
184
185 int rxpackets = 150;            /* 100 */
186 int nSmallVns = 400;            /* 200 */
187 int large = 400;                /* 200 */
188 int volcache = 400;             /* 400 */
189 int numberofcbs = 60000;        /* 60000 */
190 int lwps = 9;                   /* 6 */
191 int buffs = 90;                 /* 70 */
192 int novbc = 0;                  /* Enable Volume Break calls */
193 int busy_threshold = 600;
194 int abort_threshold = 10;
195 int udpBufSize = 0;             /* UDP buffer size for receive */
196 int sendBufSize = 16384;        /* send buffer size */
197
198 struct timeval tp;
199
200 /*
201  * FileServer's name and IP address, both network byte order and
202  * host byte order.
203  */
204 #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */
205
206 char FS_HostName[128] = "localhost";
207 afs_uint32 FS_HostAddr_NBO;
208 afs_uint32 FS_HostAddr_HBO;
209 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
210 /* All addresses in FS_HostAddrs are in NBO */
211 afsUUID FS_HostUUID;
212
213 static void FlagMsg();
214
215 /*
216  * Home for the performance statistics.
217  */
218
219 /* DEBUG HACK */
220 static void
221 CheckDescriptors()
222 {
223 #ifndef AFS_NT40_ENV
224     struct afs_stat status;
225     register int tsize = getdtablesize();
226     register int i;
227     for (i = 0; i < tsize; i++) {
228         if (afs_fstat(i, &status) != -1) {
229             printf("%d: dev %x, inode %u, length %u, type/mode %x\n", i,
230                    status.st_dev, status.st_ino, status.st_size,
231                    status.st_mode);
232         }
233     }
234     fflush(stdout);
235     ResetCheckDescriptors();
236 #endif
237 }                               /*CheckDescriptors */
238
239
240 #ifdef AFS_PTHREAD_ENV
241 void
242 CheckSignal_Signal(x)
243 {
244     CheckSignal();
245 }
246
247 void
248 ShutDown_Signal(x)
249 {
250     ShutDown();
251 }
252
253 void
254 CheckDescriptors_Signal(x)
255 {
256     CheckDescriptors();
257 }
258 #else /* AFS_PTHREAD_ENV */
259 void
260 CheckSignal_Signal(x)
261 {
262     IOMGR_SoftSig(CheckSignal, 0);
263 }
264
265 void
266 ShutDown_Signal(x)
267 {
268     IOMGR_SoftSig(ShutDown, 0);
269 }
270
271 void
272 CheckDescriptors_Signal(x)
273 {
274     IOMGR_SoftSig(CheckDescriptors, 0);
275 }
276 #endif /* AFS_PTHREAD_ENV */
277
278 /* check whether caller is authorized to manage RX statistics */
279 int
280 fs_rxstat_userok(struct rx_call *call)
281 {
282     return afsconf_SuperUser(confDir, call, NULL);
283 }
284
285 static void
286 ResetCheckSignal(void)
287 {
288     int signo;
289
290 #if defined(AFS_HPUX_ENV)
291     signo = SIGPOLL;
292 #else
293 #if defined(AFS_NT40_ENV)
294     signo = SIGUSR2;
295 #else
296     signo = SIGXCPU;
297 #endif
298 #endif
299
300 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
301     softsig_signal(signo, CheckSignal_Signal);
302 #else
303     signal(signo, CheckSignal_Signal);
304 #endif
305 }
306
307 static void
308 ResetCheckDescriptors(void)
309 {
310 #ifndef AFS_NT40_ENV
311 #if defined(AFS_PTHREAD_ENV)
312     softsig_signal(SIGTERM, CheckDescriptors_Signal);
313 #else
314     (void)signal(SIGTERM, CheckDescriptors_Signal);
315 #endif
316 #endif
317 }
318
319 #if defined(AFS_PTHREAD_ENV)
320 char *
321 threadName(void)
322 {
323     char threadid[16];
324     if (LogLevel > 999) {
325         afs_snprintf(threadid, 16, "%d", pthread_getspecific(rx_thread_id_key));
326         return threadid;
327     } else 
328         return NULL;
329 }
330 #endif
331
332 /* proc called by rxkad module to get a key */
333 static int
334 get_key(char *arock, register afs_int32 akvno, char *akey)
335 {
336     /* find the key */
337     static struct afsconf_key tkey;
338     register afs_int32 code;
339
340     if (!confDir) {
341         ViceLog(0, ("conf dir not open\n"));
342         return 1;
343     }
344     code = afsconf_GetKey(confDir, akvno, tkey.key);
345     if (code)
346         return code;
347     memcpy(akey, tkey.key, sizeof(tkey.key));
348     return 0;
349
350 }                               /*get_key */
351
352 #ifndef AFS_NT40_ENV
353 int
354 viced_syscall(afs_uint32 a3, afs_uint32 a4, void *a5)
355 {
356     afs_uint32 rcode;
357     void (*old) ();
358
359 #ifndef AFS_LINUX20_ENV
360     old = (void (*)())signal(SIGSYS, SIG_IGN);
361 #endif
362     rcode = syscall(AFS_SYSCALL, 28 /* AFSCALL_CALL */ , a3, a4, a5);
363 #ifndef AFS_LINUX20_ENV
364     signal(SIGSYS, old);
365 #endif
366
367     return rcode;
368 }
369 #endif
370
371 #if !defined(AFS_NT40_ENV)
372 #include "AFS_component_version_number.c"
373 #endif /* !AFS_NT40_ENV */
374
375 #define MAXADMINNAME 64
376 char adminName[MAXADMINNAME];
377
378 static void
379 CheckAdminName()
380 {
381     int fd = 0;
382     struct afs_stat status;
383
384     if ((afs_stat("/AdminName", &status)) ||    /* if file does not exist */
385         (status.st_size <= 0) ||        /* or it is too short */
386         (status.st_size >= (MAXADMINNAME)) ||   /* or it is too long */
387         !(fd = afs_open("/AdminName", O_RDONLY, 0))) {  /* or the open fails */
388         strcpy(adminName, "System:Administrators");     /* use the default name */
389     } else {
390         (void)read(fd, adminName, status.st_size);      /* use name from the file */
391     }
392     if (fd)
393         close(fd);              /* close fd if it was opened */
394
395 }                               /*CheckAdminName */
396
397
398 static void
399 setThreadId(char *s)
400 {
401 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
402     /* set our 'thread-id' so that the host hold table works */
403     MUTEX_ENTER(&rx_stats_mutex);       /* protects rxi_pthread_hinum */
404     ++rxi_pthread_hinum;
405     pthread_setspecific(rx_thread_id_key, (void *)rxi_pthread_hinum);
406     MUTEX_EXIT(&rx_stats_mutex);
407     ViceLog(0,
408             ("Set thread id %d for '%s'\n",
409              pthread_getspecific(rx_thread_id_key), s));
410 #endif
411 }
412
413 /* This LWP does things roughly every 5 minutes */
414 static void
415 FiveMinuteCheckLWP()
416 {
417     static int msg = 0;
418     char tbuffer[32];
419
420     ViceLog(1, ("Starting five minute check process\n"));
421     setThreadId("FiveMinuteCheckLWP");
422     while (1) {
423 #ifdef AFS_PTHREAD_ENV
424         sleep(fiveminutes);
425 #else /* AFS_PTHREAD_ENV */
426         IOMGR_Sleep(fiveminutes);
427 #endif /* AFS_PTHREAD_ENV */
428
429         /* close the log so it can be removed */
430         ReOpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);      /* don't trunc, just append */
431         ViceLog(2, ("Cleaning up timed out callbacks\n"));
432         if (CleanupTimedOutCallBacks())
433             ViceLog(5, ("Timed out callbacks deleted\n"));
434         ViceLog(2, ("Set disk usage statistics\n"));
435         VSetDiskUsage();
436         if (FS_registered == 1)
437             Do_VLRegisterRPC();
438         /* Force wakeup in case we missed something; pthreads does timedwait */
439 #ifndef AFS_PTHREAD_ENV
440         LWP_NoYieldSignal(fsync_wait);
441 #endif
442         if (printBanner && (++msg & 1)) {       /* Every 10 minutes */
443             time_t now = FT_ApproxTime();
444             if (console != NULL) {
445 #ifndef AFS_QUIETFS_ENV
446                 fprintf(console, "File server is running at %s\r",
447                         afs_ctime(&now, tbuffer, sizeof(tbuffer)));
448 #endif /* AFS_QUIETFS_ENV */
449                 ViceLog(2,
450                         ("File server is running at %s\n",
451                          afs_ctime(&now, tbuffer, sizeof(tbuffer))));
452             }
453         }
454     }
455 }                               /*FiveMinuteCheckLWP */
456
457
458 /* This LWP does host checks every 5 minutes:  it should not be used for
459  * other 5 minute activities because it may be delayed by timeouts when
460  * it probes the workstations
461  */
462 static void
463 HostCheckLWP()
464 {
465     ViceLog(1, ("Starting Host check process\n"));
466     setThreadId("HostCheckLWP");
467     while (1) {
468 #ifdef AFS_PTHREAD_ENV
469         sleep(fiveminutes);
470 #else /* AFS_PTHREAD_ENV */
471         IOMGR_Sleep(fiveminutes);
472 #endif /* AFS_PTHREAD_ENV */
473         ViceLog(2, ("Checking for dead venii & clients\n"));
474         h_CheckHosts();
475     }
476 }                               /*HostCheckLWP */
477
478 /* This LWP does fsync checks every 5 minutes:  it should not be used for
479  * other 5 minute activities because it may be delayed by timeouts when
480  * it probes the workstations
481  */
482 static
483 FsyncCheckLWP()
484 {
485     afs_int32 code;
486 #ifdef AFS_PTHREAD_ENV
487     struct timespec fsync_next;
488 #endif
489     ViceLog(1, ("Starting fsync check process\n"));
490
491     setThreadId("FsyncCheckLWP");
492
493 #ifdef AFS_PTHREAD_ENV
494     assert(pthread_cond_init(&fsync_cond, NULL) == 0);
495     assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0);
496 #endif
497
498     while (1) {
499         FSYNC_LOCK;
500 #ifdef AFS_PTHREAD_ENV
501         /* rounding is fine */
502         fsync_next.tv_nsec = 0;
503         fsync_next.tv_sec = time(0) + fiveminutes;
504
505         code =
506             pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex,
507                                    &fsync_next);
508         if (code != 0 && code != ETIMEDOUT)
509             ViceLog(0, ("pthread_cond_timedwait returned %d\n", code));
510 #else /* AFS_PTHREAD_ENV */
511         if ((code = LWP_WaitProcess(fsync_wait)) != LWP_SUCCESS)
512             ViceLog(0, ("LWP_WaitProcess returned %d\n", code));
513 #endif /* AFS_PTHREAD_ENV */
514         FSYNC_UNLOCK;
515         ViceLog(2, ("Checking for fsync events\n"));
516         do {
517             code = BreakLaterCallBacks();
518         } while (code != 0);
519     }
520 }
521
522 /*------------------------------------------------------------------------
523  * PRIVATE ClearXStatValues
524  *
525  * Description:
526  *      Initialize all of the values collected via the xstat
527  *      interface.
528  *
529  * Arguments:
530  *      None.
531  *
532  * Returns:
533  *      Nothing.
534  *
535  * Environment:
536  *      Must be called during File Server initialization.
537  *
538  * Side Effects:
539  *      As advertised.
540  *------------------------------------------------------------------------*/
541
542 static void
543 ClearXStatValues()
544 {                               /*ClearXStatValues */
545
546     struct fs_stats_opTimingData *opTimeP;      /*Ptr to timing struct */
547     struct fs_stats_xferData *opXferP;  /*Ptr to xfer struct */
548     int i;                      /*Loop counter */
549
550     /*
551      * Zero all xstat-related structures.
552      */
553     memset((char *)(&afs_perfstats), 0, sizeof(struct afs_PerfStats));
554 #if FS_STATS_DETAILED
555     memset((char *)(&afs_FullPerfStats), 0,
556            sizeof(struct fs_stats_FullPerfStats));
557
558     /*
559      * That's not enough.  We have to set reasonable minima for
560      * time and xfer values in the detailed stats.
561      */
562     opTimeP = &(afs_FullPerfStats.det.rpcOpTimes[0]);
563     for (i = 0; i < FS_STATS_NUM_RPC_OPS; i++, opTimeP++)
564         opTimeP->minTime.tv_sec = 999999;
565
566     opXferP = &(afs_FullPerfStats.det.xferOpTimes[0]);
567     for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++, opXferP++) {
568         opXferP->minTime.tv_sec = 999999;
569         opXferP->minBytes = 999999999;
570     }
571
572     /*
573      * There's more.  We have to set our unique system identifier, as
574      * declared in param.h.  If such a thing is not defined, we bitch
575      * and declare ourselves to be an unknown system type.
576      */
577 #ifdef SYS_NAME_ID
578     afs_perfstats.sysname_ID = SYS_NAME_ID;
579 #else
580 #ifndef AFS_NT40_ENV
581     ViceLog(0, ("Sys name ID constant not defined in param.h!!\n"));
582     ViceLog(0, ("[Choosing ``undefined'' sys name ID.\n"));
583 #endif
584     afs_perfstats.sysname_ID = SYS_NAME_ID_UNDEFINED;
585 #endif /* SYS_NAME_ID */
586 #endif
587
588 }                               /*ClearXStatValues */
589
590
591 static void
592 PrintCounters()
593 {
594     int dirbuff, dircall, dirio;
595     struct timeval tpl;
596     int workstations, activeworkstations, delworkstations;
597     int processSize = 0;
598     char tbuffer[32];
599
600     TM_GetTimeOfDay(&tpl, 0);
601     Statistics = 1;
602     ViceLog(0,
603             ("Vice was last started at %s\n",
604              afs_ctime(&StartTime, tbuffer, sizeof(tbuffer))));
605
606     VPrintCacheStats();
607     VPrintDiskStats();
608     DStat(&dirbuff, &dircall, &dirio);
609     ViceLog(0,
610             ("With %d directory buffers; %d reads resulted in %d read I/Os\n",
611              dirbuff, dircall, dirio));
612     rx_PrintStats(stderr);
613     h_PrintStats();
614     PrintCallBackStats();
615 #ifdef AFS_NT40_ENV
616     processSize = -1;           /* TODO: */
617 #else
618     processSize = (int)((long)sbrk(0) >> 10);
619 #endif
620     ViceLog(0,
621             ("There are %d connections, process size %d\n",
622              CurrentConnections, processSize));
623     h_GetWorkStats(&workstations, &activeworkstations, &delworkstations,
624                    tpl.tv_sec - 15 * 60);
625     ViceLog(0,
626             ("There are %d workstations, %d are active (req in < 15 mins), %d marked \"down\"\n",
627              workstations, activeworkstations, delworkstations));
628     Statistics = 0;
629
630 }                               /*PrintCounters */
631
632
633
634 static void
635 CheckSignal()
636 {
637     if (FS_registered > 0) {
638         /*
639          * We have proper ip addresses; tell the vlserver what we got; the following
640          * routine will do the proper reporting for us
641          */
642         Do_VLRegisterRPC();
643     }
644     h_DumpHosts();
645     h_PrintClients();
646     DumpCallBackState();
647     PrintCounters();
648     ResetCheckSignal();
649
650 }                               /*CheckSignal */
651
652 void
653 ShutDownAndCore(int dopanic)
654 {
655     time_t now = time(0);
656     char tbuffer[32];
657
658     ViceLog(0,
659             ("Shutting down file server at %s",
660              afs_ctime(&now, tbuffer, sizeof(tbuffer))));
661     if (dopanic)
662         ViceLog(0, ("ABNORMAL SHUTDOWN, see core file.\n"));
663 #ifndef AFS_QUIETFS_ENV
664     if (console != NULL) {
665         fprintf(console, "File server restart/shutdown received at %s\r",
666                 afs_ctime(&now, tbuffer, sizeof(tbuffer)));
667     }
668 #endif
669     DFlush();
670     if (!dopanic)
671         PrintCounters();
672
673     /* do not allows new reqests to be served from now on, all new requests
674      * are returned with an error code of RX_RESTARTING ( transient failure ) */
675     rx_SetRxTranquil();         /* dhruba */
676     VShutdown();
677
678     if (debugFile) {
679         rx_PrintStats(debugFile);
680         fflush(debugFile);
681     }
682     if (console != NULL) {
683         now = time(0);
684         if (dopanic) {
685 #ifndef AFS_QUIETFS_ENV
686             fprintf(console, "File server has terminated abnormally at %s\r",
687                     afs_ctime(&now, tbuffer, sizeof(tbuffer)));
688 #endif
689             ViceLog(0,
690                     ("File server has terminated abnormally at %s\n",
691                      afs_ctime(&now, tbuffer, sizeof(tbuffer))));
692         } else {
693 #ifndef AFS_QUIETFS_ENV
694             fprintf(console, "File server has terminated normally at %s\r",
695                     afs_ctime(&now, tbuffer, sizeof(tbuffer)));
696 #endif
697             ViceLog(0,
698                     ("File server has terminated normally at %s\n",
699                      afs_ctime(&now, tbuffer, sizeof(tbuffer))));
700         }
701     }
702
703     exit(0);
704
705 }                               /*ShutDown */
706
707 void
708 ShutDown(void)
709 {                               /* backward compatibility */
710     ShutDownAndCore(DONTPANIC);
711 }
712
713
714 static void
715 FlagMsg()
716 {
717     char buffer[1024];
718
719     /* default supports help flag */
720
721     strcpy(buffer, "Usage: fileserver ");
722     strcat(buffer, "[-d <debug level>] ");
723     strcat(buffer, "[-p <number of processes>] ");
724     strcat(buffer, "[-spare <number of spare blocks>] ");
725     strcat(buffer, "[-pctspare <percentage spare>] ");
726     strcat(buffer, "[-b <buffers>] ");
727     strcat(buffer, "[-l <large vnodes>] ");
728     strcat(buffer, "[-s <small vnodes>] ");
729     strcat(buffer, "[-vc <volume cachesize>] ");
730     strcat(buffer, "[-w <call back wait interval>] ");
731     strcat(buffer, "[-cb <number of call backs>] ");
732     strcat(buffer, "[-banner (print banner every 10 minutes)] ");
733     strcat(buffer, "[-novbc (whole volume cbs disabled)] ");
734     strcat(buffer, "[-implicit <admin mode bits: rlidwka>] ");
735     strcat(buffer, "[-readonly (read-only file server)] ");
736     strcat(buffer,
737            "[-hr <number of hours between refreshing the host cps>] ");
738     strcat(buffer, "[-busyat <redirect clients when queue > n>] ");
739     strcat(buffer, "[-nobusy <no VBUSY before a volume is attached>] ");
740     strcat(buffer, "[-rxpck <number of rx extra packets>] ");
741     strcat(buffer, "[-rxdbg (enable rx debugging)] ");
742     strcat(buffer, "[-rxdbge (enable rxevent debugging)] ");
743 #ifdef  AFS_AIX32_ENV
744     strcat(buffer, "[-m <min percentage spare in partition>] ");
745 #endif
746 #if defined(AFS_SGI_ENV)
747     strcat(buffer, "[-lock (keep fileserver from swapping)] ");
748 #endif
749     strcat(buffer, "[-L (large server conf)] ");
750     strcat(buffer, "[-S (small server conf)] ");
751     strcat(buffer, "[-k <stack size>] ");
752     strcat(buffer, "[-realm <Kerberos realm name>] ");
753     strcat(buffer, "[-udpsize <size of socket buffer in bytes>] ");
754     strcat(buffer, "[-sendsize <size of send buffer in bytes>] ");
755 /*   strcat(buffer, "[-enable_peer_stats] "); */
756 /*   strcat(buffer, "[-enable_process_stats] "); */
757     strcat(buffer, "[-help]\n");
758 /*
759     ViceLog(0, ("%s", buffer));
760 */
761
762     printf("%s", buffer);
763     fflush(stdout);
764
765 }                               /*FlagMsg */
766
767
768 static afs_int32
769 ParseRights(char *arights)
770 {
771     afs_int32 mode = 0;
772     int i, len;
773     char tc;
774
775     if (!arights || !strcmp(arights, "")) {
776         printf("Missing list of mode bits on -implicit option\n");
777         return -1;
778     }
779     if (!strcmp(arights, "none"))
780         mode = 0;
781     else if (!strcmp(arights, "read"))
782         mode = PRSFS_READ | PRSFS_LOOKUP;
783     else if (!strcmp(arights, "write"))
784         mode =
785             PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
786             PRSFS_WRITE | PRSFS_LOCK;
787     else if (!strcmp(arights, "all"))
788         mode =
789             PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
790             PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
791     else {
792         len = strlen(arights);
793         for (i = 0; i < len; i++) {
794             tc = *arights++;
795             if (tc == 'r')
796                 mode |= PRSFS_READ;
797             else if (tc == 'l')
798                 mode |= PRSFS_LOOKUP;
799             else if (tc == 'i')
800                 mode |= PRSFS_INSERT;
801             else if (tc == 'd')
802                 mode |= PRSFS_DELETE;
803             else if (tc == 'w')
804                 mode |= PRSFS_WRITE;
805             else if (tc == 'k')
806                 mode |= PRSFS_LOCK;
807             else if (tc == 'a')
808                 mode |= PRSFS_ADMINISTER;
809             else if (tc == 'A')
810                 mode |= PRSFS_USR0;
811             else if (tc == 'B')
812                 mode |= PRSFS_USR1;
813             else if (tc == 'C')
814                 mode |= PRSFS_USR2;
815             else if (tc == 'D')
816                 mode |= PRSFS_USR3;
817             else if (tc == 'E')
818                 mode |= PRSFS_USR4;
819             else if (tc == 'F')
820                 mode |= PRSFS_USR5;
821             else if (tc == 'G')
822                 mode |= PRSFS_USR6;
823             else if (tc == 'H')
824                 mode |= PRSFS_USR7;
825             else {
826                 printf("Illegal -implicit rights character '%c'.\n", tc);
827                 return -1;
828             }
829         }
830     }
831     return mode;
832 }
833
834 /*
835  * Limit MAX_FILESERVER_THREAD by the system limit on the number of
836  * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
837  * available.
838  *
839  * AIX:         sysconf() limit is real
840  * HP-UX:       sysconf() limit is real
841  * IRIX:        sysconf() limit is apparently NOT real -- too small
842  * DUX:         sysconf() limit is apparently NOT real -- too big
843  * Linux:       sysconf() limit is apparently NOT real -- too big
844  * Solaris:     no sysconf() limit
845  */
846 static int
847 max_fileserver_thread(void)
848 {
849 #if defined(AFS_PTHREAD_ENV)
850 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
851     long ans;
852
853     ans = sysconf(_SC_THREAD_THREADS_MAX);
854     if (0 < ans && ans < MAX_FILESERVER_THREAD)
855         return (int)ans;
856 #endif
857 #endif /* defined(AFS_PTHREAD_ENV) */
858     return MAX_FILESERVER_THREAD;
859 }
860
861 static int
862 ParseArgs(int argc, char *argv[])
863 {
864     int SawL = 0, SawS = 0, SawVC = 0;
865     int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
866         0, Sawbufs = 0;
867     int Sawbusy = 0;
868     int i;
869     int bufSize = 0;            /* temp variable to read in udp socket buf size */
870
871     for (i = 1; i < argc; i++) {
872         if (!strcmp(argv[i], "-d")) {
873             if ((i + 1) >= argc) {
874                 fprintf(stderr, "missing argument for -d\n"); 
875                 return -1; 
876             }
877             debuglevel = atoi(argv[++i]);
878             LogLevel = debuglevel;
879         } else if (!strcmp(argv[i], "-banner")) {
880             printBanner = 1;
881         } else if (!strcmp(argv[i], "-implicit")) {
882             if ((i + 1) >= argc) {
883                 fprintf(stderr, "missing argument for -implicit\n"); 
884                 return -1; 
885             }
886             implicitAdminRights = ParseRights(argv[++i]);
887             if (implicitAdminRights < 0)
888                 return implicitAdminRights;
889         } else if (!strcmp(argv[i], "-readonly")) {
890             readonlyServer = 1;
891         } else if (!strcmp(argv[i], "-L")) {
892             SawL = 1;
893         } else if (!strcmp(argv[i], "-S")) {
894             SawS = 1;
895         } else if (!strcmp(argv[i], "-p")) {
896             int lwps_max =
897                 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
898             Sawlwps = 1;
899             if ((i + 1) >= argc) {
900                 fprintf(stderr, "missing argument for -p\n"); 
901                 return -1; 
902             }
903             lwps = atoi(argv[++i]);
904             if (lwps > lwps_max)
905                 lwps = lwps_max;
906             else if (lwps < 6)
907                 lwps = 6;
908         } else if (!strcmp(argv[i], "-b")) {
909             Sawbufs = 1;
910             if ((i + 1) >= argc) {
911                 fprintf(stderr, "missing argument for -b\n"); 
912                 return -1; 
913             }
914             buffs = atoi(argv[++i]);
915         } else if (!strcmp(argv[i], "-l")) {
916             Sawlarge = 1;
917             if ((i + 1) >= argc) {
918                 fprintf(stderr, "missing argument for -l\n"); 
919                 return -1; 
920             }
921             large = atoi(argv[++i]);
922         } else if (!strcmp(argv[i], "-vc")) {
923             SawVC = 1;
924             if ((i + 1) >= argc) {
925                 fprintf(stderr, "missing argument for -vc\n"); 
926                 return -1; 
927             }
928             volcache = atoi(argv[++i]);
929         } else if (!strcmp(argv[i], "-novbc")) {
930             novbc = 1;
931         } else if (!strcmp(argv[i], "-rxpck")) {
932             Sawrxpck = 1;
933             if ((i + 1) >= argc) {
934                 fprintf(stderr, "missing argument for -rxpck\n"); 
935                 return -1; 
936             }
937             rxpackets = atoi(argv[++i]);
938         } else if (!strcmp(argv[i], "-s")) {
939             Sawsmall = 1;
940             if ((i + 1) >= argc) {
941                 fprintf(stderr, "missing argument for -s\n"); 
942                 return -1; 
943             }
944             nSmallVns = atoi(argv[++i]);
945         } else if (!strcmp(argv[i], "-abortthreshold")) {
946             if ((i + 1) >= argc) {
947                 fprintf(stderr, "missing argument for -abortthreshold\n"); 
948                 return -1; 
949             }
950             abort_threshold = atoi(argv[++i]);
951         } else if (!strcmp(argv[i], "-k")) {
952             if ((i + 1) >= argc) {
953                 fprintf(stderr, "missing argument for -k\n"); 
954                 return -1; 
955             }
956             stack = atoi(argv[++i]);
957         }
958 #if defined(AFS_SGI_ENV)
959         else if (!strcmp(argv[i], "-lock")) {
960             SawLock = 1;
961         }
962 #endif
963         else if (!strcmp(argv[i], "-spare")) {
964             if ((i + 1) >= argc) {
965                 fprintf(stderr, "missing argument for -spare\n"); 
966                 return -1; 
967             }
968             BlocksSpare = atoi(argv[++i]);
969             SawSpare = 1;
970         } else if (!strcmp(argv[i], "-pctspare")) {
971             if ((i + 1) >= argc) {
972                 fprintf(stderr, "missing argument for -pctspare\n"); 
973                 return -1; 
974             }
975             PctSpare = atoi(argv[++i]);
976             BlocksSpare = 0;    /* has non-zero default */
977             SawPctSpare = 1;
978         } else if (!strcmp(argv[i], "-w")) {
979             if ((i + 1) >= argc) {
980                 fprintf(stderr, "missing argument for -w\n"); 
981                 return -1; 
982             }
983             fiveminutes = atoi(argv[++i]);
984         } else if (!strcmp(argv[i], "-hr")) {
985             int hr;
986             if ((i + 1) >= argc) {
987                 fprintf(stderr, "missing argument for -hr\n"); 
988                 return -1; 
989             }
990             hr = atoi(argv[++i]);
991             if ((hr < 1) || (hr > 36)) {
992                 printf
993                     ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
994                      hr);
995                 return -1;
996             }
997             hostaclRefresh = hr * 60 * 60;
998         } else if (!strcmp(argv[i], "-rxdbg"))
999             rxlog = 1;
1000         else if (!strcmp(argv[i], "-rxdbge"))
1001             eventlog = 1;
1002         else if (!strcmp(argv[i], "-cb")) {
1003             Sawcbs = 1;
1004             if ((i + 1) >= argc) {
1005                 fprintf(stderr, "missing argument for -cb\n"); 
1006                 return -1; 
1007             }
1008             numberofcbs = atoi(argv[++i]);
1009             if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1010                 printf
1011                     ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1012                      numberofcbs);
1013                 return -1;
1014             }
1015         } else if (!strcmp(argv[i], "-busyat")) {
1016             Sawbusy = 1;
1017             if ((i + 1) >= argc) {
1018                 fprintf(stderr, "missing argument for -busyat\n"); 
1019                 return -1; 
1020             }
1021             busy_threshold = atoi(argv[++i]);
1022             if (busy_threshold < 10) {
1023                 printf
1024                     ("Busy threshold %d is too low, will compute default.\n",
1025                      busy_threshold);
1026                 Sawbusy = 0;
1027             }
1028         } else if (!strcmp(argv[i], "-nobusy"))
1029             busyonrst = 0;
1030 #ifdef  AFS_AIX32_ENV
1031         else if (!strcmp(argv[i], "-m")) {
1032             extern int aixlow_water;
1033             if ((i + 1) >= argc) {
1034                 fprintf(stderr, "missing argument for -m\n"); 
1035                 return -1; 
1036             }
1037             aixlow_water = atoi(argv[++i]);
1038             if ((aixlow_water < 0) || (aixlow_water > 30)) {
1039                 printf("space reserved %d% invalid; must be between 0-30%\n",
1040                        aixlow_water);
1041                 return -1;
1042             }
1043         }
1044 #endif
1045         else if (!strcmp(argv[i], "-nojumbo")) {
1046             rxJumbograms = 0;
1047         } else if (!strcmp(argv[i], "-realm")) {
1048             extern char local_realm[AFS_REALM_SZ];
1049             if ((i + 1) >= argc) {
1050                 fprintf(stderr, "missing argument for -realm\n"); 
1051                 return -1; 
1052             }
1053             if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1054                 printf
1055                     ("-realm argument must contain fewer than %d characters.\n",
1056                      AFS_REALM_SZ);
1057                 return -1;
1058             }
1059             strncpy(local_realm, argv[i], AFS_REALM_SZ);
1060         } else if (!strcmp(argv[i], "-udpsize")) {
1061             if ((i + 1) >= argc) {
1062                 printf("You have to specify -udpsize <integer value>\n");
1063                 return -1;
1064             }
1065             bufSize = atoi(argv[++i]);
1066             if (bufSize < rx_GetMinUdpBufSize())
1067                 printf
1068                     ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1069                      bufSize, rx_GetMinUdpBufSize());
1070             else
1071                 udpBufSize = bufSize;
1072         } else if (!strcmp(argv[i], "-sendsize")) {
1073             if ((i + 1) >= argc) {
1074                 printf("You have to specify -sendsize <integer value>\n");
1075                 return -1;
1076             }
1077             bufSize = atoi(argv[++i]);
1078             if (bufSize < 16384)
1079                 printf
1080                     ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1081                      bufSize, 16384);
1082             else
1083                 sendBufSize = bufSize;
1084         } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1085             rx_enablePeerRPCStats();
1086         } else if (!strcmp(argv[i], "-enable_process_stats")) {
1087             rx_enableProcessRPCStats();
1088         }
1089 #ifndef AFS_NT40_ENV
1090         else if (strcmp(argv[i], "-syslog") == 0) {
1091             /* set syslog logging flag */
1092             serverLogSyslog = 1;
1093         } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1094             serverLogSyslog = 1;
1095             serverLogSyslogFacility = atoi(argv[i] + 8);
1096         }
1097 #endif
1098         else {
1099             return (-1);
1100         }
1101     }
1102     if (SawS && SawL) {
1103         printf("Only one of -L, or -S must be specified\n");
1104         return -1;
1105     }
1106     if (SawS) {
1107         if (!Sawrxpck)
1108             rxpackets = 100;
1109         if (!Sawsmall)
1110             nSmallVns = 200;
1111         if (!Sawlarge)
1112             large = 200;
1113         if (!Sawcbs)
1114             numberofcbs = 20000;
1115         if (!Sawlwps)
1116             lwps = 6;
1117         if (!Sawbufs)
1118             buffs = 70;
1119         if (!SawVC)
1120             volcache = 200;
1121     }
1122     if (SawL) {
1123         if (!Sawrxpck)
1124             rxpackets = 200;
1125         if (!Sawsmall)
1126             nSmallVns = 600;
1127         if (!Sawlarge)
1128             large = 600;
1129         if (!Sawcbs)
1130             numberofcbs = 64000;
1131         if (!Sawlwps)
1132             lwps = 12;
1133         if (!Sawbufs)
1134             buffs = 120;
1135         if (!SawVC)
1136             volcache = 600;
1137     }
1138     if (!Sawbusy)
1139         busy_threshold = 3 * rxpackets / 2;
1140
1141     return (0);
1142
1143 }                               /*ParseArgs */
1144
1145
1146 #define MAXPARMS 15
1147
1148 static void
1149 NewParms(int initializing)
1150 {
1151     static struct afs_stat sbuf;
1152     register int i, fd;
1153     char *parms;
1154     char *argv[MAXPARMS];
1155     register int argc;
1156
1157     if (!(afs_stat("/vice/file/parms", &sbuf))) {
1158         parms = (char *)malloc(sbuf.st_size);
1159         if (!parms)
1160             return;
1161         fd = afs_open("parms", O_RDONLY, 0666);
1162         if (fd <= 0) {
1163             ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1164             return;
1165         }
1166
1167         i = read(fd, parms, sbuf.st_size);
1168         close(fd);
1169         if (i != sbuf.st_size) {
1170             if (i < 0) {
1171                 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1172             } else {
1173                 ViceLog(0,
1174                         ("Read on parms failed; expected %d bytes but read %d\n",
1175                          sbuf.st_size, i));
1176             }
1177             free(parms);
1178             return;
1179         }
1180
1181         for (i = 0; i < MAXPARMS; argv[i++] = 0);
1182
1183         for (argc = i = 0; i < sbuf.st_size; i++) {
1184             if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1185                 if (argv[argc] == 0)
1186                     argv[argc] = (parms + i);
1187             } else {
1188                 *(parms + i) = '\0';
1189                 if (argv[argc] != 0) {
1190                     if (++argc == MAXPARMS)
1191                         break;
1192                 }
1193                 while ((*(parms + i + 1) == ' ')
1194                        || (*(parms + i + 1) == '\n'))
1195                     i++;
1196             }
1197         }
1198         if (ParseArgs(argc, argv) == 0) {
1199             ViceLog(0, ("Change parameters to:"));
1200         } else {
1201             ViceLog(0, ("Invalid parameter in:"));
1202         }
1203         for (i = 0; i < argc; i++) {
1204             ViceLog(0, (" %s", argv[i]));
1205         }
1206         ViceLog(0, ("\n"));
1207         free(parms);
1208     } else if (!initializing)
1209         ViceLog(0,
1210                 ("Received request to change parms but no parms file exists\n"));
1211
1212 }                               /*NewParms */
1213
1214
1215 /* Miscellaneous routines */
1216 void
1217 Die(char *msg)
1218 {
1219     ViceLog(0, ("%s\n", msg));
1220     assert(0);
1221
1222 }                               /*Die */
1223
1224
1225 afs_int32
1226 InitPR()
1227 {
1228     register code;
1229
1230     /*
1231      * If this fails, it's because something major is wrong, and is not
1232      * likely to be time dependent.
1233      */
1234     code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1235     if (code != 0) {
1236         ViceLog(0,
1237                 ("Couldn't initialize protection library; code=%d.\n", code));
1238         return code;
1239     }
1240     SystemId = SYSADMINID;
1241     SystemAnyUser = ANYUSERID;
1242     SystemAnyUserCPS.prlist_len = 0;
1243     SystemAnyUserCPS.prlist_val = NULL;
1244     AnonCPS.prlist_len = 0;
1245     AnonCPS.prlist_val = NULL;
1246     while (1) {
1247         code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1248         if (code != 0) {
1249             ViceLog(0,
1250                     ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1251                      code));
1252             goto sleep;
1253         }
1254         code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1255         if (code != 0) {
1256             ViceLog(0,
1257                     ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1258                      code));
1259             return -1;
1260         }
1261         AnonymousID = ANONYMOUSID;
1262         return 0;
1263       sleep:
1264 #ifdef AFS_PTHREAD_ENV
1265         sleep(30);
1266 #else /* AFS_PTHREAD_ENV */
1267         IOMGR_Sleep(30);
1268 #endif /* AFS_PTHREAD_ENV */
1269     }
1270 }                               /*InitPR */
1271
1272 struct rx_connection *serverconns[MAXSERVERS];
1273 struct ubik_client *cstruct;
1274
1275 afs_int32
1276 vl_Initialize(char *confDir)
1277 {
1278     afs_int32 code, scIndex = 0, i;
1279     struct afsconf_dir *tdir;
1280     struct rx_securityClass *sc;
1281     struct afsconf_cell info;
1282
1283     tdir = afsconf_Open(confDir);
1284     if (!tdir) {
1285         ViceLog(0,
1286                 ("Could not open configuration directory (%s).\n", confDir));
1287         exit(1);
1288     }
1289     code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1290     if (code) {
1291         ViceLog(0, ("Could not get security object for localAuth\n"));
1292         exit(1);
1293     }
1294     code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1295     if (info.numServers > MAXSERVERS) {
1296         ViceLog(0,
1297                 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1298                  info.numServers, MAXSERVERS));
1299         exit(1);
1300     }
1301     for (i = 0; i < info.numServers; i++)
1302         serverconns[i] =
1303             rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1304                              info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1305                              scIndex);
1306     code = ubik_ClientInit(serverconns, &cstruct);
1307     if (code) {
1308         ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1309         return code;
1310     }
1311     return 0;
1312 }
1313
1314 #define SYSIDMAGIC      0x88aabbcc
1315 #define SYSIDVERSION    1
1316
1317 afs_int32
1318 ReadSysIdFile()
1319 {
1320     afs_int32 fd, nentries, i;
1321     struct versionStamp vsn;
1322     struct afs_stat status;
1323     afsUUID uuid;
1324
1325     if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1326         || (status.st_size <= 0)) {
1327         ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1328         return ENOENT;
1329     }
1330     if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1331         ViceLog(0,
1332                 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1333                  errno));
1334         return EIO;
1335     }
1336     if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1337         ViceLog(0,
1338                 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1339                  errno));
1340         return EIO;
1341     }
1342     if (vsn.magic != SYSIDMAGIC) {
1343         ViceLog(0,
1344                 ("%s: wrong magic %x (we support %x)\n",
1345                  AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1346         return EIO;
1347     }
1348     if (vsn.version != SYSIDVERSION) {
1349         ViceLog(0,
1350                 ("%s: wrong version %d (we support %d)\n",
1351                  AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1352         return EIO;
1353     }
1354     if ((i =
1355          read(fd, (char *)&uuid,
1356               sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1357         ViceLog(0,
1358                 ("%s: read of uuid failed (%d)\n",
1359                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1360         return EIO;
1361     }
1362     afs_ntohuuid(&uuid);
1363     FS_HostUUID = uuid;
1364     if ((i =
1365          read(fd, (char *)&nentries,
1366               sizeof(afs_int32))) != sizeof(afs_int32)) {
1367         ViceLog(0,
1368                 ("%s: Read of entries failed (%d)\n",
1369                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1370         return EIO;
1371     }
1372     if (nentries <= 0 || nentries > ADDRSPERSITE) {
1373         ViceLog(0,
1374                 ("%s: invalid num of interfaces: %d\n",
1375                  AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1376         return EIO;
1377     }
1378     FS_HostAddr_cnt = nentries;
1379     for (i = 0; i < nentries; i++) {
1380         if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1381             sizeof(afs_int32)) {
1382             ViceLog(0,
1383                     ("%s: Read of addresses failed (%d)\n",
1384                      AFSDIR_SERVER_SYSID_FILEPATH, errno));
1385             FS_HostAddr_cnt = 0;        /* reset it */
1386             return EIO;
1387         }
1388     }
1389     close(fd);
1390     return 0;
1391 }
1392
1393 afs_int32
1394 WriteSysIdFile()
1395 {
1396     afs_int32 fd, i;
1397     struct versionStamp vsn;
1398     struct afs_stat status;
1399     afsUUID uuid;
1400
1401     if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1402         /*
1403          * File exists; keep the old one around
1404          */
1405         renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1406                    AFSDIR_SERVER_OLDSYSID_FILEPATH);
1407     }
1408     fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1409                   0666);
1410     if (fd < 1) {
1411         ViceLog(0,
1412                 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1413                  errno));
1414         return EIO;
1415     }
1416     vsn.magic = SYSIDMAGIC;
1417     vsn.version = 1;
1418     if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1419         ViceLog(0,
1420                 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1421                  errno));
1422         return EIO;
1423     }
1424     uuid = FS_HostUUID;
1425     afs_htonuuid(&uuid);
1426     if ((i =
1427          write(fd, (char *)&uuid,
1428                sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1429         ViceLog(0,
1430                 ("%s: write of uuid failed (%d)\n",
1431                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1432         return EIO;
1433     }
1434     if ((i =
1435          write(fd, (char *)&FS_HostAddr_cnt,
1436                sizeof(afs_int32))) != sizeof(afs_int32)) {
1437         ViceLog(0,
1438                 ("%s: write of # of entries failed (%d)\n",
1439                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1440         return EIO;
1441     }
1442     for (i = 0; i < FS_HostAddr_cnt; i++) {
1443         if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1444             sizeof(afs_int32)) {
1445             ViceLog(0,
1446                     ("%s: write of addresses failed (%d)\n",
1447                      AFSDIR_SERVER_SYSID_FILEPATH, errno));
1448             return EIO;
1449         }
1450     }
1451     close(fd);
1452     return 0;
1453 }
1454
1455 /*
1456  * defect 10966 
1457  * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1458  * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1459  * and so we need to convert each of them into HBO which is what the extra 
1460  * array called FS_HostAddrs_HBO is used here.
1461  */
1462 afs_int32
1463 Do_VLRegisterRPC()
1464 {
1465     register int code;
1466     bulkaddrs addrs;
1467     extern int VL_RegisterAddrs();
1468     afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1469     int i = 0;
1470
1471     for (i = 0; i < FS_HostAddr_cnt; i++)
1472         FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1473     addrs.bulkaddrs_len = FS_HostAddr_cnt;
1474     addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1475     code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1476     if (code) {
1477         if (code == VL_MULTIPADDR) {
1478             ViceLog(0,
1479                     ("VL_RegisterAddrs rpc failed; The ethernet address exist on a different server; repair it\n"));
1480             ViceLog(0,
1481                     ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1482             return code;
1483         } else if (code == RXGEN_OPCODE) {
1484             ViceLog(0,
1485                     ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1486             FS_registered = 2;  /* So we don't have to retry in the gc daemon */
1487         } else {
1488             ViceLog(0,
1489                     ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1490                      code, errno));
1491         }
1492     } else {
1493         FS_registered = 2;      /* So we don't have to retry in the gc daemon */
1494         WriteSysIdFile();
1495     }
1496
1497     return 0;
1498 }
1499
1500 afs_int32
1501 InitVL()
1502 {
1503     afs_int32 code;
1504     extern int rxi_numNetAddrs;
1505     extern afs_uint32 rxi_NetAddrs[];
1506
1507     /*
1508      * If this fails, it's because something major is wrong, and is not
1509      * likely to be time dependent.
1510      */
1511     code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1512     if (code != 0) {
1513         ViceLog(0,
1514                 ("Couldn't initialize protection library; code=%d.\n", code));
1515         return code;
1516     }
1517
1518     /* Read or create the sysid file and register the fileserver's
1519      * IP addresses with the vlserver.
1520      */
1521     code = ReadSysIdFile();
1522     if (code) {
1523         /* Need to create the file */
1524         ViceLog(0, ("Creating new SysID file\n"));
1525         if ((code = afs_uuid_create(&FS_HostUUID))) {
1526             ViceLog(0, ("Failed to create new uuid: %d\n", code));
1527             exit(1);
1528         }
1529     }
1530     /* A good sysid file exists; inform the vlserver. If any conflicts,
1531      * we always use the latest interface available as the real truth.
1532      */
1533 #ifndef AFS_NT40_ENV
1534     if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1535         /*
1536          * Find addresses we are supposed to register as per the netrestrict 
1537          * and netinfo files (/usr/afs/local/NetInfo and 
1538          * /usr/afs/local/NetRestict)
1539          */
1540         char reason[1024];
1541         afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1542                                        ADDRSPERSITE, reason,
1543                                        AFSDIR_SERVER_NETINFO_FILEPATH,
1544                                        AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1545         if (code < 0) {
1546             ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1547             exit(1);
1548         }
1549         FS_HostAddr_cnt = (afs_uint32) code;
1550     } else
1551 #endif
1552     {
1553         FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1554     }
1555
1556     FS_registered = 1;
1557     code = Do_VLRegisterRPC();
1558     return code;
1559 }
1560
1561 int
1562 main(int argc, char *argv[])
1563 {
1564     afs_int32 code;
1565     char tbuffer[32];
1566     struct rx_securityClass *sc[4];
1567     struct rx_service *tservice;
1568 #ifdef AFS_PTHREAD_ENV
1569     pthread_t serverPid;
1570     pthread_attr_t tattr;
1571 #else /* AFS_PTHREAD_ENV */
1572     PROCESS parentPid, serverPid;
1573 #endif /* AFS_PTHREAD_ENV */
1574     struct hostent *he;
1575     int minVnodesRequired;      /* min size of vnode cache */
1576 #ifndef AFS_NT40_ENV
1577     struct rlimit rlim;         /* max number of open file descriptors */
1578 #endif
1579     int curLimit;
1580     time_t t;
1581
1582 #ifdef  AFS_AIX32_ENV
1583     struct sigaction nsa;
1584
1585     sigemptyset(&nsa.sa_mask);
1586     nsa.sa_handler = SIG_DFL;
1587     nsa.sa_flags = SA_FULLDUMP;
1588     sigaction(SIGABRT, &nsa, NULL);
1589     sigaction(SIGSEGV, &nsa, NULL);
1590 #endif
1591
1592     /* Initialize dirpaths */
1593     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1594 #ifdef AFS_NT40_ENV
1595         ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1596 #endif
1597         fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1598                 argv[0]);
1599         exit(2);
1600     }
1601 #ifndef AFS_QUIETFS_ENV
1602     console = afs_fopen("/dev/console", "w");
1603 #endif
1604
1605     if (ParseArgs(argc, argv)) {
1606         FlagMsg();
1607         exit(-1);
1608     }
1609 #ifdef AFS_PTHREAD_ENV
1610     assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1611 #endif /* AFS_PTHREAD_ENV */
1612
1613 #ifdef AFS_SGI_VNODE_GLUE
1614     if (afs_init_kernel_config(-1) < 0) {
1615         printf
1616             ("Can't determine NUMA configuration, not starting fileserver.\n");
1617         exit(1);
1618     }
1619 #endif
1620     confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1621     if (!confDir) {
1622         fprintf(stderr, "Unable to open config directory %s\n",
1623                 AFSDIR_SERVER_ETC_DIRPATH);
1624         exit(-1);
1625     }
1626
1627     NewParms(1);
1628
1629     /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1630 #ifndef AFS_NT40_ENV
1631     serverLogSyslogTag = "fileserver";
1632 #endif
1633     OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1634     SetupLogSignals();
1635
1636     if (SawSpare && SawPctSpare) {
1637         ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1638         exit(-1);
1639     }
1640 #ifdef AFS_SGI_XFS_IOPS_ENV
1641     ViceLog(0, ("XFS/EFS File server starting\n"));
1642 #else
1643     ViceLog(0, ("File server starting\n"));
1644 #endif
1645
1646 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1647     /* initialize the pthread soft signal handler thread */
1648     softsig_init();
1649 #endif
1650
1651     /* install signal handlers for controlling the fileserver process */
1652     ResetCheckSignal();         /* set CheckSignal_Signal() sig handler */
1653     ResetCheckDescriptors();    /* set CheckDescriptors_Signal() sig handler */
1654
1655 #if defined(AFS_SGI_ENV)
1656     /* give this guy a non-degrading priority so help busy servers */
1657     schedctl(NDPRI, 0, NDPNORMMAX);
1658     if (SawLock)
1659         plock(PROCLOCK);
1660 #else
1661 #ifndef AFS_NT40_ENV
1662     nice(-5);                   /* TODO: */
1663 #endif
1664 #endif
1665     assert(DInit(buffs) == 0);
1666
1667 #ifdef AFS_NT40_ENV
1668     if (afs_winsockInit() < 0) {
1669         ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1670         ViceLog(0, ("File server failed to intialize winsock.\n"));
1671         exit(1);
1672     }
1673 #endif
1674     CheckAdminName();
1675
1676     /* if we support more than 16 threads, then we better have the ability 
1677      ** to keep open a large number of files simultaneously 
1678      */
1679 #if     defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1680     curLimit = OPEN_MAX;        /* for pre AIX 4.2 systems */
1681 #elif defined(AFS_NT40_ENV)
1682     curLimit = NT_OPEN_MAX;     /* open file descriptor limit on NT */
1683 #else
1684
1685     curLimit = 0;               /* the number of open file descriptors */
1686     code = getrlimit(RLIMIT_NOFILE, &rlim);
1687     if (code == 0) {
1688         curLimit = rlim.rlim_cur;
1689         rlim.rlim_cur = rlim.rlim_max;
1690         code = setrlimit(RLIMIT_NOFILE, &rlim);
1691         if (code == 0)
1692             curLimit = rlim.rlim_max;
1693     }
1694     if (code != 0)
1695         ViceLog(0, ("Failed to increase open file limit, using default\n"));
1696
1697 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1698
1699     curLimit -= 32;             /* leave a slack of 32 file descriptors */
1700     if (lwps > curLimit) {
1701         if (curLimit > 0)
1702             lwps = curLimit;
1703         else if (lwps > 16)
1704             lwps = 16;          /* default to a maximum of 16 threads */
1705         ViceLog(0,
1706                 ("The system supports a max of %d open files and we are starting %d threads\n",
1707                  curLimit, lwps));
1708     }
1709 #ifndef AFS_PTHREAD_ENV
1710     assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1711            LWP_SUCCESS);
1712 #endif /* !AFS_PTHREAD_ENV */
1713
1714     /* Initialize volume support */
1715     if (!novbc) {
1716         V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1717     }
1718
1719 #if defined(AFS_PTHREAD_ENV)
1720     threadNameProgram = threadName;
1721 #endif
1722
1723     /* initialize libacl routines */
1724     acl_Initialize(ACL_VERSION);
1725
1726     /* initialize RX support */
1727 #ifndef AFS_NT40_ENV
1728     rxi_syscallp = viced_syscall;
1729 #endif
1730     rx_extraPackets = rxpackets;
1731     rx_extraQuota = 4;          /* for outgoing prserver calls from R threads */
1732     rx_SetBusyThreshold(busy_threshold, VBUSY);
1733     rx_SetCallAbortThreshold(abort_threshold);
1734     rx_SetConnAbortThreshold(abort_threshold);
1735     stackSize = lwps * 4000;
1736     if (stackSize < 32000)
1737         stackSize = 32000;
1738     else if (stackSize > 44000)
1739         stackSize = 44000;
1740 #if    defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
1741     rx_SetStackSize(1, stackSize);
1742 #endif
1743     if (udpBufSize)
1744         rx_SetUdpBufSize(udpBufSize);   /* set the UDP buffer size for receive */
1745     if (rx_Init((int)htons(7000)) < 0) {
1746         ViceLog(0, ("Cannot initialize RX\n"));
1747         exit(1);
1748     }
1749     if (!rxJumbograms) {
1750         /* Don't send and don't allow 3.4 clients to send jumbograms. */
1751         rx_SetNoJumbo();
1752     }
1753     rx_GetIFInfo();
1754     rx_SetRxDeadTime(30);
1755     sc[0] = rxnull_NewServerSecurityObject();
1756     sc[1] = 0;                  /* rxvab_NewServerSecurityObject(key1, 0) */
1757     sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
1758     sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
1759     tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
1760                              "AFS",
1761                                                         /* security classes */ sc,
1762                                                         /* numb sec classes */
1763                              4, RXAFS_ExecuteRequest);
1764     if (!tservice) {
1765         ViceLog(0,
1766                 ("Failed to initialize RX, probably two servers running.\n"));
1767         exit(-1);
1768     }
1769     rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
1770     rx_SetMinProcs(tservice, 3);
1771     rx_SetMaxProcs(tservice, lwps);
1772     rx_SetCheckReach(tservice, 1);
1773
1774     tservice =
1775         rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
1776                       RXSTATS_ExecuteRequest);
1777     if (!tservice) {
1778         ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1779         exit(-1);
1780     }
1781     rx_SetMinProcs(tservice, 2);
1782     rx_SetMaxProcs(tservice, 4);
1783
1784     /*
1785      * Enable RX hot threads, which allows the listener thread to trade
1786      * places with an idle thread and moves the context switch from listener
1787      * to worker out of the critical path.
1788      */
1789     rx_EnableHotThread();
1790
1791     /* Some rx debugging */
1792     if (rxlog || eventlog) {
1793         debugFile = afs_fopen("rx_dbg", "w");
1794         if (rxlog)
1795             rx_debugFile = debugFile;
1796         if (eventlog)
1797             rxevent_debugFile = debugFile;
1798     }
1799
1800     init_sys_error_to_et();     /* Set up error table translation */
1801     h_InitHostPackage();        /* set up local cellname and realmname */
1802     InitCallBack(numberofcbs);
1803     ClearXStatValues();
1804
1805     code = InitVL();
1806     if (code) {
1807         ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
1808         exit(1);
1809     }
1810
1811     code = InitPR();
1812     if (code) {
1813         ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
1814         exit(1);
1815     }
1816
1817     /* allow super users to manage RX statistics */
1818     rx_SetRxStatUserOk(fs_rxstat_userok);
1819
1820     rx_StartServer(0);          /* now start handling requests */
1821
1822     /* we ensure that there is enough space in the vnode buffer to satisfy
1823      ** requests from all concurrent threads. 
1824      ** the maximum number of vnodes used by a single thread at any one time
1825      ** is three ( "link" uses three vnodes simultaneously, one vLarge and
1826      ** two vSmall for linking files and two vLarge and one vSmall for linking
1827      ** files  ) : dhruba 
1828      */
1829     minVnodesRequired = 2 * lwps + 1;
1830     if (minVnodesRequired > nSmallVns) {
1831         nSmallVns = minVnodesRequired;
1832         ViceLog(0,
1833                 ("Overriding -s command line parameter with %d\n",
1834                  nSmallVns));
1835     }
1836     if (minVnodesRequired > large) {
1837         large = minVnodesRequired;
1838         ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
1839     }
1840
1841     /* We now do this after getting the listener up and running, so that client
1842      * connections don't timeout (maybe) if a file server is restarted, since it
1843      * will be available "real soon now".  Worry about whether we can satisfy the 
1844      * calls in the volume package itself.
1845      */
1846     if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
1847         ViceLog(0,
1848                 ("Shutting down: errors encountered initializing volume package\n"));
1849         VShutdown();
1850         exit(1);
1851     }
1852
1853     /*
1854      * We are done calling fopen/fdopen. It is safe to use a large
1855      * of the file descriptor cache.
1856      */
1857     ih_UseLargeCache();
1858
1859 #ifdef AFS_PTHREAD_ENV
1860     ViceLog(5, ("Starting pthreads\n"));
1861     assert(pthread_attr_init(&tattr) == 0);
1862     assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1863
1864     assert(pthread_create
1865            (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
1866             &fiveminutes) == 0);
1867     assert(pthread_create
1868            (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
1869     assert(pthread_create
1870            (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
1871 #else /* AFS_PTHREAD_ENV */
1872     ViceLog(5, ("Starting LWP\n"));
1873     assert(LWP_CreateProcess
1874            (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1875             (void *)&fiveminutes, "FiveMinuteChecks",
1876             &serverPid) == LWP_SUCCESS);
1877
1878     assert(LWP_CreateProcess
1879            (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1880             (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1881     assert(LWP_CreateProcess
1882            (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1883             (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1884 #endif /* AFS_PTHREAD_ENV */
1885
1886     TM_GetTimeOfDay(&tp, 0);
1887
1888 #ifndef AFS_QUIETFS_ENV
1889     if (console != NULL) { 
1890         time_t t = tp.tv_sec;
1891         fprintf(console, "File server has started at %s\r",
1892                 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
1893     }
1894 #endif
1895
1896     /*
1897      * Figure out the FileServer's name and primary address.
1898      */
1899     ViceLog(0, ("Getting FileServer name...\n"));
1900     code = gethostname(FS_HostName, 64);
1901     if (code) {
1902         ViceLog(0, ("gethostname() failed\n"));
1903     }
1904     ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
1905
1906     ViceLog(0, ("Getting FileServer address...\n"));
1907     he = gethostbyname(FS_HostName);
1908     if (!he) {
1909         ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
1910     } else {
1911         char hoststr[16];
1912         memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
1913         (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
1914         FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
1915         ViceLog(0,
1916                 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
1917                  FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
1918     }
1919
1920     /* Install handler to catch the shutdown signal;
1921      * bosserver assumes SIGQUIT shutdown
1922      */
1923 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1924     softsig_signal(SIGQUIT, ShutDown_Signal);
1925 #else
1926     (void)signal(SIGQUIT, ShutDown_Signal);
1927 #endif
1928
1929     t = tp.tv_sec;
1930     ViceLog(0,
1931             ("File Server started %s",
1932              afs_ctime(&t, tbuffer, sizeof(tbuffer))));
1933 #if FS_STATS_DETAILED
1934     afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
1935 #endif
1936 #ifdef AFS_PTHREAD_ENV
1937     while (1) {
1938         sleep(1000);            /* long time */
1939     }
1940 #else /* AFS_PTHREAD_ENV */
1941     assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
1942 #endif /* AFS_PTHREAD_ENV */
1943 }