viced: Release all hosts in h_Enumerate*
[openafs.git] / src / viced / host.c
index 0d62f84..7cf9b76 100644 (file)
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
+#include <roken.h>
 
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#ifdef AFS_NT40_ENV
-#include <fcntl.h>
-#include <winsock2.h>
-#else
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
-#include <netdb.h>
-#include <netinet/in.h>
 #endif
 
-#include <afs/stds.h>
 #include <rx/xdr.h>
 #include <afs/afs_assert.h>
 #include <lwp.h>
@@ -51,7 +44,6 @@
 #include <afs/com_err.h>
 #include <rx/rx.h>
 #include <afs/cellconfig.h>
-#include <stdlib.h>
 #include "viced_prototypes.h"
 #include "viced.h"
 #include "host.h"
@@ -304,17 +296,17 @@ hpr_Initialize(struct ubik_client **uclient)
     /* Most callers use secLevel==1, however, the fileserver uses secLevel==2
      * to force use of the KeyFile.  secLevel == 0 implies -noauth was
      * specified. */
-    if ((afsconf_GetLatestKey(tdir, 0, 0) == 0)) {
-        code = afsconf_ClientAuthSecure(tdir, &sc, &scIndex);
-        if (code)
-           ViceLog(0, ("hpr_Initialize: clientauthsecure returns %d %s (so trying noauth)", code, afs_error_message(code)));
-        if (code)
-            scIndex = RX_SECIDX_NULL;
-    }
-    if ((scIndex == RX_SECIDX_NULL) && (sc == NULL))
-        sc = rxnull_NewClientSecurityObject();
+    code = afsconf_ClientAuthSecure(tdir, &sc, &scIndex);
+    if (code) {
+       ViceLog(0, ("hpr_Initialize: clientauthsecure returns %d %s "
+                   "(so trying noauth)", code, afs_error_message(code)));
+       scIndex = RX_SECIDX_NULL;
+       sc = rxnull_NewClientSecurityObject();
+    }
+
     if (scIndex == RX_SECIDX_NULL)
-       ViceLog(0, ("hpr_Initialize: Could not get afs tokens, running unauthenticated. [%d]", code));
+       ViceLog(0, ("hpr_Initialize: Could not get afs tokens, "
+                   "running unauthenticated. [%d]", code));
 
     memset(serverconns, 0, sizeof(serverconns));        /* terminate list!!! */
     for (i = 0; i < info.numServers; i++) {
@@ -960,23 +952,18 @@ h_TossStuff_r(struct host *host)
 
 
 
-/* h_Enumerate: Calls (*proc)(host, held, param) for at least each host in the
+/* h_Enumerate: Calls (*proc)(host, param) for at least each host in the
  * system at the start of the enumeration (perhaps more).  Hosts may be deleted
  * (have delete flag set); ditto for clients.  refCount is always incremented
- * before (*proc) is called.  The param flags is passed to (*proc) as the
- * param flags, permitting (*proc) to stop the enumeration (BAIL).
+ * before (*proc) is called.
  *
- * Needed?  Why not always h_Hold_r and h_Release_r in (*proc), or even -never-
- * h_Hold_r or h_Release_r in (*proc)?
- *
- * **The proc should return 0 if the host should be released, 1 if it should
- * be held after enumeration.
+ * The return value of the proc is a set of flags. The proc should set
+ * H_ENUMERATE_BAIL(foo) if the enumeration of hosts should be stopped early.
  */
 void
-h_Enumerate(int (*proc) (struct host*, int, void *), void *param)
+h_Enumerate(int (*proc) (struct host*, void *), void *param)
 {
     struct host *host, **list;
-    int *flags;
     int i, count;
     int totalCount;
 
@@ -987,13 +974,7 @@ h_Enumerate(int (*proc) (struct host*, int, void *), void *param)
     }
     list = (struct host **)malloc(hostCount * sizeof(struct host *));
     if (!list) {
-       ViceLog(0, ("Failed malloc in h_Enumerate (list)\n"));
-       osi_Panic("Failed malloc in h_Enumerate (list)\n");
-    }
-    flags = (int *)malloc(hostCount * sizeof(int));
-    if (!flags) {
-       ViceLog(0, ("Failed malloc in h_Enumerate (flags)\n"));
-       osi_Panic("Failed malloc in h_Enumerate (flags)\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_Enumerate (list)\n"));
     }
     for (totalCount = count = 0, host = hostList;
          host && totalCount < hostCount;
@@ -1013,43 +994,51 @@ h_Enumerate(int (*proc) (struct host*, int, void *), void *param)
     }
     H_UNLOCK;
     for (i = 0; i < count; i++) {
-       flags[i] = (*proc) (list[i], flags[i], param);
+       int flags;
+       flags = (*proc) (list[i], param);
        H_LOCK;
        h_Release_r(list[i]);
        H_UNLOCK;
        /* bail out of the enumeration early */
-       if (H_ENUMERATE_ISSET_BAIL(flags[i]))
+       if (H_ENUMERATE_ISSET_BAIL(flags)) {
            break;
+       } else if (flags) {
+           ViceLog(0, ("h_Enumerate got back invalid return value %d\n", flags));
+           ShutDownAndCore(PANIC);
+       }
+    }
+    if (i < count-1) {
+       /* we bailed out of enumerating hosts early; we still have holds on
+        * some of the hosts in 'list', so release them */
+       i++;
+       H_LOCK;
+       for ( ; i < count; i++) {
+           h_Release_r(list[i]);
+       }
+       H_UNLOCK;
     }
     free((void *)list);
-    free((void *)flags);
 }      /* h_Enumerate */
 
 
 /* h_Enumerate_r (revised):
- * Calls (*proc)(host, flags, param) for each host in hostList, starting
+ * Calls (*proc)(host, param) for each host in hostList, starting
  * at enumstart. Called only under H_LOCK.  Hosts may be deleted (have
  * delete flag set); ditto for clients.  refCount is always incremented
- * before (*proc) is called.  The param flags is passed to (*proc) as the
- * param flags, permitting (*proc) to stop the enumeration (BAIL).
- *
- * Needed?  Why not always h_Hold_r and h_Release_r in (*proc), or even -never-
- * h_Hold_r or h_Release_r in (*proc)?
+ * before (*proc) is called.
  *
  * @note Assumes that hostList is only prepended to, that a host is never
  *       inserted into the middle. Otherwise this would not be guaranteed to
  *       terminate.
  *
- * **The proc should return 0 if the host should be released, 1 if it should
- * be held after enumeration.
+ * The return value of the proc is a set of flags. The proc should set
+ * H_ENUMERATE_BAIL(foo) if the enumeration of hosts should be stopped early.
  */
 void
-h_Enumerate_r(int (*proc) (struct host *, int, void *),
+h_Enumerate_r(int (*proc) (struct host *, void *),
              struct host *enumstart, void *param)
 {
     struct host *host, *next;
-    int flags = 0;
-    int nflags = 0;
     int count;
     int origHostCount;
 
@@ -1088,7 +1077,7 @@ h_Enumerate_r(int (*proc) (struct host *, int, void *),
      * h_Release_r */
     origHostCount = hostCount;
 
-    for (count = 0, host = enumstart; host && count < origHostCount; host = next, flags = nflags, count++) {
+    for (count = 0, host = enumstart; host && count < origHostCount; host = next, count++) {
        next = host->next;
 
        /* find the next non-deleted host */
@@ -1100,14 +1089,21 @@ h_Enumerate_r(int (*proc) (struct host *, int, void *),
                ShutDownAndCore(PANIC);
            }
        }
-       if (next && !H_ENUMERATE_ISSET_BAIL(flags))
+       if (next)
            h_Hold_r(next);
 
        if (!(host->hostFlags & HOSTDELETED)) {
-           flags = (*proc) (host, flags, param);
+           int flags;
+           flags = (*proc) (host, param);
            if (H_ENUMERATE_ISSET_BAIL(flags)) {
                h_Release_r(host); /* this might free up the host */
+               if (next) {
+                   h_Release_r(next);
+               }
                break;
+           } else if (flags) {
+               ViceLog(0, ("h_Enumerate_r got back invalid return value %d\n", flags));
+               ShutDownAndCore(PANIC);
            }
        }
        h_Release_r(host); /* this might free up the host */
@@ -1154,8 +1150,7 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host)
     /* insert into beginning of list for this bucket */
     chain = (struct h_UuidHashChain *)malloc(sizeof(struct h_UuidHashChain));
     if (!chain) {
-       ViceLog(0, ("Failed malloc in h_AddHostToUuidHashTable_r\n"));
-       osi_Panic("Failed malloc in h_AddHostToUuidHashTable_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_AddHostToUuidHashTable_r\n"));
     }
     chain->hostPtr = host;
     chain->next = hostUuidHashTable[index];
@@ -1341,8 +1336,7 @@ createHostAddrHashChain_r(int index, afs_uint32 addr, afs_uint16 port, struct ho
     /* insert into beginning of list for this bucket */
     chain = (struct h_AddrHashChain *)malloc(sizeof(struct h_AddrHashChain));
     if (!chain) {
-       ViceLog(0, ("Failed malloc in h_AddHostToAddrHashTable_r\n"));
-       osi_Panic("Failed malloc in h_AddHostToAddrHashTable_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_AddHostToAddrHashTable_r\n"));
     }
     chain->hostPtr = host;
     chain->next = hostAddrHashTable[index];
@@ -1562,8 +1556,7 @@ addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port)
     interface = (struct Interface *)
        malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * number));
     if (!interface) {
-       ViceLog(0, ("Failed malloc in addInterfaceAddr_r\n"));
-       osi_Panic("Failed malloc in addInterfaceAddr_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in addInterfaceAddr_r\n"));
     }
     interface->numberOfInterfaces = number + 1;
     interface->uuid = host->interface->uuid;
@@ -1755,8 +1748,7 @@ h_GetHost_r(struct rx_connection *tcon)
            ((code == 0) && (afs_uuid_equal(&interf.uuid, &nulluuid)))) {
            identP = (struct Identity *)malloc(sizeof(struct Identity));
            if (!identP) {
-               ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-               osi_Panic("Failed malloc in h_GetHost_r\n");
+               ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
            }
            identP->valid = 0;
            rx_SetSpecific(tcon, rxcon_ident_key, identP);
@@ -1797,8 +1789,7 @@ h_GetHost_r(struct rx_connection *tcon)
            interfValid = 1;
            identP = (struct Identity *)malloc(sizeof(struct Identity));
            if (!identP) {
-               ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-               osi_Panic("Failed malloc in h_GetHost_r\n");
+               ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
            }
            identP->valid = 1;
            identP->uuid = interf.uuid;
@@ -1986,8 +1977,7 @@ h_GetHost_r(struct rx_connection *tcon)
                    pident = 1;
 
                if (!identP) {
-                   ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-                   osi_Panic("Failed malloc in h_GetHost_r\n");
+                   ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
                }
                identP->valid = 0;
                if (!pident)
@@ -2005,8 +1995,7 @@ h_GetHost_r(struct rx_connection *tcon)
                    pident = 1;
 
                if (!identP) {
-                   ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-                   osi_Panic("Failed malloc in h_GetHost_r\n");
+                   ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
                }
                identP->valid = 1;
                interfValid = 1;
@@ -2270,8 +2259,7 @@ MapName_r(char *aname, char *acell, afs_int32 * aval)
            foreign = 1;        /* attempt cross-cell authentication */
            tname = (char *)malloc(PR_MAXNAMELEN);
            if (!tname) {
-               ViceLog(0, ("Failed malloc in MapName_r\n"));
-               osi_Panic("Failed malloc in MapName_r\n");
+               ViceLogThenPanic(0, ("Failed malloc in MapName_r\n"));
            }
            strcpy(tname, aname);
            tname[anamelen] = '@';
@@ -2671,6 +2659,14 @@ GetClient(struct rx_connection *tcon, struct client **cp)
        H_UNLOCK;
        return VICETOKENDEAD;
     }
+    if (client->deleted) {
+       ViceLog(0, ("GetClient: got deleted client, this should not happen! "
+                   "Connection will appear to have no rights; "
+                   "tcon %p sid %d epoch %d client %p host %s:%d viceid %d\n",
+                   tcon, (int)rxr_CidOf(tcon), (int)rxr_GetEpoch(tcon), client,
+                   afs_inet_ntoa_r(client->host->host, hoststr),
+                   (int)ntohs(client->host->port), (int)client->ViceId));
+    }
 
     client->refCount++;
     *cp = client;
@@ -2703,8 +2699,7 @@ h_UserName(struct client *client)
     lids.idlist_len = 1;
     lids.idlist_val = (afs_int32 *) malloc(1 * sizeof(afs_int32));
     if (!lids.idlist_val) {
-       ViceLog(0, ("Failed malloc in h_UserName\n"));
-       osi_Panic("Failed malloc in h_UserName\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_UserName\n"));
     }
     lnames.namelist_len = 0;
     lnames.namelist_val = (prname *) 0;
@@ -2732,7 +2727,7 @@ h_PrintStats(void)
 
 
 static int
-h_PrintClient(struct host *host, int flags, void *rock)
+h_PrintClient(struct host *host, void *rock)
 {
     StreamHandle_t *file = (StreamHandle_t *)rock;
     struct client *client;
@@ -2741,41 +2736,40 @@ h_PrintClient(struct host *host, int flags, void *rock)
     char tbuffer[32];
     char hoststr[16];
     time_t LastCall, expTime;
+    struct tm tm;
 
     H_LOCK;
     LastCall = host->LastCall;
     if (host->hostFlags & HOSTDELETED) {
        H_UNLOCK;
-       return flags;
-    }
-    (void)afs_snprintf(tmpStr, sizeof tmpStr,
-                      "Host %s:%d down = %d, LastCall %s",
-                      afs_inet_ntoa_r(host->host, hoststr),
-                      ntohs(host->port), (host->hostFlags & VENUSDOWN),
-                      afs_ctime(&LastCall, tbuffer,
-                                sizeof(tbuffer)));
+       return 0;
+    }
+    strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+            localtime_r(&LastCall, &tm));
+    snprintf(tmpStr, sizeof tmpStr, "Host %s:%d down = %d, LastCall %s\n",
+            afs_inet_ntoa_r(host->host, hoststr),
+            ntohs(host->port), (host->hostFlags & VENUSDOWN),
+            tbuffer);
     (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
     for (client = host->FirstClient; client; client = client->next) {
        if (!client->deleted) {
-               expTime = client->expTime;
-               (void)afs_snprintf(tmpStr, sizeof tmpStr,
-                                  "    user id=%d,  name=%s, sl=%s till %s",
-                                  client->ViceId, h_UserName(client),
-                                  client->
-                                  authClass ? "Authenticated" :
-                                  "Not authenticated",
-                                  client->
-                                  authClass ? afs_ctime(&expTime, tbuffer,
-                                                        sizeof(tbuffer))
-                                  : "No Limit\n");
-               (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
-           (void)afs_snprintf(tmpStr, sizeof tmpStr, "      CPS-%d is [",
-                              client->CPS.prlist_len);
+           expTime = client->expTime;
+           strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+                    localtime_r(&expTime, &tm));
+           snprintf(tmpStr, sizeof tmpStr,
+                    "    user id=%d,  name=%s, sl=%s till %s\n",
+                    client->ViceId, h_UserName(client),
+                    client->authClass ? "Authenticated"
+                                      : "Not authenticated",
+                    client->authClass ? tbuffer : "No Limit");
+           (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
+           snprintf(tmpStr, sizeof tmpStr, "      CPS-%d is [",
+                        client->CPS.prlist_len);
            (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
            if (client->CPS.prlist_val) {
-               for (i = 0; i > client->CPS.prlist_len; i++) {
-                   (void)afs_snprintf(tmpStr, sizeof tmpStr, " %d",
-                                      client->CPS.prlist_val[i]);
+               for (i = 0; i < client->CPS.prlist_len; i++) {
+                   snprintf(tmpStr, sizeof tmpStr, " %d",
+                            client->CPS.prlist_val[i]);
                    (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
                }
            }
@@ -2784,7 +2778,7 @@ h_PrintClient(struct host *host, int flags, void *rock)
        }
     }
     H_UNLOCK;
-    return flags;
+    return 0;
 
 }                              /*h_PrintClient */
 
@@ -2800,6 +2794,7 @@ h_PrintClients(void)
     time_t now;
     char tmpStr[256];
     char tbuffer[32];
+    struct tm tm;
 
     StreamHandle_t *file = STREAM_OPEN(AFSDIR_SERVER_CLNTDUMP_FILEPATH, "w");
 
@@ -2810,8 +2805,10 @@ h_PrintClients(void)
        return;
     }
     now = FT_ApproxTime();
-    (void)afs_snprintf(tmpStr, sizeof tmpStr, "List of active users at %s\n",
-                      afs_ctime(&now, tbuffer, sizeof(tbuffer)));
+    strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+            localtime_r(&now, &tm));
+    snprintf(tmpStr, sizeof tmpStr, "List of active users at %s\n\n",
+            tbuffer);
     (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
     h_Enumerate(h_PrintClient, (char *)file);
     STREAM_REALLYCLOSE(file);
@@ -2822,7 +2819,7 @@ h_PrintClients(void)
 
 
 static int
-h_DumpHost(struct host *host, int flags, void *rock)
+h_DumpHost(struct host *host, void *rock)
 {
     StreamHandle_t *file = (StreamHandle_t *)rock;
 
@@ -2831,19 +2828,20 @@ h_DumpHost(struct host *host, int flags, void *rock)
     char hoststr[16];
 
     H_LOCK;
-    (void)afs_snprintf(tmpStr, sizeof tmpStr,
-                      "ip:%s port:%d hidx:%d cbid:%d lock:%x last:%u active:%u down:%d del:%d cons:%d cldel:%d\n\t hpfailed:%d hcpsCall:%u hcps [",
-                      afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), host->index,
-                      host->cblist, CheckLock(&host->lock), host->LastCall,
-                      host->ActiveCall, (host->hostFlags & VENUSDOWN),
-                      host->hostFlags & HOSTDELETED, host->Console,
-                      host->hostFlags & CLIENTDELETED, host->hcpsfailed,
-                      host->cpsCall);
+    snprintf(tmpStr, sizeof tmpStr,
+            "ip:%s port:%d hidx:%d cbid:%d lock:%x last:%u active:%u "
+            "down:%d del:%d cons:%d cldel:%d\n\t hpfailed:%d hcpsCall:%u "
+            "hcps [",
+            afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
+            host->index, host->cblist, CheckLock(&host->lock),
+            host->LastCall, host->ActiveCall, (host->hostFlags & VENUSDOWN),
+            host->hostFlags & HOSTDELETED, host->Console,
+            host->hostFlags & CLIENTDELETED, host->hcpsfailed,
+            host->cpsCall);
     (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
     if (host->hcps.prlist_val)
        for (i = 0; i < host->hcps.prlist_len; i++) {
-           (void)afs_snprintf(tmpStr, sizeof tmpStr, " %d",
-                              host->hcps.prlist_val[i]);
+           snprintf(tmpStr, sizeof tmpStr, " %d", host->hcps.prlist_val[i]);
            (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
        }
     sprintf(tmpStr, "] [");
@@ -2860,7 +2858,7 @@ h_DumpHost(struct host *host, int flags, void *rock)
     (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
 
     H_UNLOCK;
-    return flags;
+    return 0;
 
 }                              /*h_DumpHost */
 
@@ -2872,6 +2870,7 @@ h_DumpHosts(void)
     StreamHandle_t *file = STREAM_OPEN(AFSDIR_SERVER_HOSTDUMP_FILEPATH, "w");
     char tmpStr[256];
     char tbuffer[32];
+    struct tm tm;
 
     if (file == NULL) {
        ViceLog(0,
@@ -2880,8 +2879,9 @@ h_DumpHosts(void)
        return;
     }
     now = FT_ApproxTime();
-    (void)afs_snprintf(tmpStr, sizeof tmpStr, "List of active hosts at %s\n",
-                      afs_ctime(&now, tbuffer, sizeof(tbuffer)));
+    strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+            localtime_r(&now, &tm));
+    snprintf(tmpStr, sizeof tmpStr, "List of active hosts at %s\n\n", tbuffer);
     (void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
     h_Enumerate(h_DumpHost, (char *)file);
     STREAM_REALLYCLOSE(file);
@@ -2897,10 +2897,10 @@ h_DumpHosts(void)
 static int h_stateFillHeader(struct host_state_header * hdr);
 static int h_stateCheckHeader(struct host_state_header * hdr);
 static int h_stateAllocMap(struct fs_dump_state * state);
-static int h_stateSaveHost(struct host * host, int flags, void *rock);
+static int h_stateSaveHost(struct host * host, void *rock);
 static int h_stateRestoreHost(struct fs_dump_state * state);
-static int h_stateRestoreIndex(struct host * h, int flags, void *rock);
-static int h_stateVerifyHost(struct host * h, int flags, void *rock);
+static int h_stateRestoreIndex(struct host * h, void *rock);
+static int h_stateVerifyHost(struct host * h, void *rock);
 static int h_stateVerifyAddrHash(struct fs_dump_state * state, struct host * h,
                                  afs_uint32 addr, afs_uint16 port, int valid);
 static int h_stateVerifyUuidHash(struct fs_dump_state * state, struct host * h);
@@ -2993,13 +2993,13 @@ h_stateRestoreIndices(struct fs_dump_state * state)
 }
 
 static int
-h_stateRestoreIndex(struct host * h, int flags, void *rock)
+h_stateRestoreIndex(struct host * h, void *rock)
 {
     struct fs_dump_state *state = (struct fs_dump_state *)rock;
     if (cb_OldToNew(state, h->cblist, &h->cblist)) {
-       return H_ENUMERATE_BAIL(flags);
+       return H_ENUMERATE_BAIL(0);
     }
-    return flags;
+    return 0;
 }
 
 int
@@ -3010,14 +3010,14 @@ h_stateVerify(struct fs_dump_state * state)
 }
 
 static int
-h_stateVerifyHost(struct host * h, int flags, void* rock)
+h_stateVerifyHost(struct host * h, void* rock)
 {
     struct fs_dump_state *state = (struct fs_dump_state *)rock;
     int i;
 
     if (h == NULL) {
        ViceLog(0, ("h_stateVerifyHost: error: NULL host pointer in linked list\n"));
-       return H_ENUMERATE_BAIL(flags);
+       return H_ENUMERATE_BAIL(0);
     }
 
     if (h->interface) {
@@ -3039,7 +3039,7 @@ h_stateVerifyHost(struct host * h, int flags, void* rock)
        state->bail = 1;
     }
 
-    return flags;
+    return 0;
 }
 
 /**
@@ -3217,7 +3217,7 @@ h_stateAllocMap(struct fs_dump_state * state)
 
 /* function called by h_Enumerate to save a host to disk */
 static int
-h_stateSaveHost(struct host * host, int flags, void* rock)
+h_stateSaveHost(struct host * host, void* rock)
 {
     struct fs_dump_state *state = (struct fs_dump_state *) rock;
     int if_len=0, hcps_len=0;
@@ -3283,9 +3283,9 @@ h_stateSaveHost(struct host * host, int flags, void* rock)
     if (hcps)
        free(hcps);
     if (state->bail) {
-       return H_ENUMERATE_BAIL(flags);
+       return H_ENUMERATE_BAIL(0);
     }
-    return flags;
+    return 0;
 }
 
 /* restores a host from disk */
@@ -3810,7 +3810,7 @@ CheckHost(struct host *host, int flags, void *rock)
 #endif
 
 int
-CheckHost_r(struct host *host, int flags, void *dummy)
+CheckHost_r(struct host *host, void *dummy)
 {
     struct client *client;
     struct rx_connection *cb_conn = NULL;
@@ -3821,7 +3821,7 @@ CheckHost_r(struct host *host, int flags, void *dummy)
     FS_STATE_RDLOCK;
     if (fs_state.mode == FS_MODE_SHUTDOWN) {
        FS_STATE_UNLOCK;
-       return H_ENUMERATE_BAIL(flags);
+       return H_ENUMERATE_BAIL(0);
     }
     FS_STATE_UNLOCK;
 #endif
@@ -3836,6 +3836,7 @@ CheckHost_r(struct host *host, int flags, void *dummy)
     if (host->LastCall < checktime) {
        h_Lock_r(host);
        if (!(host->hostFlags & HOSTDELETED)) {
+           host->hostFlags |= HWHO_INPROGRESS;
            cb_conn = host->callback_rxcon;
            rx_GetConnection(cb_conn);
            if (host->LastCall < clientdeletetime) {
@@ -3903,10 +3904,11 @@ CheckHost_r(struct host *host, int flags, void *dummy)
            rx_PutConnection(cb_conn);
            cb_conn=NULL;
            H_LOCK;
+           host->hostFlags &= ~HWHO_INPROGRESS;
        }
        h_Unlock_r(host);
     }
-    return flags;
+    return 0;
 
 }                              /*CheckHost_r */
 
@@ -4034,16 +4036,14 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf)
            malloc(sizeof(struct Interface) +
                   (sizeof(struct AddrPort) * (count - 1)));
        if (!interface) {
-           ViceLog(0, ("Failed malloc in initInterfaceAddr_r 1\n"));
-           osi_Panic("Failed malloc in initInterfaceAddr_r 1\n");
+           ViceLogThenPanic(0, ("Failed malloc in initInterfaceAddr_r 1\n"));
        }
        interface->numberOfInterfaces = count;
     } else {
        interface = (struct Interface *)
            malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * count));
        if (!interface) {
-           ViceLog(0, ("Failed malloc in initInterfaceAddr_r 2\n"));
-           osi_Panic("Failed malloc in initInterfaceAddr_r 2\n");
+           ViceLogThenPanic(0, ("Failed malloc in initInterfaceAddr_r 2\n"));
        }
        interface->numberOfInterfaces = count + 1;
        interface->interface[count].addr = myAddr;