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 */
78 IOMGR_SoftSig(CheckSignal, 0);
84 register int i, errorcode;
85 struct ubik_trans *trans;
88 Init_VLdbase(&trans, LOCKREAD, VLGETSTATS - VL_LOWEST_OPCODE))
90 VLog(0, ("Dump name hash table out\n"));
91 for (i = 0; i < HASHSIZE; i++) {
94 VLog(0, ("Dump id hash table out\n"));
95 for (i = 0; i < HASHSIZE; i++) {
98 return (ubik_EndTrans(trans));
102 /* Initialize the stats for the opcodes */
108 dynamic_statistics.start_time = (afs_uint32) time(0);
109 for (i = 0; i < MAX_NUMBER_OPCODES; i++) {
110 dynamic_statistics.requests[i] = 0;
111 dynamic_statistics.aborts[i] = 0;
115 /* check whether caller is authorized to manage RX statistics */
117 vldb_rxstat_userok(call)
118 struct rx_call *call;
120 return afsconf_SuperUser(vldb_confdir, call, NULL);
123 /* Main server module */
125 #include "AFS_component_version_number.c"
131 register afs_int32 code;
133 struct rx_service *tservice;
134 struct rx_securityClass *sc[3];
135 extern int VL_ExecuteRequest();
136 extern int RXSTATS_ExecuteRequest();
137 struct afsconf_dir *tdir;
138 struct ktc_encryptionKey tkey;
139 struct afsconf_cell info;
141 char hostname[VL_MAXNAMELEN];
142 int noAuth = 0, index, i;
143 extern int rx_extraPackets;
144 char commandLine[150];
145 char clones[MAXHOSTSPERCELL];
149 * The following signal action for AIX is necessary so that in case of a
150 * crash (i.e. core is generated) we can include the user's data section
151 * in the core dump. Unfortunately, by default, only a partial core is
152 * generated which, in many cases, isn't too useful.
154 struct sigaction nsa;
156 rx_extraPackets = 100; /* should be a switch, I guess... */
157 sigemptyset(&nsa.sa_mask);
158 nsa.sa_handler = SIG_DFL;
159 nsa.sa_flags = SA_FULLDUMP;
160 sigaction(SIGABRT, &nsa, NULL);
161 sigaction(SIGSEGV, &nsa, NULL);
165 /* Parse command line */
166 for (index = 1; index < argc; index++) {
167 if (strcmp(argv[index], "-noauth") == 0) {
170 } else if (strcmp(argv[index], "-p") == 0) {
171 lwps = atoi(argv[++index]);
173 printf("Warning: '-p %d' is too big; using %d instead\n",
178 } else if (strcmp(argv[index], "-nojumbo") == 0) {
181 } else if (strcmp(argv[index], "-smallmem") == 0) {
184 } else if (strcmp(argv[index], "-trace") == 0) {
185 extern char rxi_tracename[80];
186 strcpy(rxi_tracename, argv[++index]);
188 } else if (strcmp(argv[index], "-auditlog") == 0) {
191 char oldName[MAXPATHLEN];
192 char *fileName = argv[++index];
197 if ((lstat(fileName, &statbuf) == 0)
198 && (S_ISFIFO(statbuf.st_mode))) {
199 flags = O_WRONLY | O_NONBLOCK;
203 strcpy(oldName, fileName);
204 strcat(oldName, ".old");
205 renamefile(fileName, oldName);
206 flags = O_WRONLY | O_TRUNC | O_CREAT;
208 tempfd = open(fileName, flags, 0666);
210 auditout = fdopen(tempfd, "a");
212 osi_audit_file(auditout);
214 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
216 printf("Warning: auditlog %s not writable, ignored.\n", fileName);
217 } else if (strcmp(argv[index], "-enable_peer_stats") == 0) {
218 rx_enablePeerRPCStats();
219 } else if (strcmp(argv[index], "-enable_process_stats") == 0) {
220 rx_enableProcessRPCStats();
222 } else if (strcmp(argv[index], "-syslog") == 0) {
223 /* set syslog logging flag */
225 } else if (strncmp(argv[index], "-syslog=", 8) == 0) {
227 serverLogSyslogFacility = atoi(argv[index] + 8);
230 /* support help flag */
232 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
233 "[-auditlog <log path>] "
234 "[-syslog[=FACILITY]] "
235 "[-enable_peer_stats] [-enable_process_stats] "
238 printf("Usage: vlserver [-p <number of processes>] [-nojumbo] "
239 "[-auditlog <log path>] "
240 "[-enable_peer_stats] [-enable_process_stats] "
248 /* Initialize dirpaths */
249 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
251 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
253 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
257 vl_dbaseName = AFSDIR_SERVER_VLDB_FILEPATH;
260 serverLogSyslogTag = "vlserver";
262 OpenLog(AFSDIR_SERVER_VLOG_FILEPATH); /* set up logging */
265 tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
268 ("vlserver: can't open configuration files in dir %s, giving up.\n",
269 AFSDIR_SERVER_ETC_DIRPATH);
273 /* initialize winsock */
274 if (afs_winsockInit() < 0) {
275 ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0);
276 fprintf(stderr, "vlserver: couldn't initialize winsock. \n");
281 gethostname(hostname, sizeof(hostname));
282 th = gethostbyname(hostname);
284 printf("vlserver: couldn't get address of this host (%s).\n",
288 memcpy(&myHost, th->h_addr, sizeof(afs_int32));
290 #if !defined(AFS_HPUX_ENV) && !defined(AFS_NT40_ENV) && !defined(AFS_DJGPP_ENV)
291 signal(SIGXCPU, CheckSignal_Signal);
293 /* get list of servers */
295 afsconf_GetExtendedCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info,
298 printf("vlserver: Couldn't get cell server list for 'afsvldb'.\n");
302 vldb_confdir = tdir; /* Preserve our configuration dir */
303 /* rxvab no longer supported */
304 memset(&tkey, 0, sizeof(tkey));
307 afsconf_SetNoAuthFlag(tdir, 1);
310 ubik_CRXSecurityProc = afsconf_ClientAuth;
311 ubik_CRXSecurityRock = (char *)tdir;
312 ubik_SRXSecurityProc = afsconf_ServerAuth;
313 ubik_SRXSecurityRock = (char *)tdir;
314 ubik_CheckRXSecurityProc = afsconf_CheckAuth;
315 ubik_CheckRXSecurityRock = (char *)tdir;
317 ubik_ServerInitByInfo(myHost, htons(AFSCONF_VLDBPORT), &info, &clones,
318 vl_dbaseName, &VL_dbase);
320 printf("vlserver: Ubik init failed with code %d\n", code);
326 rx_SetRxDeadTime(50);
328 memset(HostAddress, 0, sizeof(HostAddress));
331 sc[0] = rxnull_NewServerSecurityObject();
332 sc[1] = (struct rx_securityClass *)0;
333 sc[2] = rxkad_NewServerSecurityObject(0, tdir, afsconf_GetKey, NULL);
335 rx_NewService(0, USER_SERVICE_ID, "Vldb server", sc, 3,
337 if (tservice == (struct rx_service *)0) {
338 printf("vlserver: Could not create VLDB_SERVICE rx service\n");
341 rx_SetMinProcs(tservice, 2);
344 rx_SetMaxProcs(tservice, lwps);
347 rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats", sc, 3,
348 RXSTATS_ExecuteRequest);
349 if (tservice == (struct rx_service *)0) {
350 printf("vlserver: Could not create rpc stats rx service\n");
353 rx_SetMinProcs(tservice, 2);
354 rx_SetMaxProcs(tservice, 4);
356 for (commandLine[0] = '\0', i = 0; i < argc; i++) {
358 strcat(commandLine, " ");
359 strcat(commandLine, argv[i]);
362 ("Starting AFS vlserver %d (%s)\n", VLDBVERSION_4, commandLine));
363 printf("%s\n", cml_version_number); /* Goes to the log */
365 /* allow super users to manage RX statistics */
366 rx_SetRxStatUserOk(vldb_rxstat_userok);
368 rx_StartServer(1); /* Why waste this idle process?? */