viced: null-terminate server list for ubik
[openafs.git] / src / viced / viced.c
index f03ac08..c448d80 100644 (file)
@@ -180,6 +180,7 @@ pthread_key_t viced_uclient_key;
 #define ADDRSPERSITE 16                /* Same global is in rx/rx_user.c */
 
 char FS_HostName[128] = "localhost";
+char *FS_configPath = NULL;
 afs_uint32 FS_HostAddr_NBO;
 afs_uint32 FS_HostAddr_HBO;
 afs_uint32 FS_HostAddrs[ADDRSPERSITE], FS_HostAddr_cnt = 0, FS_registered = 0;
@@ -279,9 +280,9 @@ CheckDescriptors_Signal(int x)
     CheckDescriptors(NULL);
 }
 
-/* check whether caller is authorized to manage RX statistics */
+/* check whether caller is authorized to perform admin operations */
 int
-fs_rxstat_userok(struct rx_call *call)
+viced_SuperUser(struct rx_call *call)
 {
     return afsconf_SuperUser(confDir, call, NULL);
 }
@@ -984,7 +985,7 @@ ParseArgs(int argc, char *argv[])
 {
     int code;
     int optval;
-    char *optstring;
+    char *optstring = NULL;
     struct cmd_item *optlist;
     struct cmd_syndesc *opts;
 
@@ -1482,30 +1483,24 @@ InitPR(void)
     }
 }                              /*InitPR */
 
-struct rx_connection *serverconns[MAXSERVERS];
-struct ubik_client *cstruct;
+static struct ubik_client *cstruct;
 
-afs_int32
-vl_Initialize(const char *confDir)
+static afs_int32
+vl_Initialize(struct afsconf_dir *dir)
 {
     afs_int32 code, i;
     afs_int32 scIndex = RX_SECIDX_NULL;
-    struct afsconf_dir *tdir;
-    struct rx_securityClass *sc;
     struct afsconf_cell info;
+    struct rx_securityClass *sc;
+    struct rx_connection *serverconns[MAXSERVERS];
 
-    tdir = afsconf_Open(confDir);
-    if (!tdir) {
-       ViceLog(0,
-               ("Could not open configuration directory (%s).\n", confDir));
-       exit(1);
-    }
-    code = afsconf_ClientAuth(tdir, &sc, &scIndex);
+    memset(serverconns, 0, sizeof(serverconns));
+    code = afsconf_ClientAuth(dir, &sc, &scIndex);
     if (code) {
        ViceLog(0, ("Could not get security object for localAuth\n"));
        exit(1);
     }
-    code = afsconf_GetCellInfo(tdir, NULL, AFSCONF_VLDBSERVICE, &info);
+    code = afsconf_GetCellInfo(dir, NULL, AFSCONF_VLDBSERVICE, &info);
     if (info.numServers > MAXSERVERS) {
        ViceLog(0,
                ("vl_Initialize: info.numServers=%d (> MAXSERVERS=%d)\n",
@@ -1518,7 +1513,6 @@ vl_Initialize(const char *confDir)
                             info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
                             scIndex);
     code = ubik_ClientInit(serverconns, &cstruct);
-    afsconf_Close(tdir);
     if (code) {
        ViceLog(0, ("vl_Initialize: ubik client init failed.\n"));
        return code;
@@ -1749,7 +1743,7 @@ SetupVL(void)
 }
 
 afs_int32
-InitVL(void)
+InitVL(struct afsconf_dir *dir)
 {
     afs_int32 code;
 
@@ -1757,7 +1751,7 @@ InitVL(void)
      * If this fails, it's because something major is wrong, and is not
      * likely to be time dependent.
      */
-    code = vl_Initialize(AFSDIR_SERVER_ETC_DIRPATH);
+    code = vl_Initialize(dir);
     if (code != 0) {
        ViceLog(0,
                ("Couldn't initialize volume location library; code=%d.\n", code));
@@ -1843,10 +1837,12 @@ main(int argc, char *argv[])
        exit(1);
     }
 #endif
-    confDir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
+    FS_configPath = strdup(AFSDIR_SERVER_ETC_DIRPATH);
+
+    confDir = afsconf_Open(FS_configPath);
     if (!confDir) {
        fprintf(stderr, "Unable to open config directory %s\n",
-               AFSDIR_SERVER_ETC_DIRPATH);
+               FS_configPath);
        exit(-1);
     }
 
@@ -2036,7 +2032,7 @@ main(int argc, char *argv[])
     InitCallBack(numberofcbs);
     ClearXStatValues();
 
-    code = InitVL();
+    code = InitVL(confDir);
     if (code && code != VL_MULTIPADDR) {
        ViceLog(0, ("Fatal error in library initialization, exiting!!\n"));
        exit(1);
@@ -2049,7 +2045,7 @@ main(int argc, char *argv[])
     }
 
     /* allow super users to manage RX statistics */
-    rx_SetRxStatUserOk(fs_rxstat_userok);
+    rx_SetRxStatUserOk(viced_SuperUser);
 
     CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0);
     MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0);