osi-audit-locking-fix-20060201
[openafs.git] / src / budb / server.c
index 95be539..3f0ebc9 100644 (file)
 RCSID
     ("$Header$");
 
+#include <fcntl.h>
+#include <sys/stat.h>
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
-#include <fcntl.h>
 #include <WINNT/afsevent.h>
 #else
 #include <netinet/in.h>
@@ -75,6 +76,14 @@ char dbDir[AFSDIR_PATH_MAX], cellConfDir[AFSDIR_PATH_MAX];
 /* debugging control */
 int debugging = 0;
 
+#if defined(AFS_PTHREAD_ENV)
+char *
+threadNum(void)
+{
+    return pthread_getspecific(rx_thread_id_key);
+}
+#endif
+
 /* check whether caller is authorized to manage RX statistics */
 int
 BU_rxstat_userok(call)
@@ -159,6 +168,9 @@ initializeArgHandler()
     cmd_AddParm(cptr, "-ubikbuffers", CMD_SINGLE, CMD_OPTIONAL,
                "the number of ubik buffers");
 
+    cmd_AddParm(cptr, "-auditlog", CMD_SINGLE, CMD_OPTIONAL,
+               "audit log path");
+
 }
 
 int
@@ -212,6 +224,36 @@ argHandler(as, arock)
     else
        ubik_nBuffers = 0;
 
+    if (as->parms[7].items != 0) {
+       int tempfd, flags;
+       FILE *auditout;
+       char oldName[MAXPATHLEN];
+       char *fileName = as->parms[7].items->data;
+#ifndef AFS_NT40_ENV
+       struct stat statbuf;
+
+       if ((lstat(fileName, &statbuf) == 0) 
+           && (S_ISFIFO(statbuf.st_mode))) {
+           flags = O_WRONLY | O_NONBLOCK;
+       } else 
+#endif
+       {
+           strcpy(oldName, fileName);
+           strcat(oldName, ".old");
+           renamefile(fileName, oldName);
+           flags = O_WRONLY | O_TRUNC | O_CREAT;
+       }
+       tempfd = open(fileName, flags, 0666);
+       if (tempfd > -1) {
+           auditout = fdopen(tempfd, "a");
+           if (auditout) {
+               osi_audit_file(auditout);
+           } else
+               printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+       } else
+           printf("Warning: auditlog %s not writable, ignored.\n", fileName);
+    }
+
     return 0;
 }
 
@@ -316,6 +358,10 @@ main(argc, argv)
     time_t currentTime;
     afs_int32 code = 0;
 
+    char  clones[MAXHOSTSPERCELL];
+
+       
+       
     struct rx_service *tservice;
     struct rx_securityClass *sca[3];
 
@@ -349,6 +395,7 @@ main(argc, argv)
     sigaction(SIGSEGV, &nsa, NULL);
     sigaction(SIGABRT, &nsa, NULL);
 #endif
+    osi_audit_init();
     osi_audit(BUDB_StartEvent, 0, AUD_END);
 
     initialize_BUDB_error_table();
@@ -385,6 +432,10 @@ main(argc, argv)
 
     srandom(1);
 
+#ifdef AFS_PTHREAD_ENV
+    SetLogThreadNumProgram( threadNum );
+#endif
+
     /* process the user supplied args */
     helpOption = 1;
     code = cmd_Dispatch(argc, argv);
@@ -430,7 +481,8 @@ main(argc, argv)
 
        LogDebug(1, "Using server list from %s cell database.\n", lcell);
 
-       code = afsconf_GetCellInfo(BU_conf, lcell, 0, &cellinfo);
+       code = afsconf_GetExtendedCellInfo (BU_conf, lcell, 0, &cellinfo, 
+                                           &clones); 
        code =
            convert_cell_to_ubik(&cellinfo, &globalConfPtr->myHost,
                                 globalConfPtr->serverList);
@@ -465,8 +517,13 @@ main(argc, argv)
 
     rx_SetRxDeadTime(60);      /* 60 seconds inactive before timeout */
 
-    code = ubik_ServerInit(globalConfPtr->myHost, htons(AFSCONF_BUDBPORT), globalConfPtr->serverList, dbNamePtr,       /* name prefix */
-                          &BU_dbase);
+    code = ubik_ServerInitByInfo (globalConfPtr->myHost,
+                                 htons(AFSCONF_BUDBPORT), 
+                                 &cellinfo,
+                                 &clones,              
+                                 dbNamePtr,           /* name prefix */
+                                 &BU_dbase);
+
     if (code) {
        LogError(code, "Ubik init failed\n");
        com_err(whoami, code, "Ubik init failed");
@@ -550,6 +607,7 @@ LogDebug(level, a, b, c, d, e, f, g, h, i)
            fclose(globalConfPtr->log);
        }
     }
+    return 0;
 }
 
 static char *
@@ -578,6 +636,7 @@ Log(a, b, c, d, e, f, g, h, i)
        fflush(globalConfPtr->log);
        fclose(globalConfPtr->log);
     }
+    return 0;
 }
 
  /*VARARGS*/
@@ -600,6 +659,7 @@ LogError(code, a, b, c, d, e, f, g, h, i)
        fflush(globalConfPtr->log);
        fclose(globalConfPtr->log);
     }
+    return 0;
 }
 
 
@@ -622,4 +682,5 @@ LogNetDump(dumpPtr)
        printDump(globalConfPtr->log, &hostDump);
        fclose(globalConfPtr->log);
     }
+    return 0;
 }