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