2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
26 #include <WINNT/afsevent.h>
28 #ifdef HAVE_SYS_FILE_H
35 #ifdef HAVE_NETINET_IN_H
36 #include <netinet/in.h>
42 #include <rx/rx_globals.h>
43 #include <afs/cellconfig.h>
48 #include <afs/afsutil.h>
53 const char *vl_dbaseName;
54 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
57 struct vldstats dynamic_statistics;
58 struct ubik_dbase *VL_dbase;
59 afs_uint32 HostAddress[MAXSERVERID + 1];
60 extern int afsconf_CheckAuth();
61 extern int afsconf_ServerAuth();
66 int rxJumbograms = 1; /* default is to send and receive jumbo grams */
70 #define ADDRSPERSITE 16 /* Same global is in rx/rx_user.c */
71 afs_uint32 SHostAddrs[ADDRSPERSITE];
76 IOMGR_SoftSig(CheckSignal, 0);
82 register int i, errorcode;
83 struct ubik_trans *trans;
86 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
88 VLog(0, ("Dump name hash table out\n"));
89 for (i = 0; i < HASHSIZE; i++) {
92 VLog(0, ("Dump id hash table out\n"));
93 for (i = 0; i < HASHSIZE; i++) {
96 return (ubik_EndTrans(trans));
100 /* Initialize the stats for the opcodes */
106 dynamic_statistics.start_time = (afs_uint32) time(0);
107 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
108 dynamic_statistics.requests[i] = 0;
109 dynamic_statistics.aborts[i] = 0;
113 /* check whether caller is authorized to manage RX statistics */
115 vldb_rxstat_userok(call)
116 struct rx_call *call;
118 return afsconf_SuperUser(vldb_confdir, call, NULL);
121 /* Main server module */
123 #include "AFS_component_version_number.c"
129 register afs_int32 code;
131 struct rx_service *tservice;
132 struct rx_securityClass *sc[3];
133 extern int VL_ExecuteRequest();
134 extern int RXSTATS_ExecuteRequest();
135 struct afsconf_dir *tdir;
136 struct ktc_encryptionKey tkey;
137 struct afsconf_cell info;
139 char hostname[VL_MAXNAMELEN];
140 int noAuth = 0, index, i;
141 extern int rx_extraPackets;
142 char commandLine[150];
143 char clones[MAXHOSTSPERCELL];
144 afs_uint32 host = ntohl(INADDR_ANY);
148 * The following signal action for AIX is necessary so that in case of a
149 * crash (i.e. core is generated) we can include the user's data section
150 * in the core dump. Unfortunately, by default, only a partial core is
151 * generated which, in many cases, isn't too useful.
153 struct sigaction nsa;
155 rx_extraPackets = 100; /* should be a switch, I guess... */
156 sigemptyset(&nsa.sa_mask);
157 nsa.sa_handler = SIG_DFL;
158 nsa.sa_flags = SA_FULLDUMP;
159 sigaction(SIGABRT, &nsa, NULL);
160 sigaction(SIGSEGV, &nsa, NULL);
164 /* Parse command line */
165 for (index = 1; index < argc; index++) {
166 if (strcmp(argv[index], "-noauth") == 0) {
169 } else if (strcmp(argv[index], "-p") == 0) {
170 lwps = atoi(argv[++index]);
172 printf("Warning: '-p %d' is too big; using %d instead\n",
177 } else if (strcmp(argv[index], "-nojumbo") == 0) {
180 } else if (strcmp(argv[index], "-rxbind") == 0) {
183 } else if (!strcmp(argv[index], "-rxmaxmtu")) {
184 if ((index + 1) >= argc) {
185 fprintf(stderr, "missing argument for -rxmaxmtu\n");
188 rxMaxMTU = atoi(argv[++i]);
189 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
190 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
191 printf("rxMaxMTU %d% invalid; must be between %d-%d\n",
192 rxMaxMTU, RX_MIN_PACKET_SIZE,
193 RX_MAX_PACKET_DATA_SIZE);
197 } else if (strcmp(argv[index], "-smallmem") == 0) {
200 } else if (strcmp(argv[index], "-trace") == 0) {
201 extern char rxi_tracename[80];
202 strcpy(rxi_tracename, argv[++index]);
204 } else if (strcmp(argv[index], "-auditlog") == 0) {
207 char oldName[MAXPATHLEN];
208 char *fileName = argv[++index];
213 if ((lstat(fileName, &statbuf) == 0)
214 && (S_ISFIFO(statbuf.st_mode))) {
215 flags = O_WRONLY | O_NONBLOCK;
219 strcpy(oldName, fileName);
220 strcat(oldName, ".old");
221 renamefile(fileName, oldName);
222 flags = O_WRONLY | O_TRUNC | O_CREAT;
224 tempfd = open(fileName, flags, 0666);
226 auditout = fdopen(tempfd, "a");
228 osi_audit_file(auditout);
230 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
232 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
233 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
234 rx_enablePeerRPCStats();
235 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
236 rx_enableProcessRPCStats();
238 } else if (strcmp(argv[index], "-syslog") == 0) {
239 /* set syslog logging flag */
241 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
243 serverLogSyslogFacility = atoi(argv[index] + 8);
246 /* support help flag */
248 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
249 "[-rxmaxmtu <bytes>] [-rxbind] "
250 "[-auditlog <log path>] "
251 "[-syslog[=FACILITY]] "
252 "[-enable_peer_stats] [-enable_process_stats] "
255 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
256 "[-rxmaxmtu <bytes>] [-rxbind] "
257 "[-auditlog <log path>] "
258 "[-enable_peer_stats] [-enable_process_stats] "
266 /* Initialize dirpaths */
267 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
269 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
271 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
275 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
278 serverLogSyslogTag = "vlserver";
280 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
283 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
286 ("vlserver: can't open configuration files in dir %s, giving up.\n",
287 AFSDIR_SERVER_ETC_DIRPATH);
291 /* initialize winsock */
292 if (afs_winsockInit() < 0) {
293 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
294 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
299 gethostname(hostname, sizeof(hostname));
300 th = gethostbyname(hostname);
302 printf("vlserver: couldn't get address of this host (%s).\n",
306 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
308 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
309 signal(SIGXCPU, CheckSignal_Signal);
311 /* get list of servers */
313 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
316 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
320 vldb_confdir = tdir; /* Preserve our configuration dir */
321 /* rxvab no longer supported */
322 memset(&tkey, 0, sizeof(tkey));
325 afsconf_SetNoAuthFlag(tdir, 1);
330 if (AFSDIR_SERVER_NETRESTRICT_FILEPATH ||
331 AFSDIR_SERVER_NETINFO_FILEPATH) {
333 ccode = parseNetFiles(SHostAddrs, NULL, NULL,
334 ADDRSPERSITE, reason,
335 AFSDIR_SERVER_NETINFO_FILEPATH,
336 AFSDIR_SERVER_NETRESTRICT_FILEPATH);
340 ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE);
343 host = SHostAddrs[0];
344 rx_InitHost(host, htons(AFSCONF_VLDBPORT));
349 ubik_CRXSecurityProc = afsconf_ClientAuth;
350 ubik_CRXSecurityRock = (char *)tdir;
351 ubik_SRXSecurityProc = afsconf_ServerAuth;
352 ubik_SRXSecurityRock = (char *)tdir;
353 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
354 ubik_CheckRXSecurityRock = (char *)tdir;
356 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
357 vl_dbaseName, &VL_dbase);
359 printf("vlserver: Ubik init failed with code %d\n", code);
365 if (rxMaxMTU != -1) {
366 rx_SetMaxMTU(rxMaxMTU);
368 rx_SetRxDeadTime(50);
370 memset(HostAddress, 0, sizeof(HostAddress));
373 sc[0] = rxnull_NewServerSecurityObject();
374 sc[1] = (struct rx_securityClass *)0;
375 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
378 rx_NewServiceHost(host, 0, USER_SERVICE_ID, "Vldb server", sc, 3,
380 if (tservice == (struct rx_service *)0) {
381 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
384 rx_SetMinProcs(tservice, 2);
387 rx_SetMaxProcs(tservice, lwps);
390 rx_NewServiceHost(host, 0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
391 RXSTATS_ExecuteRequest);
392 if (tservice == (struct rx_service *)0) {
393 printf("vlserver: Could not create rpc stats rx service\n");
396 rx_SetMinProcs(tservice, 2);
397 rx_SetMaxProcs(tservice, 4);
399 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
401 strcat(commandLine, " ");
402 strcat(commandLine, argv[i]);
405 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
406 printf("%s\n", cml_version_number); /* Goes to the log */
408 /* allow super users to manage RX statistics */
409 rx_SetRxStatUserOk(vldb_rxstat_userok);
411 rx_StartServer(1); /* Why waste this idle process?? */