auditlogs-for-everyone-20050702
[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, "[-enable_peer_stats] "); */
754 /*   strcat(buffer, "[-enable_process_stats] "); */
755     strcat(buffer, "[-help]\n");
756 /*
757     ViceLog(0, ("%s", buffer));
758 */
759
760     printf("%s", buffer);
761     fflush(stdout);
762
763 }                               /*FlagMsg */
764
765
766 static afs_int32
767 ParseRights(char *arights)
768 {
769     afs_int32 mode = 0;
770     int i, len;
771     char tc;
772
773     if (!arights || !strcmp(arights, "")) {
774         printf("Missing list of mode bits on -implicit option\n");
775         return -1;
776     }
777     if (!strcmp(arights, "none"))
778         mode = 0;
779     else if (!strcmp(arights, "read"))
780         mode = PRSFS_READ | PRSFS_LOOKUP;
781     else if (!strcmp(arights, "write"))
782         mode =
783             PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
784             PRSFS_WRITE | PRSFS_LOCK;
785     else if (!strcmp(arights, "all"))
786         mode =
787             PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
788             PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
789     else {
790         len = strlen(arights);
791         for (i = 0; i < len; i++) {
792             tc = *arights++;
793             if (tc == 'r')
794                 mode |= PRSFS_READ;
795             else if (tc == 'l')
796                 mode |= PRSFS_LOOKUP;
797             else if (tc == 'i')
798                 mode |= PRSFS_INSERT;
799             else if (tc == 'd')
800                 mode |= PRSFS_DELETE;
801             else if (tc == 'w')
802                 mode |= PRSFS_WRITE;
803             else if (tc == 'k')
804                 mode |= PRSFS_LOCK;
805             else if (tc == 'a')
806                 mode |= PRSFS_ADMINISTER;
807             else if (tc == 'A')
808                 mode |= PRSFS_USR0;
809             else if (tc == 'B')
810                 mode |= PRSFS_USR1;
811             else if (tc == 'C')
812                 mode |= PRSFS_USR2;
813             else if (tc == 'D')
814                 mode |= PRSFS_USR3;
815             else if (tc == 'E')
816                 mode |= PRSFS_USR4;
817             else if (tc == 'F')
818                 mode |= PRSFS_USR5;
819             else if (tc == 'G')
820                 mode |= PRSFS_USR6;
821             else if (tc == 'H')
822                 mode |= PRSFS_USR7;
823             else {
824                 printf("Illegal -implicit rights character '%c'.\n", tc);
825                 return -1;
826             }
827         }
828     }
829     return mode;
830 }
831
832 /*
833  * Limit MAX_FILESERVER_THREAD by the system limit on the number of
834  * pthreads (sysconf(_SC_THREAD_THREADS_MAX)), if applicable and
835  * available.
836  *
837  * AIX:         sysconf() limit is real
838  * HP-UX:       sysconf() limit is real
839  * IRIX:        sysconf() limit is apparently NOT real -- too small
840  * DUX:         sysconf() limit is apparently NOT real -- too big
841  * Linux:       sysconf() limit is apparently NOT real -- too big
842  * Solaris:     no sysconf() limit
843  */
844 static int
845 max_fileserver_thread(void)
846 {
847 #if defined(AFS_PTHREAD_ENV)
848 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
849     long ans;
850
851     ans = sysconf(_SC_THREAD_THREADS_MAX);
852     if (0 < ans && ans < MAX_FILESERVER_THREAD)
853         return (int)ans;
854 #endif
855 #endif /* defined(AFS_PTHREAD_ENV) */
856     return MAX_FILESERVER_THREAD;
857 }
858
859 static int
860 ParseArgs(int argc, char *argv[])
861 {
862     int SawL = 0, SawS = 0, SawVC = 0;
863     int Sawrxpck = 0, Sawsmall = 0, Sawlarge = 0, Sawcbs = 0, Sawlwps =
864         0, Sawbufs = 0;
865     int Sawbusy = 0;
866     int i;
867     int bufSize = 0;            /* temp variable to read in udp socket buf size */
868
869     for (i = 1; i < argc; i++) {
870         if (!strcmp(argv[i], "-d")) {
871             if ((i + 1) >= argc) {
872                 fprintf(stderr, "missing argument for -d\n"); 
873                 return -1; 
874             }
875             debuglevel = atoi(argv[++i]);
876             LogLevel = debuglevel;
877         } else if (!strcmp(argv[i], "-banner")) {
878             printBanner = 1;
879         } else if (!strcmp(argv[i], "-implicit")) {
880             if ((i + 1) >= argc) {
881                 fprintf(stderr, "missing argument for -implicit\n"); 
882                 return -1; 
883             }
884             implicitAdminRights = ParseRights(argv[++i]);
885             if (implicitAdminRights < 0)
886                 return implicitAdminRights;
887         } else if (!strcmp(argv[i], "-readonly")) {
888             readonlyServer = 1;
889         } else if (!strcmp(argv[i], "-L")) {
890             SawL = 1;
891         } else if (!strcmp(argv[i], "-S")) {
892             SawS = 1;
893         } else if (!strcmp(argv[i], "-p")) {
894             int lwps_max =
895                 max_fileserver_thread() - FILESERVER_HELPER_THREADS;
896             Sawlwps = 1;
897             if ((i + 1) >= argc) {
898                 fprintf(stderr, "missing argument for -p\n"); 
899                 return -1; 
900             }
901             lwps = atoi(argv[++i]);
902             if (lwps > lwps_max)
903                 lwps = lwps_max;
904             else if (lwps < 6)
905                 lwps = 6;
906         } else if (!strcmp(argv[i], "-b")) {
907             Sawbufs = 1;
908             if ((i + 1) >= argc) {
909                 fprintf(stderr, "missing argument for -b\n"); 
910                 return -1; 
911             }
912             buffs = atoi(argv[++i]);
913         } else if (!strcmp(argv[i], "-l")) {
914             Sawlarge = 1;
915             if ((i + 1) >= argc) {
916                 fprintf(stderr, "missing argument for -l\n"); 
917                 return -1; 
918             }
919             large = atoi(argv[++i]);
920         } else if (!strcmp(argv[i], "-vc")) {
921             SawVC = 1;
922             if ((i + 1) >= argc) {
923                 fprintf(stderr, "missing argument for -vc\n"); 
924                 return -1; 
925             }
926             volcache = atoi(argv[++i]);
927         } else if (!strcmp(argv[i], "-novbc")) {
928             novbc = 1;
929         } else if (!strcmp(argv[i], "-rxpck")) {
930             Sawrxpck = 1;
931             if ((i + 1) >= argc) {
932                 fprintf(stderr, "missing argument for -rxpck\n"); 
933                 return -1; 
934             }
935             rxpackets = atoi(argv[++i]);
936 #ifdef AFS_PTHREAD_ENV
937         } else if (!strcmp(argv[i], "-vattachpar")) {
938             if ((i + 1) >= argc) {
939                 fprintf(stderr, "missing argument for -vattachpar\n"); 
940                 return -1; 
941             }
942             vol_attach_threads = atoi(argv[++i]);
943 #endif /* AFS_PTHREAD_ENV */
944         } else if (!strcmp(argv[i], "-s")) {
945             Sawsmall = 1;
946             if ((i + 1) >= argc) {
947                 fprintf(stderr, "missing argument for -s\n"); 
948                 return -1; 
949             }
950             nSmallVns = atoi(argv[++i]);
951         } else if (!strcmp(argv[i], "-abortthreshold")) {
952             if ((i + 1) >= argc) {
953                 fprintf(stderr, "missing argument for -abortthreshold\n"); 
954                 return -1; 
955             }
956             abort_threshold = atoi(argv[++i]);
957         } else if (!strcmp(argv[i], "-k")) {
958             if ((i + 1) >= argc) {
959                 fprintf(stderr, "missing argument for -k\n"); 
960                 return -1; 
961             }
962             stack = atoi(argv[++i]);
963         }
964 #if defined(AFS_SGI_ENV)
965         else if (!strcmp(argv[i], "-lock")) {
966             SawLock = 1;
967         }
968 #endif
969         else if (!strcmp(argv[i], "-spare")) {
970             if ((i + 1) >= argc) {
971                 fprintf(stderr, "missing argument for -spare\n"); 
972                 return -1; 
973             }
974             BlocksSpare = atoi(argv[++i]);
975             SawSpare = 1;
976         } else if (!strcmp(argv[i], "-pctspare")) {
977             if ((i + 1) >= argc) {
978                 fprintf(stderr, "missing argument for -pctspare\n"); 
979                 return -1; 
980             }
981             PctSpare = atoi(argv[++i]);
982             BlocksSpare = 0;    /* has non-zero default */
983             SawPctSpare = 1;
984         } else if (!strcmp(argv[i], "-w")) {
985             if ((i + 1) >= argc) {
986                 fprintf(stderr, "missing argument for -w\n"); 
987                 return -1; 
988             }
989             fiveminutes = atoi(argv[++i]);
990         } else if (!strcmp(argv[i], "-hr")) {
991             int hr;
992             if ((i + 1) >= argc) {
993                 fprintf(stderr, "missing argument for -hr\n"); 
994                 return -1; 
995             }
996             hr = atoi(argv[++i]);
997             if ((hr < 1) || (hr > 36)) {
998                 printf
999                     ("host acl refresh interval of %d hours is invalid; hours must be between 1 and 36\n\n",
1000                      hr);
1001                 return -1;
1002             }
1003             hostaclRefresh = hr * 60 * 60;
1004         } else if (!strcmp(argv[i], "-rxdbg"))
1005             rxlog = 1;
1006         else if (!strcmp(argv[i], "-rxdbge"))
1007             eventlog = 1;
1008         else if (!strcmp(argv[i], "-cb")) {
1009             Sawcbs = 1;
1010             if ((i + 1) >= argc) {
1011                 fprintf(stderr, "missing argument for -cb\n"); 
1012                 return -1; 
1013             }
1014             numberofcbs = atoi(argv[++i]);
1015             if ((numberofcbs < 10000) || (numberofcbs > 2147483647)) {
1016                 printf
1017                     ("number of cbs %d invalid; must be between 10000 and 2147483647\n",
1018                      numberofcbs);
1019                 return -1;
1020             }
1021         } else if (!strcmp(argv[i], "-busyat")) {
1022             Sawbusy = 1;
1023             if ((i + 1) >= argc) {
1024                 fprintf(stderr, "missing argument for -busyat\n"); 
1025                 return -1; 
1026             }
1027             busy_threshold = atoi(argv[++i]);
1028             if (busy_threshold < 10) {
1029                 printf
1030                     ("Busy threshold %d is too low, will compute default.\n",
1031                      busy_threshold);
1032                 Sawbusy = 0;
1033             }
1034         } else if (!strcmp(argv[i], "-nobusy"))
1035             busyonrst = 0;
1036 #ifdef  AFS_AIX32_ENV
1037         else if (!strcmp(argv[i], "-m")) {
1038             extern int aixlow_water;
1039             if ((i + 1) >= argc) {
1040                 fprintf(stderr, "missing argument for -m\n"); 
1041                 return -1; 
1042             }
1043             aixlow_water = atoi(argv[++i]);
1044             if ((aixlow_water < 0) || (aixlow_water > 30)) {
1045                 printf("space reserved %d% invalid; must be between 0-30%\n",
1046                        aixlow_water);
1047                 return -1;
1048             }
1049         }
1050 #endif
1051         else if (!strcmp(argv[i], "-nojumbo")) {
1052             rxJumbograms = 0;
1053         } else if (!strcmp(argv[i], "-realm")) {
1054             extern char local_realm[AFS_REALM_SZ];
1055             if ((i + 1) >= argc) {
1056                 fprintf(stderr, "missing argument for -realm\n"); 
1057                 return -1; 
1058             }
1059             if (strlen(argv[++i]) >= AFS_REALM_SZ) {
1060                 printf
1061                     ("-realm argument must contain fewer than %d characters.\n",
1062                      AFS_REALM_SZ);
1063                 return -1;
1064             }
1065             strncpy(local_realm, argv[i], AFS_REALM_SZ);
1066         } else if (!strcmp(argv[i], "-udpsize")) {
1067             if ((i + 1) >= argc) {
1068                 printf("You have to specify -udpsize <integer value>\n");
1069                 return -1;
1070             }
1071             bufSize = atoi(argv[++i]);
1072             if (bufSize < rx_GetMinUdpBufSize())
1073                 printf
1074                     ("Warning:udpsize %d is less than minimum %d; ignoring\n",
1075                      bufSize, rx_GetMinUdpBufSize());
1076             else
1077                 udpBufSize = bufSize;
1078         } else if (!strcmp(argv[i], "-sendsize")) {
1079             if ((i + 1) >= argc) {
1080                 printf("You have to specify -sendsize <integer value>\n");
1081                 return -1;
1082             }
1083             bufSize = atoi(argv[++i]);
1084             if (bufSize < 16384)
1085                 printf
1086                     ("Warning:sendsize %d is less than minimum %d; ignoring\n",
1087                      bufSize, 16384);
1088             else
1089                 sendBufSize = bufSize;
1090         } else if (!strcmp(argv[i], "-enable_peer_stats")) {
1091             rx_enablePeerRPCStats();
1092         } else if (!strcmp(argv[i], "-enable_process_stats")) {
1093             rx_enableProcessRPCStats();
1094         }
1095         else if (strcmp(argv[i], "-auditlog") == 0) {
1096             int tempfd, flags;
1097             FILE *auditout;
1098             char oldName[MAXPATHLEN];
1099             char *fileName = argv[++i];
1100             
1101 #ifndef AFS_NT40_ENV
1102             struct stat statbuf;
1103             
1104             if ((lstat(fileName, &statbuf) == 0) 
1105                 && (S_ISFIFO(statbuf.st_mode))) {
1106                 flags = O_WRONLY | O_NONBLOCK;
1107             } else 
1108 #endif
1109             {
1110                 strcpy(oldName, fileName);
1111                 strcat(oldName, ".old");
1112                 renamefile(fileName, oldName);
1113                 flags = O_WRONLY | O_TRUNC | O_CREAT;
1114             }
1115             tempfd = open(fileName, flags, 0666);
1116             if (tempfd > -1) {
1117                 auditout = fdopen(tempfd, "a");
1118                 if (auditout) {
1119                     osi_audit_file(auditout);
1120                 } else
1121                     printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1122             } else
1123                 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
1124         }
1125 #ifndef AFS_NT40_ENV
1126         else if (strcmp(argv[i], "-syslog") == 0) {
1127             /* set syslog logging flag */
1128             serverLogSyslog = 1;
1129         } else if (strncmp(argv[i], "-syslog=", 8) == 0) {
1130             serverLogSyslog = 1;
1131             serverLogSyslogFacility = atoi(argv[i] + 8);
1132         }
1133 #endif
1134         else if (strcmp(argv[i], "-mrafslogs") == 0) {
1135             /* set syslog logging flag */
1136             mrafsStyleLogs = 1;
1137         } 
1138         else {
1139             return (-1);
1140         }
1141     }
1142     if (SawS && SawL) {
1143         printf("Only one of -L, or -S must be specified\n");
1144         return -1;
1145     }
1146     if (SawS) {
1147         if (!Sawrxpck)
1148             rxpackets = 100;
1149         if (!Sawsmall)
1150             nSmallVns = 200;
1151         if (!Sawlarge)
1152             large = 200;
1153         if (!Sawcbs)
1154             numberofcbs = 20000;
1155         if (!Sawlwps)
1156             lwps = 6;
1157         if (!Sawbufs)
1158             buffs = 70;
1159         if (!SawVC)
1160             volcache = 200;
1161     }
1162     if (SawL) {
1163         if (!Sawrxpck)
1164             rxpackets = 200;
1165         if (!Sawsmall)
1166             nSmallVns = 600;
1167         if (!Sawlarge)
1168             large = 600;
1169         if (!Sawcbs)
1170             numberofcbs = 64000;
1171         if (!Sawlwps)
1172             lwps = 12;
1173         if (!Sawbufs)
1174             buffs = 120;
1175         if (!SawVC)
1176             volcache = 600;
1177     }
1178     if (!Sawbusy)
1179         busy_threshold = 3 * rxpackets / 2;
1180
1181     return (0);
1182
1183 }                               /*ParseArgs */
1184
1185
1186 #define MAXPARMS 15
1187
1188 static void
1189 NewParms(int initializing)
1190 {
1191     static struct afs_stat sbuf;
1192     register int i, fd;
1193     char *parms;
1194     char *argv[MAXPARMS];
1195     register int argc;
1196
1197     if (!(afs_stat("/vice/file/parms", &sbuf))) {
1198         parms = (char *)malloc(sbuf.st_size);
1199         if (!parms)
1200             return;
1201         fd = afs_open("parms", O_RDONLY, 0666);
1202         if (fd <= 0) {
1203             ViceLog(0, ("Open for parms failed with errno = %d\n", errno));
1204             return;
1205         }
1206
1207         i = read(fd, parms, sbuf.st_size);
1208         close(fd);
1209         if (i != sbuf.st_size) {
1210             if (i < 0) {
1211                 ViceLog(0, ("Read on parms failed with errno = %d\n", errno));
1212             } else {
1213                 ViceLog(0,
1214                         ("Read on parms failed; expected %d bytes but read %d\n",
1215                          sbuf.st_size, i));
1216             }
1217             free(parms);
1218             return;
1219         }
1220
1221         for (i = 0; i < MAXPARMS; argv[i++] = 0);
1222
1223         for (argc = i = 0; i < sbuf.st_size; i++) {
1224             if ((*(parms + i) != ' ') && (*(parms + i) != '\n')) {
1225                 if (argv[argc] == 0)
1226                     argv[argc] = (parms + i);
1227             } else {
1228                 *(parms + i) = '\0';
1229                 if (argv[argc] != 0) {
1230                     if (++argc == MAXPARMS)
1231                         break;
1232                 }
1233                 while ((*(parms + i + 1) == ' ')
1234                        || (*(parms + i + 1) == '\n'))
1235                     i++;
1236             }
1237         }
1238         if (ParseArgs(argc, argv) == 0) {
1239             ViceLog(0, ("Change parameters to:"));
1240         } else {
1241             ViceLog(0, ("Invalid parameter in:"));
1242         }
1243         for (i = 0; i < argc; i++) {
1244             ViceLog(0, (" %s", argv[i]));
1245         }
1246         ViceLog(0, ("\n"));
1247         free(parms);
1248     } else if (!initializing)
1249         ViceLog(0,
1250                 ("Received request to change parms but no parms file exists\n"));
1251
1252 }                               /*NewParms */
1253
1254
1255 /* Miscellaneous routines */
1256 void
1257 Die(char *msg)
1258 {
1259     ViceLog(0, ("%s\n", msg));
1260     assert(0);
1261
1262 }                               /*Die */
1263
1264
1265 afs_int32
1266 InitPR()
1267 {
1268     register code;
1269
1270     /*
1271      * If this fails, it's because something major is wrong, and is not
1272      * likely to be time dependent.
1273      */
1274     code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0);
1275     if (code != 0) {
1276         ViceLog(0,
1277                 ("Couldn't initialize protection library; code=%d.\n", code));
1278         return code;
1279     }
1280     SystemId = SYSADMINID;
1281     SystemAnyUser = ANYUSERID;
1282     SystemAnyUserCPS.prlist_len = 0;
1283     SystemAnyUserCPS.prlist_val = NULL;
1284     AnonCPS.prlist_len = 0;
1285     AnonCPS.prlist_val = NULL;
1286     while (1) {
1287         code = pr_GetCPS(SystemAnyUser, &SystemAnyUserCPS);
1288         if (code != 0) {
1289             ViceLog(0,
1290                     ("Couldn't get CPS for AnyUser, will try again in 30 seconds; code=%d.\n",
1291                      code));
1292             goto sleep;
1293         }
1294         code = pr_GetCPS(ANONYMOUSID, &AnonCPS);
1295         if (code != 0) {
1296             ViceLog(0,
1297                     ("Couldn't get Anonymous CPS, exiting; code=%d.\n",
1298                      code));
1299             return -1;
1300         }
1301         AnonymousID = ANONYMOUSID;
1302         return 0;
1303       sleep:
1304 #ifdef AFS_PTHREAD_ENV
1305         sleep(30);
1306 #else /* AFS_PTHREAD_ENV */
1307         IOMGR_Sleep(30);
1308 #endif /* AFS_PTHREAD_ENV */
1309     }
1310 }                               /*InitPR */
1311
1312 struct rx_connection *serverconns[MAXSERVERS];
1313 struct ubik_client *cstruct;
1314
1315 afs_int32
1316 vl_Initialize(char *confDir)
1317 {
1318     afs_int32 code, scIndex = 0, i;
1319     struct afsconf_dir *tdir;
1320     struct rx_securityClass *sc;
1321     struct afsconf_cell info;
1322
1323     tdir = afsconf_Open(confDir);
1324     if (!tdir) {
1325         ViceLog(0,
1326                 ("Could not open configuration directory (%s).\n", confDir));
1327         exit(1);
1328     }
1329     code = afsconf_ClientAuth(tdir, &sc, &scIndex);
1330     if (code) {
1331         ViceLog(0, ("Could not get security object for localAuth\n"));
1332         exit(1);
1333     }
1334     code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
1335     if (info.numServers > MAXSERVERS) {
1336         ViceLog(0,
1337                 ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
1338                  info.numServers, MAXSERVERS));
1339         exit(1);
1340     }
1341     for (i = 0; i < info.numServers; i++)
1342         serverconns[i] =
1343             rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
1344                              info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
1345                              scIndex);
1346     code = ubik_ClientInit(serverconns, &cstruct);
1347     if (code) {
1348         ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
1349         return code;
1350     }
1351     return 0;
1352 }
1353
1354 #define SYSIDMAGIC      0x88aabbcc
1355 #define SYSIDVERSION    1
1356
1357 afs_int32
1358 ReadSysIdFile()
1359 {
1360     afs_int32 fd, nentries, i;
1361     struct versionStamp vsn;
1362     struct afs_stat status;
1363     afsUUID uuid;
1364
1365     if ((afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status))
1366         || (status.st_size <= 0)) {
1367         ViceLog(0, ("%s: doesn't exist\n", AFSDIR_SERVER_SYSID_FILEPATH));
1368         return ENOENT;
1369     }
1370     if (!(fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_RDONLY, 0))) {
1371         ViceLog(0,
1372                 ("%s: can't open (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1373                  errno));
1374         return EIO;
1375     }
1376     if ((i = read(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1377         ViceLog(0,
1378                 ("%s: Read failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1379                  errno));
1380         return EIO;
1381     }
1382     if (vsn.magic != SYSIDMAGIC) {
1383         ViceLog(0,
1384                 ("%s: wrong magic %x (we support %x)\n",
1385                  AFSDIR_SERVER_SYSID_FILEPATH, vsn.magic, SYSIDMAGIC));
1386         return EIO;
1387     }
1388     if (vsn.version != SYSIDVERSION) {
1389         ViceLog(0,
1390                 ("%s: wrong version %d (we support %d)\n",
1391                  AFSDIR_SERVER_SYSID_FILEPATH, vsn.version, SYSIDVERSION));
1392         return EIO;
1393     }
1394     if ((i =
1395          read(fd, (char *)&uuid,
1396               sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1397         ViceLog(0,
1398                 ("%s: read of uuid failed (%d)\n",
1399                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1400         return EIO;
1401     }
1402     afs_ntohuuid(&uuid);
1403     FS_HostUUID = uuid;
1404     if ((i =
1405          read(fd, (char *)&nentries,
1406               sizeof(afs_int32))) != sizeof(afs_int32)) {
1407         ViceLog(0,
1408                 ("%s: Read of entries failed (%d)\n",
1409                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1410         return EIO;
1411     }
1412     if (nentries <= 0 || nentries > ADDRSPERSITE) {
1413         ViceLog(0,
1414                 ("%s: invalid num of interfaces: %d\n",
1415                  AFSDIR_SERVER_SYSID_FILEPATH, nentries));
1416         return EIO;
1417     }
1418     FS_HostAddr_cnt = nentries;
1419     for (i = 0; i < nentries; i++) {
1420         if (read(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1421             sizeof(afs_int32)) {
1422             ViceLog(0,
1423                     ("%s: Read of addresses failed (%d)\n",
1424                      AFSDIR_SERVER_SYSID_FILEPATH, errno));
1425             FS_HostAddr_cnt = 0;        /* reset it */
1426             return EIO;
1427         }
1428     }
1429     close(fd);
1430     return 0;
1431 }
1432
1433 afs_int32
1434 WriteSysIdFile()
1435 {
1436     afs_int32 fd, i;
1437     struct versionStamp vsn;
1438     struct afs_stat status;
1439     afsUUID uuid;
1440
1441     if (!afs_stat(AFSDIR_SERVER_SYSID_FILEPATH, &status)) {
1442         /*
1443          * File exists; keep the old one around
1444          */
1445         renamefile(AFSDIR_SERVER_SYSID_FILEPATH,
1446                    AFSDIR_SERVER_OLDSYSID_FILEPATH);
1447     }
1448     fd = afs_open(AFSDIR_SERVER_SYSID_FILEPATH, O_WRONLY | O_TRUNC | O_CREAT,
1449                   0666);
1450     if (fd < 1) {
1451         ViceLog(0,
1452                 ("%s: can't create (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1453                  errno));
1454         return EIO;
1455     }
1456     vsn.magic = SYSIDMAGIC;
1457     vsn.version = 1;
1458     if ((i = write(fd, (char *)&vsn, sizeof(vsn))) != sizeof(vsn)) {
1459         ViceLog(0,
1460                 ("%s: write failed (%d)\n", AFSDIR_SERVER_SYSID_FILEPATH,
1461                  errno));
1462         return EIO;
1463     }
1464     uuid = FS_HostUUID;
1465     afs_htonuuid(&uuid);
1466     if ((i =
1467          write(fd, (char *)&uuid,
1468                sizeof(struct afsUUID))) != sizeof(struct afsUUID)) {
1469         ViceLog(0,
1470                 ("%s: write of uuid failed (%d)\n",
1471                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1472         return EIO;
1473     }
1474     if ((i =
1475          write(fd, (char *)&FS_HostAddr_cnt,
1476                sizeof(afs_int32))) != sizeof(afs_int32)) {
1477         ViceLog(0,
1478                 ("%s: write of # of entries failed (%d)\n",
1479                  AFSDIR_SERVER_SYSID_FILEPATH, errno));
1480         return EIO;
1481     }
1482     for (i = 0; i < FS_HostAddr_cnt; i++) {
1483         if (write(fd, (char *)&FS_HostAddrs[i], sizeof(afs_int32)) !=
1484             sizeof(afs_int32)) {
1485             ViceLog(0,
1486                     ("%s: write of addresses failed (%d)\n",
1487                      AFSDIR_SERVER_SYSID_FILEPATH, errno));
1488             return EIO;
1489         }
1490     }
1491     close(fd);
1492     return 0;
1493 }
1494
1495 /*
1496  * defect 10966 
1497  * This routine sets up the buffers for the VL_RegisterAddrs RPC. All addresses
1498  * in FS_HostAddrs[] are in NBO, while the RPC treats them as a "blob" of data
1499  * and so we need to convert each of them into HBO which is what the extra 
1500  * array called FS_HostAddrs_HBO is used here.
1501  */
1502 afs_int32
1503 Do_VLRegisterRPC()
1504 {
1505     register int code;
1506     bulkaddrs addrs;
1507     extern int VL_RegisterAddrs();
1508     afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
1509     int i = 0;
1510
1511     for (i = 0; i < FS_HostAddr_cnt; i++)
1512         FS_HostAddrs_HBO[i] = ntohl(FS_HostAddrs[i]);
1513     addrs.bulkaddrs_len = FS_HostAddr_cnt;
1514     addrs.bulkaddrs_val = (afs_uint32 *) FS_HostAddrs_HBO;
1515     code = ubik_Call(VL_RegisterAddrs, cstruct, 0, &FS_HostUUID, 0, &addrs);
1516     if (code) {
1517         if (code == VL_MULTIPADDR) {
1518             ViceLog(0,
1519                     ("VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n"));
1520             ViceLog(0,
1521                     ("VL_RegisterAddrs rpc failed; See VLLog for details\n"));
1522             return code;
1523         } else if (code == RXGEN_OPCODE) {
1524             ViceLog(0,
1525                     ("vlserver doesn't support VL_RegisterAddrs rpc; ignored\n"));
1526             FS_registered = 2;  /* So we don't have to retry in the gc daemon */
1527         } else {
1528             ViceLog(0,
1529                     ("VL_RegisterAddrs rpc failed; will retry periodically (code=%d, err=%d)\n",
1530                      code, errno));
1531         }
1532     } else {
1533         FS_registered = 2;      /* So we don't have to retry in the gc daemon */
1534         WriteSysIdFile();
1535     }
1536
1537     return 0;
1538 }
1539
1540 afs_int32
1541 InitVL()
1542 {
1543     afs_int32 code;
1544     extern int rxi_numNetAddrs;
1545     extern afs_uint32 rxi_NetAddrs[];
1546
1547     /*
1548      * If this fails, it's because something major is wrong, and is not
1549      * likely to be time dependent.
1550      */
1551     code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
1552     if (code != 0) {
1553         ViceLog(0,
1554                 ("Couldn't initialize protection library; code=%d.\n", code));
1555         return code;
1556     }
1557
1558     /* Read or create the sysid file and register the fileserver's
1559      * IP addresses with the vlserver.
1560      */
1561     code = ReadSysIdFile();
1562     if (code) {
1563         /* Need to create the file */
1564         ViceLog(0, ("Creating new SysID file\n"));
1565         if ((code = afs_uuid_create(&FS_HostUUID))) {
1566             ViceLog(0, ("Failed to create new uuid: %d\n", code));
1567             exit(1);
1568         }
1569     }
1570     /* A good sysid file exists; inform the vlserver. If any conflicts,
1571      * we always use the latest interface available as the real truth.
1572      */
1573 #ifndef AFS_NT40_ENV
1574     if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
1575         /*
1576          * Find addresses we are supposed to register as per the netrestrict 
1577          * and netinfo files (/usr/afs/local/NetInfo and 
1578          * /usr/afs/local/NetRestict)
1579          */
1580         char reason[1024];
1581         afs_int32 code = parseNetFiles(FS_HostAddrs, NULL, NULL,
1582                                        ADDRSPERSITE, reason,
1583                                        AFSDIR_SERVER_NETINFO_FILEPATH,
1584                                        AFSDIR_SERVER_NETRESTRICT_FILEPATH);
1585         if (code < 0) {
1586             ViceLog(0, ("Can't register any valid addresses: %s\n", reason));
1587             exit(1);
1588         }
1589         FS_HostAddr_cnt = (afs_uint32) code;
1590     } else
1591 #endif
1592     {
1593         FS_HostAddr_cnt = rx_getAllAddr(FS_HostAddrs, ADDRSPERSITE);
1594     }
1595
1596     FS_registered = 1;
1597     code = Do_VLRegisterRPC();
1598     return code;
1599 }
1600
1601 int
1602 main(int argc, char *argv[])
1603 {
1604     afs_int32 code;
1605     char tbuffer[32];
1606     struct rx_securityClass *sc[4];
1607     struct rx_service *tservice;
1608 #ifdef AFS_PTHREAD_ENV
1609     pthread_t serverPid;
1610     pthread_attr_t tattr;
1611 #else /* AFS_PTHREAD_ENV */
1612     PROCESS parentPid, serverPid;
1613 #endif /* AFS_PTHREAD_ENV */
1614     struct hostent *he;
1615     int minVnodesRequired;      /* min size of vnode cache */
1616 #ifndef AFS_NT40_ENV
1617     struct rlimit rlim;         /* max number of open file descriptors */
1618 #endif
1619     int curLimit;
1620     time_t t;
1621
1622 #ifdef  AFS_AIX32_ENV
1623     struct sigaction nsa;
1624
1625     sigemptyset(&nsa.sa_mask);
1626     nsa.sa_handler = SIG_DFL;
1627     nsa.sa_flags = SA_FULLDUMP;
1628     sigaction(SIGABRT, &nsa, NULL);
1629     sigaction(SIGSEGV, &nsa, NULL);
1630 #endif
1631
1632     /* Initialize dirpaths */
1633     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
1634 #ifdef AFS_NT40_ENV
1635         ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
1636 #endif
1637         fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
1638                 argv[0]);
1639         exit(2);
1640     }
1641 #ifndef AFS_QUIETFS_ENV
1642     console = afs_fopen("/dev/console", "w");
1643 #endif
1644
1645     if (ParseArgs(argc, argv)) {
1646         FlagMsg();
1647         exit(-1);
1648     }
1649 #ifdef AFS_PTHREAD_ENV
1650     assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0);
1651 #endif /* AFS_PTHREAD_ENV */
1652
1653 #ifdef AFS_SGI_VNODE_GLUE
1654     if (afs_init_kernel_config(-1) < 0) {
1655         printf
1656             ("Can't determine NUMA configuration, not starting fileserver.\n");
1657         exit(1);
1658     }
1659 #endif
1660     confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
1661     if (!confDir) {
1662         fprintf(stderr, "Unable to open config directory %s\n",
1663                 AFSDIR_SERVER_ETC_DIRPATH);
1664         exit(-1);
1665     }
1666
1667     NewParms(1);
1668
1669     /* Open FileLog on stdout, stderr, fd 1 and fd2 (for perror), sigh. */
1670 #ifndef AFS_NT40_ENV
1671     serverLogSyslogTag = "fileserver";
1672 #endif
1673     OpenLog(AFSDIR_SERVER_FILELOG_FILEPATH);
1674     SetupLogSignals();
1675
1676     if (SawSpare && SawPctSpare) {
1677         ViceLog(0, ("Both -spare and -pctspare specified, exiting.\n"));
1678         exit(-1);
1679     }
1680 #ifdef AFS_SGI_XFS_IOPS_ENV
1681     ViceLog(0, ("XFS/EFS File server starting\n"));
1682 #else
1683     ViceLog(0, ("File server starting\n"));
1684 #endif
1685
1686 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1687     /* initialize the pthread soft signal handler thread */
1688     softsig_init();
1689 #endif
1690
1691     /* install signal handlers for controlling the fileserver process */
1692     ResetCheckSignal();         /* set CheckSignal_Signal() sig handler */
1693     ResetCheckDescriptors();    /* set CheckDescriptors_Signal() sig handler */
1694
1695 #if defined(AFS_SGI_ENV)
1696     /* give this guy a non-degrading priority so help busy servers */
1697     schedctl(NDPRI, 0, NDPNORMMAX);
1698     if (SawLock)
1699         plock(PROCLOCK);
1700 #else
1701 #ifndef AFS_NT40_ENV
1702     nice(-5);                   /* TODO: */
1703 #endif
1704 #endif
1705     assert(DInit(buffs) == 0);
1706
1707 #ifdef AFS_NT40_ENV
1708     if (afs_winsockInit() < 0) {
1709         ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
1710         ViceLog(0, ("File server failed to intialize winsock.\n"));
1711         exit(1);
1712     }
1713 #endif
1714     CheckAdminName();
1715
1716     /* if we support more than 16 threads, then we better have the ability 
1717      ** to keep open a large number of files simultaneously 
1718      */
1719 #if     defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV)
1720     curLimit = OPEN_MAX;        /* for pre AIX 4.2 systems */
1721 #elif defined(AFS_NT40_ENV)
1722     curLimit = NT_OPEN_MAX;     /* open file descriptor limit on NT */
1723 #else
1724
1725     curLimit = 0;               /* the number of open file descriptors */
1726     code = getrlimit(RLIMIT_NOFILE, &rlim);
1727     if (code == 0) {
1728         curLimit = rlim.rlim_cur;
1729         rlim.rlim_cur = rlim.rlim_max;
1730         code = setrlimit(RLIMIT_NOFILE, &rlim);
1731         if (code == 0)
1732             curLimit = rlim.rlim_max;
1733     }
1734     if (code != 0)
1735         ViceLog(0, ("Failed to increase open file limit, using default\n"));
1736
1737 #endif /* defined(AFS_AIX_ENV) && !defined(AFS_AIX42_ENV) */
1738
1739     curLimit -= 32;             /* leave a slack of 32 file descriptors */
1740     if (lwps > curLimit) {
1741         if (curLimit > 0)
1742             lwps = curLimit;
1743         else if (lwps > 16)
1744             lwps = 16;          /* default to a maximum of 16 threads */
1745         ViceLog(0,
1746                 ("The system supports a max of %d open files and we are starting %d threads\n",
1747                  curLimit, lwps));
1748     }
1749 #ifndef AFS_PTHREAD_ENV
1750     assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) ==
1751            LWP_SUCCESS);
1752 #endif /* !AFS_PTHREAD_ENV */
1753
1754     /* Initialize volume support */
1755     if (!novbc) {
1756         V_BreakVolumeCallbacks = BreakVolumeCallBacksLater;
1757     }
1758
1759 #ifdef AFS_PTHREAD_ENV
1760     SetLogThreadNumProgram( threadNum );
1761 #endif
1762
1763     /* initialize libacl routines */
1764     acl_Initialize(ACL_VERSION);
1765
1766     /* initialize RX support */
1767 #ifndef AFS_NT40_ENV
1768     rxi_syscallp = viced_syscall;
1769 #endif
1770     rx_extraPackets = rxpackets;
1771     rx_extraQuota = 4;          /* for outgoing prserver calls from R threads */
1772     rx_SetBusyThreshold(busy_threshold, VBUSY);
1773     rx_SetCallAbortThreshold(abort_threshold);
1774     rx_SetConnAbortThreshold(abort_threshold);
1775     stackSize = lwps * 4000;
1776     if (stackSize < 32000)
1777         stackSize = 32000;
1778     else if (stackSize > 44000)
1779         stackSize = 44000;
1780 #if    defined(AFS_HPUX_ENV) || defined(AFS_SUN_ENV) || defined(AFS_SGI51_ENV)
1781     rx_SetStackSize(1, stackSize);
1782 #endif
1783     if (udpBufSize)
1784         rx_SetUdpBufSize(udpBufSize);   /* set the UDP buffer size for receive */
1785     if (rx_Init((int)htons(7000)) < 0) {
1786         ViceLog(0, ("Cannot initialize RX\n"));
1787         exit(1);
1788     }
1789     if (!rxJumbograms) {
1790         /* Don't send and don't allow 3.4 clients to send jumbograms. */
1791         rx_SetNoJumbo();
1792     }
1793     rx_GetIFInfo();
1794     rx_SetRxDeadTime(30);
1795     sc[0] = rxnull_NewServerSecurityObject();
1796     sc[1] = 0;                  /* rxvab_NewServerSecurityObject(key1, 0) */
1797     sc[2] = rxkad_NewServerSecurityObject(rxkad_clear, NULL, get_key, NULL);
1798     sc[3] = rxkad_NewServerSecurityObject(rxkad_crypt, NULL, get_key, NULL);
1799     tservice = rx_NewService( /* port */ 0, /* service id */ 1, /*service name */
1800                              "AFS",
1801                                                         /* security classes */ sc,
1802                                                         /* numb sec classes */
1803                              4, RXAFS_ExecuteRequest);
1804     if (!tservice) {
1805         ViceLog(0,
1806                 ("Failed to initialize RX, probably two servers running.\n"));
1807         exit(-1);
1808     }
1809     rx_SetDestroyConnProc(tservice, (void (*)())h_FreeConnection);
1810     rx_SetMinProcs(tservice, 3);
1811     rx_SetMaxProcs(tservice, lwps);
1812     rx_SetCheckReach(tservice, 1);
1813
1814     tservice =
1815         rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 4,
1816                       RXSTATS_ExecuteRequest);
1817     if (!tservice) {
1818         ViceLog(0, ("Failed to initialize rpc stat service.\n"));
1819         exit(-1);
1820     }
1821     rx_SetMinProcs(tservice, 2);
1822     rx_SetMaxProcs(tservice, 4);
1823
1824     /*
1825      * Enable RX hot threads, which allows the listener thread to trade
1826      * places with an idle thread and moves the context switch from listener
1827      * to worker out of the critical path.
1828      */
1829     rx_EnableHotThread();
1830
1831     /* Some rx debugging */
1832     if (rxlog || eventlog) {
1833         debugFile = afs_fopen("rx_dbg", "w");
1834         if (rxlog)
1835             rx_debugFile = debugFile;
1836         if (eventlog)
1837             rxevent_debugFile = debugFile;
1838     }
1839
1840     init_sys_error_to_et();     /* Set up error table translation */
1841     h_InitHostPackage();        /* set up local cellname and realmname */
1842     InitCallBack(numberofcbs);
1843     ClearXStatValues();
1844
1845     code = InitVL();
1846     if (code) {
1847         ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
1848         exit(1);
1849     }
1850
1851     code = InitPR();
1852     if (code) {
1853         ViceLog(0, ("Fatal error in protection initialization, exiting!!\n"));
1854         exit(1);
1855     }
1856
1857     /* allow super users to manage RX statistics */
1858     rx_SetRxStatUserOk(fs_rxstat_userok);
1859
1860     rx_StartServer(0);          /* now start handling requests */
1861
1862     /* we ensure that there is enough space in the vnode buffer to satisfy
1863      ** requests from all concurrent threads. 
1864      ** the maximum number of vnodes used by a single thread at any one time
1865      ** is three ( "link" uses three vnodes simultaneously, one vLarge and
1866      ** two vSmall for linking files and two vLarge and one vSmall for linking
1867      ** files  ) : dhruba 
1868      */
1869     minVnodesRequired = 2 * lwps + 1;
1870     if (minVnodesRequired > nSmallVns) {
1871         nSmallVns = minVnodesRequired;
1872         ViceLog(0,
1873                 ("Overriding -s command line parameter with %d\n",
1874                  nSmallVns));
1875     }
1876     if (minVnodesRequired > large) {
1877         large = minVnodesRequired;
1878         ViceLog(0, ("Overriding -l command line parameter with %d\n", large));
1879     }
1880
1881     /* We now do this after getting the listener up and running, so that client
1882      * connections don't timeout (maybe) if a file server is restarted, since it
1883      * will be available "real soon now".  Worry about whether we can satisfy the 
1884      * calls in the volume package itself.
1885      */
1886     if (VInitVolumePackage(fileServer, large, nSmallVns, 0, volcache)) {
1887         ViceLog(0,
1888                 ("Shutting down: errors encountered initializing volume package\n"));
1889         VShutdown();
1890         exit(1);
1891     }
1892
1893     /*
1894      * We are done calling fopen/fdopen. It is safe to use a large
1895      * of the file descriptor cache.
1896      */
1897     ih_UseLargeCache();
1898
1899 #ifdef AFS_PTHREAD_ENV
1900     ViceLog(5, ("Starting pthreads\n"));
1901     assert(pthread_attr_init(&tattr) == 0);
1902     assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
1903
1904     assert(pthread_create
1905            (&serverPid, &tattr, (void *)FiveMinuteCheckLWP,
1906             &fiveminutes) == 0);
1907     assert(pthread_create
1908            (&serverPid, &tattr, (void *)HostCheckLWP, &fiveminutes) == 0);
1909     assert(pthread_create
1910            (&serverPid, &tattr, (void *)FsyncCheckLWP, &fiveminutes) == 0);
1911 #else /* AFS_PTHREAD_ENV */
1912     ViceLog(5, ("Starting LWP\n"));
1913     assert(LWP_CreateProcess
1914            (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1915             (void *)&fiveminutes, "FiveMinuteChecks",
1916             &serverPid) == LWP_SUCCESS);
1917
1918     assert(LWP_CreateProcess
1919            (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1920             (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS);
1921     assert(LWP_CreateProcess
1922            (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2,
1923             (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS);
1924 #endif /* AFS_PTHREAD_ENV */
1925
1926     TM_GetTimeOfDay(&tp, 0);
1927
1928 #ifndef AFS_QUIETFS_ENV
1929     if (console != NULL) { 
1930         time_t t = tp.tv_sec;
1931         fprintf(console, "File server has started at %s\r",
1932                 afs_ctime(&t, tbuffer, sizeof(tbuffer)));
1933     }
1934 #endif
1935
1936     /*
1937      * Figure out the FileServer's name and primary address.
1938      */
1939     ViceLog(0, ("Getting FileServer name...\n"));
1940     code = gethostname(FS_HostName, 64);
1941     if (code) {
1942         ViceLog(0, ("gethostname() failed\n"));
1943     }
1944     ViceLog(0, ("FileServer host name is '%s'\n", FS_HostName));
1945
1946     ViceLog(0, ("Getting FileServer address...\n"));
1947     he = gethostbyname(FS_HostName);
1948     if (!he) {
1949         ViceLog(0, ("Can't find address for FileServer '%s'\n", FS_HostName));
1950     } else {
1951         char hoststr[16];
1952         memcpy(&FS_HostAddr_NBO, he->h_addr, 4);
1953         (void)afs_inet_ntoa_r(FS_HostAddr_NBO, hoststr);
1954         FS_HostAddr_HBO = ntohl(FS_HostAddr_NBO);
1955         ViceLog(0,
1956                 ("FileServer %s has address %s (0x%x or 0x%x in host byte order)\n",
1957                  FS_HostName, hoststr, FS_HostAddr_NBO, FS_HostAddr_HBO));
1958     }
1959
1960     /* Install handler to catch the shutdown signal;
1961      * bosserver assumes SIGQUIT shutdown
1962      */
1963 #if defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
1964     softsig_signal(SIGQUIT, ShutDown_Signal);
1965 #else
1966     (void)signal(SIGQUIT, ShutDown_Signal);
1967 #endif
1968
1969     t = tp.tv_sec;
1970     ViceLog(0,
1971             ("File Server started %s",
1972              afs_ctime(&t, tbuffer, sizeof(tbuffer))));
1973 #if FS_STATS_DETAILED
1974     afs_FullPerfStats.det.epoch.tv_sec = StartTime = tp.tv_sec;
1975 #endif
1976 #ifdef AFS_PTHREAD_ENV
1977     while (1) {
1978         sleep(1000);            /* long time */
1979     }
1980 #else /* AFS_PTHREAD_ENV */
1981     assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS);
1982 #endif /* AFS_PTHREAD_ENV */
1983 }