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