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>
25 #include <WINNT/afsevent.h>
27 #ifdef HAVE_SYS_FILE_H
34 #ifdef HAVE_NETINET_IN_H
35 #include <netinet/in.h>
49 #include <rx/rx_globals.h>
50 #include <afs/cellconfig.h>
55 #include <afs/afsutil.h>
60 const char *vl_dbaseName;
61 struct afsconf_dir *vldb_confdir = 0; /* vldb configuration dir */
64 struct vldstats dynamic_statistics;
65 struct ubik_dbase *VL_dbase;
66 afs_uint32 HostAddress[MAXSERVERID + 1];
67 extern int afsconf_CheckAuth();
68 extern int afsconf_ServerAuth();
73 int rxJumbograms = 1; /* default is to send and receive jumbo grams */
79 IOMGR_SoftSig(CheckSignal, 0);
85 register int i, errorcode;
86 struct ubik_trans *trans;
89 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
91 VLog(0, ("Dump name hash table out\n"));
92 for (i = 0; i < HASHSIZE; i++) {
95 VLog(0, ("Dump id hash table out\n"));
96 for (i = 0; i < HASHSIZE; i++) {
99 return (ubik_EndTrans(trans));
103 /* Initialize the stats for the opcodes */
109 dynamic_statistics.start_time = (afs_uint32) time(0);
110 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
111 dynamic_statistics.requests[i] = 0;
112 dynamic_statistics.aborts[i] = 0;
116 /* check whether caller is authorized to manage RX statistics */
118 vldb_rxstat_userok(call)
119 struct rx_call *call;
121 return afsconf_SuperUser(vldb_confdir, call, NULL);
124 /* Main server module */
126 #include "AFS_component_version_number.c"
132 register afs_int32 code;
134 struct rx_service *tservice;
135 struct rx_securityClass *sc[3];
136 extern int VL_ExecuteRequest();
137 extern int RXSTATS_ExecuteRequest();
138 struct afsconf_dir *tdir;
139 struct ktc_encryptionKey tkey;
140 struct afsconf_cell info;
142 char hostname[VL_MAXNAMELEN];
143 int noAuth = 0, index, i;
144 extern int rx_extraPackets;
145 char commandLine[150];
146 char clones[MAXHOSTSPERCELL];
150 * The following signal action for AIX is necessary so that in case of a
151 * crash (i.e. core is generated) we can include the user's data section
152 * in the core dump. Unfortunately, by default, only a partial core is
153 * generated which, in many cases, isn't too useful.
155 struct sigaction nsa;
157 rx_extraPackets = 100; /* should be a switch, I guess... */
158 sigemptyset(&nsa.sa_mask);
159 nsa.sa_handler = SIG_DFL;
160 nsa.sa_flags = SA_FULLDUMP;
161 sigaction(SIGABRT, &nsa, NULL);
162 sigaction(SIGSEGV, &nsa, NULL);
166 /* Parse command line */
167 for (index = 1; index < argc; index++) {
168 if (strcmp(argv[index], "-noauth") == 0) {
171 } else if (strcmp(argv[index], "-p") == 0) {
172 lwps = atoi(argv[++index]);
174 printf("Warning: '-p %d' is too big; using %d instead\n",
179 } else if (strcmp(argv[index], "-nojumbo") == 0) {
182 } else if (!strcmp(argv[i], "-rxmaxmtu")) {
183 if ((i + 1) >= argc) {
184 fprintf(stderr, "missing argument for -rxmaxmtu\n");
187 rxMaxMTU = atoi(argv[++i]);
188 if ((rxMaxMTU < RX_MIN_PACKET_SIZE) ||
189 (rxMaxMTU > RX_MAX_PACKET_DATA_SIZE)) {
190 printf("rxMaxMTU %d% invalid; must be between %d-%d\n",
191 rxMaxMTU, RX_MIN_PACKET_SIZE,
192 RX_MAX_PACKET_DATA_SIZE);
196 } else if (strcmp(argv[index], "-smallmem") == 0) {
199 } else if (strcmp(argv[index], "-trace") == 0) {
200 extern char rxi_tracename[80];
201 strcpy(rxi_tracename, argv[++index]);
203 } else if (strcmp(argv[index], "-auditlog") == 0) {
206 char oldName[MAXPATHLEN];
207 char *fileName = argv[++index];
212 if ((lstat(fileName, &statbuf) == 0)
213 && (S_ISFIFO(statbuf.st_mode))) {
214 flags = O_WRONLY | O_NONBLOCK;
218 strcpy(oldName, fileName);
219 strcat(oldName, ".old");
220 renamefile(fileName, oldName);
221 flags = O_WRONLY | O_TRUNC | O_CREAT;
223 tempfd = open(fileName, flags, 0666);
225 auditout = fdopen(tempfd, "a");
227 osi_audit_file(auditout);
229 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
231 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
232 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
233 rx_enablePeerRPCStats();
234 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
235 rx_enableProcessRPCStats();
237 } else if (strcmp(argv[index], "-syslog") == 0) {
238 /* set syslog logging flag */
240 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
242 serverLogSyslogFacility = atoi(argv[index] + 8);
245 /* support help flag */
247 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
248 "[-rxmaxmtu <bytes>] "
249 "[-auditlog <log path>] "
250 "[-syslog[=FACILITY]] "
251 "[-enable_peer_stats] [-enable_process_stats] "
254 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
255 "[-rxmaxmtu <bytes>] "
256 "[-auditlog <log path>] "
257 "[-enable_peer_stats] [-enable_process_stats] "
265 /* Initialize dirpaths */
266 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
268 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
270 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
274 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
277 serverLogSyslogTag = "vlserver";
279 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
282 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
285 ("vlserver: can't open configuration files in dir %s, giving up.\n",
286 AFSDIR_SERVER_ETC_DIRPATH);
290 /* initialize winsock */
291 if (afs_winsockInit() < 0) {
292 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
293 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
298 gethostname(hostname, sizeof(hostname));
299 th = gethostbyname(hostname);
301 printf("vlserver: couldn't get address of this host (%s).\n",
305 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
307 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
308 signal(SIGXCPU, CheckSignal_Signal);
310 /* get list of servers */
312 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
315 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
319 vldb_confdir = tdir; /* Preserve our configuration dir */
320 /* rxvab no longer supported */
321 memset(&tkey, 0, sizeof(tkey));
324 afsconf_SetNoAuthFlag(tdir, 1);
327 ubik_CRXSecurityProc = afsconf_ClientAuth;
328 ubik_CRXSecurityRock = (char *)tdir;
329 ubik_SRXSecurityProc = afsconf_ServerAuth;
330 ubik_SRXSecurityRock = (char *)tdir;
331 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
332 ubik_CheckRXSecurityRock = (char *)tdir;
334 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
335 vl_dbaseName, &VL_dbase);
337 printf("vlserver: Ubik init failed with code %d\n", code);
343 if (rxMaxMTU != -1) {
344 rx_SetMaxMTU(rxMaxMTU);
346 rx_SetRxDeadTime(50);
348 memset(HostAddress, 0, sizeof(HostAddress));
351 sc[0] = rxnull_NewServerSecurityObject();
352 sc[1] = (struct rx_securityClass *)0;
353 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
355 rx_NewService(0, USER_SERVICE_ID, "Vldb server", sc, 3,
357 if (tservice == (struct rx_service *)0) {
358 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
361 rx_SetMinProcs(tservice, 2);
364 rx_SetMaxProcs(tservice, lwps);
367 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
368 RXSTATS_ExecuteRequest);
369 if (tservice == (struct rx_service *)0) {
370 printf("vlserver: Could not create rpc stats rx service\n");
373 rx_SetMinProcs(tservice, 2);
374 rx_SetMaxProcs(tservice, 4);
376 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
378 strcat(commandLine, " ");
379 strcat(commandLine, argv[i]);
382 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
383 printf("%s\n", cml_version_number); /* Goes to the log */
385 /* allow super users to manage RX statistics */
386 rx_SetRxStatUserOk(vldb_rxstat_userok);
388 rx_StartServer(1); /* Why waste this idle process?? */