]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ipc/ipcdev.git/blobdiff - qnx/src/ipc3x_dev/ti/syslink/utils/hlos/knl/NameServer_daemon.c
QNX: NameServer_delete in NameServer daemon leaks memory
[ipc/ipcdev.git] / qnx / src / ipc3x_dev / ti / syslink / utils / hlos / knl / NameServer_daemon.c
index c9db723b2b95791cfdfa62b6a32115a8d835a851..5fb5d6f891859c13ca30d8f284158a993802bc19 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013, Texas Instruments Incorporated
+ * Copyright (c) 2012-2015, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 /* Internal stuff: */
 #include <_MessageQCopy.h>
 #include <_NameServer.h>
-#include <_NameServerRemoteRpmsg.h>
-#include <_IpcLog.h>
-
-/* TI Ipc utils: */
-#include <TiIpcFxns.h>
-
-#include "ti/ipc/ti_ipc.h"
+#include <_NameServer_daemon.h>
+#include <ti/ipc/namesrv/_NameServerRemoteRpmsg.h>
+#include <ti/syslink/utils/Trace.h>
 
 #define MESSAGEQ_RPMSG_PORT       61
 #define NAME_SERVER_RPMSG_ADDR    0
@@ -122,28 +118,23 @@ struct NameServer_Object {
 /* structure for NameServer module state */
 typedef struct NameServer_ModuleObject {
     CIRCLEQ_HEAD(dummy1, NameServer_Object) objList;
-    Int32               refCount;
-    MessageQCopy_Handle mq;
+    Int32                refCount;
+    MessageQCopy_Handle  mq;
     /* MessageQCopy instance to receive from remote proc nameserver ports: */
-    UInt32              recvAddr;
+    UInt32               recvAddr;
     /* Local endpoint for receiving from remote proc nameserver ports: */
-    pthread_t           listener;
+    pthread_t            listener;
     /* Listener thread for NameServer replies and requests. */
-    int                 waitFdW;
-    int                 waitFdR;
+    int                  waitFdW;
+    int                  waitFdR;
     /* Pipe to post to NameServer_get. */
-    NameServerMsg       nsMsg;
+    NameServerRemote_Msg nsMsg;
     /* NameServer Message cache. */
-    NameServer_Params   defInstParams;
+    NameServer_Params    defInstParams;
     /* Default instance paramters */
-    pthread_mutex_t     modGate;
+    pthread_mutex_t      modGate;
 } NameServer_ModuleObject;
 
-#define CIRCLEQ_destruct(head) { \
-        (head)->cqh_first = NULL; \
-        (head)->cqh_last = NULL; \
-}
-
 #define CIRCLEQ_elemClear(elem) { \
         (elem)->cqe_next = (elem)->cqe_prev = (Void *)(elem); \
 }
@@ -234,17 +225,17 @@ static UInt32 stringHash(String s)
     return (hash);
 }
 
-static void NameServerRemote_processMessage(NameServerMsg * msg, UInt16 procId)
+static void NameServerRemote_processMessage(NameServerRemote_Msg * msg, UInt16 procId)
 {
     NameServer_Handle handle;
     Int               status = NameServer_E_FAIL;
     char              buf = 'n';
-    int               numBytes;
     int               waitFd = NameServer_module->waitFdW;
 
     if (msg->request == NAMESERVER_REQUEST) {
-        LOG2("NameServer Request: instanceName: %s, name: %s\n",
-             (String)msg->instanceName, (String)msg->name)
+        GT_2trace(curTrace, GT_1CLASS, "NameServer Request: "
+                  "instanceName: %s, name: %s",
+                  (String)msg->instanceName, (String)msg->name);
 
         assert(msg->valueLen <= MAXVALUELEN);
 
@@ -257,75 +248,96 @@ static void NameServerRemote_processMessage(NameServerMsg * msg, UInt16 procId)
         if (handle != NULL) {
             /* Search for the NameServer entry */
             if (msg->valueLen <= sizeof (Bits32)) {
-                LOG0("Calling NameServer_getLocalUInt32...\n")
+                GT_0trace(curTrace, GT_1CLASS, "Calling NameServer_getLocalUInt32...");
                 status = NameServer_getLocalUInt32(handle,
                      (String)msg->name, &msg->value);
             }
             else {
-                LOG0("Calling NameServer_getLocal...\n")
+                GT_0trace(curTrace, GT_1CLASS, "Calling NameServer_getLocal...");
                 status = NameServer_getLocal(handle,
                      (String)msg->name, (Ptr)msg->valueBuf, &msg->valueLen);
             }
         }
 
-        LOG2("NameServer Response: instanceName: %s, name: %s,",
-             (String)msg->instanceName, (String)msg->name)
+        GT_2trace(curTrace, GT_1CLASS,
+             "NameServer Response: instanceName: %s, name: %s,",
+             (String)msg->instanceName, (String)msg->name);
         /* set the request status */
         if (status < 0) {
-            LOG1(" Value not found, status: %d\n", status)
+            GT_1trace(curTrace, GT_1CLASS, " Value not found, status: %d",
+                      status);
             msg->requestStatus = 0;
         }
         else {
             msg->requestStatus = 1;
-            LOG1(" Value: 0x%x\n", msg->value)
+            GT_1trace(curTrace, GT_1CLASS, " Value: 0x%x", msg->value);
         }
 
         /* specify message as a response */
         msg->request = NAMESERVER_RESPONSE;
         msg->reserved = NAMESERVER_MSG_TOKEN;
 
-        /* send response message to remote processor */
-        status = MessageQCopy_send(procId, MultiProc_self(),
-            MESSAGEQ_RPMSG_PORT, RPMSG_RESERVED_ADDRESSES, msg,
-            sizeof(NameServerMsg), TRUE);
-        if (status < 0) {
-            LOG0("NameServer: MessageQCopy_send failed\n")
+        pthread_mutex_lock(&NameServer_module->modGate);
+
+        /*
+         * Check if MessageQCopy object is valid. If not, we received a request
+         * but we are not able to respond to it due to recovery.
+         * We will simply drop the request.
+         */
+        if (NameServer_module->mq == NULL) {
+            GT_0trace(curTrace, GT_3CLASS,
+                      "NameServerRemote_processMessage: MessageQCopy not ready."
+                      " Request dropped.");
+        }
+        else {
+            /* send response message to remote processor */
+            status = MessageQCopy_send(procId, MultiProc_self(),
+                MESSAGEQ_RPMSG_PORT, RPMSG_RESERVED_ADDRESSES, msg,
+                sizeof(NameServerRemote_Msg), TRUE);
+            if (status < 0) {
+                GT_setFailureReason(curTrace, GT_4CLASS,
+                                    "NameServerRemote_processMessage",
+                                    status, "MessageQCopy_send failed");
+            }
         }
+
+        pthread_mutex_unlock(&NameServer_module->modGate);
     }
     else {
-        LOG2("NameServer Reply: instanceName: %s, name: %s",
-             (String)msg->instanceName, (String)msg->name)
-        LOG1(", value: 0x%x\n", msg->value)
+        GT_3trace(curTrace, GT_1CLASS, "NameServer Reply: instanceName: %s, "
+             "name: %s, value: 0x%x", (String)msg->instanceName,
+             (String)msg->name, msg->value);
 
         /* Save the response message.  */
-        memcpy(&NameServer_module->nsMsg, msg, sizeof(NameServerMsg));
+        memcpy(&NameServer_module->nsMsg, msg, sizeof(NameServerRemote_Msg));
 
         /* Post the eventfd upon which NameServer_get() is waiting */
-        numBytes = write(waitFd, &buf, sizeof(buf));
+        write(waitFd, &buf, sizeof(buf));
     }
 }
 
 static Void _listener_cb(MessageQCopy_Handle handle, void * data, int len,
     void * priv, UInt32 src, UInt16 srcProc)
 {
-    NameServerMsg msg;
+    NameServerRemote_Msg msg;
 
-    LOG0("listener_cb: Entered Listener thread.\n")
+    GT_6trace(curTrace, GT_ENTER, "_listener_cb", handle, data, len, priv, src, srcProc);
 
-    LOG1("NameServer: Listener got NameServer message "
+    GT_1trace(curTrace, GT_1CLASS, "NameServer: Listener got NameServer message "
          "from MessageQCopy: 0x%p!\n", handle);
     /* Get NameServer message and process: */
     memcpy(&msg, data, len);
 
-    if (len != sizeof(NameServerMsg)) {
-        LOG1("NameServer: got bad NameServerMsg len (%d)\n",
-            len)
+    if (len != sizeof(NameServerRemote_Msg)) {
+        GT_1trace(curTrace, GT_4CLASS, "NameServer: got bad "
+                  "NameServerRemote_Msg len (%d)\n", len);
     }
     else {
-        LOG1("listener_cb: read from MessageQCopy 0x%p\n", handle)
-        LOG2("\tReceived ns msg: byte count: %d, from addr: %d, ",
-             len, src)
-        LOG1("from vproc: %d\n", srcProc)
+        GT_1trace(curTrace, GT_1CLASS, "listener_cb: "
+                  "read from MessageQCopy 0x%p", handle);
+        GT_3trace(curTrace, GT_1CLASS, "\tReceived ns msg: "
+                  "byte count: %d, from addr: %d, from vproc: %d",
+                  len, src, srcProc);
         NameServerRemote_processMessage(&msg, srcProc);
     }
 }
@@ -339,26 +351,25 @@ static Void _listener_cb(MessageQCopy_Handle handle, void * data, int len,
 Int NameServer_setup(Void)
 {
     Int    status = NameServer_S_SUCCESS;
-    UInt16 numProcs;
     int    fd[2];
 
     pthread_mutex_lock(&NameServer_module->modGate);
 
-    LOG1("NameServer_setup: entered, refCount=%d\n", NameServer_module->refCount)
+    GT_1trace(curTrace, GT_ENTER, "NameServer_setup: refCount",
+              NameServer_module->refCount);
 
     NameServer_module->refCount++;
 
     if (NameServer_module->refCount > 1) {
-        LOG0("NameServer_setup: already setup\n")
+        GT_0trace(curTrace, GT_1CLASS, "NameServer_setup: already setup");
         status = NameServer_S_ALREADYSETUP;
         goto exit;
     }
 
-    numProcs = MultiProc_getNumProcessors();
-
     if (pipe(fd) == -1) {
         status = NameServer_E_FAIL;
-        LOG0("NameServer_setup: failed to create waitFd.\n")
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_setup", status,
+                            "failed to create waitFd.");
         goto exit;
     }
     NameServer_module->waitFdW = fd[1];
@@ -370,7 +381,8 @@ Int NameServer_setup(Void)
 
     if (NameServer_module->mq == NULL) {
         status = NameServer_E_FAIL;
-        LOG0("NameServer_setup: failed to create MessageQCopy instance.\n")
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_setup", status,
+                            "failed to create MessageQCopy instance.");
         goto exit;
     }
 
@@ -378,8 +390,8 @@ Int NameServer_setup(Void)
     CIRCLEQ_INIT(&NameServer_module->objList);
 
 exit:
-    LOG1("NameServer_setup: exiting, refCount=%d\n", \
-        NameServer_module->refCount)
+    GT_1trace(curTrace, GT_LEAVE, "NameServer_setup: refCount",
+              NameServer_module->refCount);
 
     pthread_mutex_unlock(&NameServer_module->modGate);
 
@@ -393,12 +405,15 @@ Int NameServer_destroy(void)
 
     pthread_mutex_lock(&NameServer_module->modGate);
 
-    LOG1("NameServer_destroy: entered, refCount=%d\n", NameServer_module->refCount)
+    GT_1trace(curTrace, GT_ENTER, "NameServer_destroy: refCount",
+              NameServer_module->refCount);
 
     NameServer_module->refCount--;
 
     if (NameServer_module->refCount > 0) {
-        LOG1("NameServer_destroy(): refCount(%d) > 0, exiting\n", NameServer_module->refCount)
+        GT_1trace(curTrace, GT_1CLASS,
+                  "NameServer_destroy(): refCount(%d) > 0, exiting",
+                  NameServer_module->refCount);
         status = NameServer_S_SUCCESS;
 
         goto exit;
@@ -409,13 +424,14 @@ Int NameServer_destroy(void)
         MessageQCopy_delete(&NameServer_module->mq);
     }
 
-    CIRCLEQ_destruct(&NameServer_module->objList);
+    /* TODO: delete any remaining instances */
 
     close(NameServer_module->waitFdW);
     close(NameServer_module->waitFdR);
 
 exit:
-    LOG1("NameServer_destroy: exiting, refCount=%d\n", NameServer_module->refCount)
+    GT_1trace(curTrace, GT_LEAVE, "NameServer_destroy: refCount",
+              NameServer_module->refCount);
 
     pthread_mutex_unlock(&NameServer_module->modGate);
 
@@ -464,7 +480,7 @@ NameServer_Handle NameServer_create(String name,
     assert(name != NULL);
     assert(NameServer_module->refCount != 0);
 
-    LOG1("NameServer_create(): '%s'\n", name)
+    GT_1trace(curTrace, GT_1CLASS, "NameServer_create(): '%s'\n", name);
 
     pthread_mutex_lock(&NameServer_module->modGate);
 
@@ -476,7 +492,8 @@ NameServer_Handle NameServer_create(String name,
             handle->refCount++;
         }
         else {
-            LOG0("NameServer_create: NameServer params mismatch\n")
+            GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_create",
+                                NameServer_E_FAIL, "NameServer params mismatch");
             handle = NULL;
         }
         goto leave;
@@ -486,14 +503,16 @@ NameServer_Handle NameServer_create(String name,
     }
 
     if (!handle) {
-        LOG0("NameServer_create: NameServer_Handle alloc failed\n")
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_create",
+                            NameServer_E_FAIL, "NameServer_Handle alloc failed");
         goto leave;
     }
 
     handle->refCount = 1;
     handle->name = (String)malloc(strlen(name) + 1u);
     if (!handle->name) {
-        LOG0("NameServer_create: instance name alloc failed\n")
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_create",
+                            NameServer_E_FAIL, "instance name alloc failed");
         goto cleanup;
     }
     strncpy(handle->name, name, strlen (name) + 1u);
@@ -535,36 +554,50 @@ leave:
 }
 
 
-/* Function to delete a name server. */
-Int NameServer_delete(NameServer_Handle * handle)
+/*
+ *  ======== NameServer_delete ========
+ *  Delete a name server instance
+ */
+Int NameServer_delete(NameServer_Handle *handle)
 {
     Int status = NameServer_S_SUCCESS;
+    struct NameServer_Object *obj;
 
     assert(handle != NULL);
     assert(*handle != NULL);
-    assert((*handle)->count == 0);
     assert(NameServer_module->refCount != 0);
 
+    obj = *(struct NameServer_Object **)handle;
+
     pthread_mutex_lock(&NameServer_module->modGate);
 
-    (*handle)->refCount--;
-    if ((*handle)->refCount != 0) {
+    obj->refCount--;
+    if (obj->refCount != 0) {
         goto leave;
     }
 
-    if ((*handle)->count == 0) {
-        CIRCLEQ_REMOVE(&NameServer_module->objList, *handle, elem);
+    /* delete each entry on the name list */
+    while (obj->nameList.cqh_first != (void *)&obj->nameList) {
+        NameServer_removeEntry(*handle, (Ptr)(obj->nameList.cqh_first));
+    }
 
-        if ((*handle)->name != NULL) {
-            free((*handle)->name);
-            (*handle)->name = NULL;
-        }
+    /* free the instance name */
+    if (obj->name != NULL) {
+        free(obj->name);
+        obj->name = NULL;
+    }
 
-        CIRCLEQ_destruct(&(*handle)->nameList);
+    /* destroy the mutex */
+    pthread_mutex_destroy(&obj->gate);
 
-        free((*handle));
-        (*handle) = NULL;
-    }
+    /* remove from objList */
+    CIRCLEQ_REMOVE(&NameServer_module->objList, obj, elem);
+
+    /* finally, free the instance object */
+    free(obj);
+
+    /* set the caller's handle to null */
+    (*handle) = NULL;
 
 leave:
     pthread_mutex_unlock(&NameServer_module->modGate);
@@ -590,14 +623,23 @@ Ptr NameServer_add(NameServer_Handle handle, String name, Ptr buf, UInt len)
     /* Calculate the hash */
     hash = stringHash(name);
 
-    if (len > handle->params.maxValueLen) {
+    pthread_mutex_lock(&handle->gate);
+
+    if (strlen(name) > handle->params.maxNameLen - 1) {
         status = NameServer_E_INVALIDARG;
-        LOG0("NameServer_add: value length exceeded maximum!\n")
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status,
+                            "name length exceeded maximum!");
         new_node = NULL;
         goto exit;
     }
 
-    pthread_mutex_lock(&handle->gate);
+    if (len > handle->params.maxValueLen) {
+        status = NameServer_E_INVALIDARG;
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status,
+                            "value length exceeded maximum!");
+        new_node = NULL;
+        goto exit;
+    }
 
     /* Traverse the list to find duplicate check */
     CIRCLEQ_traverse(node, &handle->nameList, NameServer_TableEntry_tag) {
@@ -607,7 +649,8 @@ Ptr NameServer_add(NameServer_Handle handle, String name, Ptr buf, UInt len)
             if (strcmp(node->name, name) == 0) {
                 if (handle->params.checkExisting == TRUE) {
                     status = NameServer_E_INVALIDARG;
-                    LOG1("NameServer_add: '%s' - duplicate entry found!\n", name)
+                    GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status, "duplicate entry found!");
+                    GT_1trace(curTrace, GT_3CLASS, "\t'%s' - duplicate entry found!", name);
                     break;
                 }
             }
@@ -627,7 +670,8 @@ Ptr NameServer_add(NameServer_Handle handle, String name, Ptr buf, UInt len)
     new_node = (NameServer_TableEntry *)malloc(sizeof(NameServer_TableEntry));
     if (new_node == NULL) {
         status = NameServer_E_MEMORY;
-        LOG1("NameServer_add: %d - malloc new_node failed!\n", status)
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status,
+                            "malloc new_node failed!");
 
         goto exit;
     }
@@ -655,9 +699,10 @@ Ptr NameServer_add(NameServer_Handle handle, String name, Ptr buf, UInt len)
 
     handle->count++;
 
-    LOG2("NameServer_add: Entered key: '%s', data: 0x%x\n",
-         name, *(UInt32 *)buf)
-
+    /* Only print a single byte of buf. Address may not be 32-bit aligned */
+    GT_2trace(curTrace, GT_1CLASS,
+              "NameServer_add: Entered key: '%s', data: 0x%x",
+              name, *(UInt8 *)buf);
 exit:
     pthread_mutex_unlock(&handle->gate);
 
@@ -743,7 +788,8 @@ Int NameServer_remove(NameServer_Handle handle, String name)
 
     if (done == FALSE) {
         status = NameServer_E_INVALIDARG;
-        LOG1("NameServer_remove %d Entry not found!\n", status)
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_remove", status,
+                            " Entry not found!");
     }
 
     pthread_mutex_unlock(&handle->gate);
@@ -798,13 +844,29 @@ Int NameServer_getRemote(NameServer_Handle handle,
     Int status = NameServer_S_SUCCESS;
     Int mqcStatus = -1;
     struct NameServer_Object *obj = (struct NameServer_Object *)(handle);
-    NameServerMsg nsMsg;
-    NameServerMsg *replyMsg;
+    NameServerRemote_Msg nsMsg;
+    NameServerRemote_Msg *replyMsg;
     fd_set rfds;
     int ret = 0, maxfd, waitFd;
     struct timeval tv;
     char buf = '1';
     int numBytes;
+    static int seqNum = 0;
+    Bool done = FALSE;
+
+    if (strlen(name) >= MAXNAMEINCHAR) {
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+                            NameServer_E_NAMETOOLONG,
+                            "Name is too long in remote query");
+        return NameServer_E_NAMETOOLONG;
+    }
+
+    if (strlen(obj->name) >= MAXNAMEINCHAR) {
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+                            NameServer_E_NAMETOOLONG,
+                            "Instance name is too long for remote query");
+        return NameServer_E_NAMETOOLONG;
+    }
 
     pthread_mutex_lock(&NameServer_module->modGate);
 
@@ -817,82 +879,114 @@ Int NameServer_getRemote(NameServer_Handle handle,
     nsMsg.request = NAMESERVER_REQUEST;
     nsMsg.requestStatus = 0;
     nsMsg.valueLen = *len;
+    nsMsg.seqNum = seqNum++;
 
     strncpy((char *)nsMsg.instanceName, obj->name, strlen(obj->name) + 1);
     strncpy((char *)nsMsg.name, name, strlen(name) + 1);
 
-    LOG2("NameServer_getRemote: Requesting from procId %d, %s:",
-           procId, (String)nsMsg.instanceName)
-    LOG1("%s...\n", (String)nsMsg.name)
+    GT_3trace(curTrace, GT_1CLASS,
+              "NameServer_getRemote: Requesting from procId %d, %s:%s...",
+              procId, (String)nsMsg.instanceName, (String)nsMsg.name);
+
+    /*
+     * Check if MessageQCopy object is valid. Technically we don't need it
+     * to send, but it is an indication of whether recovery is in process
+     */
+    if (NameServer_module->mq == NULL) {
+        status = NameServer_E_NOTFOUND;
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+                            status, "MessageQCopy not ready");
+        goto exit;
+    }
+
     /* send message */
     mqcStatus = MessageQCopy_send(procId, MultiProc_self(), MESSAGEQ_RPMSG_PORT,
-            RPMSG_RESERVED_ADDRESSES, &nsMsg, sizeof(NameServerMsg),
-        TRUE);
+            RPMSG_RESERVED_ADDRESSES, &nsMsg, sizeof(NameServerRemote_Msg),
+            TRUE);
     if (mqcStatus < 0) {
-        LOG0("NameServer_getRemote: Can't send to remote endpoint\n")
         status = NameServer_E_NOTFOUND;
+        GT_1trace(curTrace, GT_3CLASS, "NameServer_getRemote: "
+                 "Can't send to remote endpoint on procId %d", procId);
         goto exit;
     }
 
-    /* Block on waitFd for signal from listener thread: */
-    waitFd = NameServer_module->waitFdR;
-    FD_ZERO(&rfds);
-    FD_SET(waitFd, &rfds);
-    maxfd = waitFd + 1;
-    LOG1("NameServer_getRemote: pending on waitFd: %d\n", waitFd)
-    ret = select(maxfd, &rfds, NULL, NULL, &tv);
-    if (ret == -1) {
-        LOG0("NameServer_getRemote: select failed.")
-        status = NameServer_E_FAIL;
-        goto exit;
-    }
-    else if (!ret) {
-        LOG0("NameServer_getRemote: select timed out.\n")
-        status = NameServer_E_TIMEOUT;
-        goto exit;
-    }
+    while (!done) {
+        /* Block on waitFd for signal from listener thread: */
+        waitFd = NameServer_module->waitFdR;
+        FD_ZERO(&rfds);
+        FD_SET(waitFd, &rfds);
+        maxfd = waitFd + 1;
+        GT_1trace(curTrace, GT_1CLASS, "NameServer_getRemote: pending on waitFd: %d\n", waitFd);
+        ret = select(maxfd, &rfds, NULL, NULL, &tv);
+        if (ret == -1) {
+            status = NameServer_E_FAIL;
+            GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+                                status, "select failed.");
+            goto exit;
+        }
+        else if (!ret) {
+            status = NameServer_E_TIMEOUT;
+            GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+                                status, "select timed out.");
+            goto exit;
+        }
+
+        if (FD_ISSET(waitFd, &rfds)) {
+            /* Read, just to balance the write: */
+            numBytes = read(waitFd, &buf, sizeof(buf));
+            if (numBytes == -1) {
+                status = NameServer_E_FAIL;
+                GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+                                    status, "read failure");
+                goto exit;
+            }
+
+            /* Process response: */
+            replyMsg = &NameServer_module->nsMsg;
 
-    if (FD_ISSET(waitFd, &rfds)) {
-        /* Read, just to balance the write: */
-        numBytes = read(waitFd, &buf, sizeof(buf));
+            if (replyMsg->seqNum != seqNum - 1) {
+                /* Ignore responses without current sequence # */
+                continue;
+            }
 
-        /* Process response: */
-        replyMsg = &NameServer_module->nsMsg;
+            if (replyMsg->requestStatus) {
+                /* name is found */
 
-        if (replyMsg->requestStatus) {
-            /* name is found */
+                /* set length to amount of data that was copied */
+                *len = replyMsg->valueLen;
 
-            /* set length to amount of data that was copied */
-            *len = replyMsg->valueLen;
+                /* set the contents of value */
+                if (*len <= sizeof (Bits32)) {
+                    *(UInt32 *)value = (UInt32)replyMsg->value;
+                    GT_4trace(curTrace, GT_1CLASS, "NameServer_getRemote: "
+                              "Reply from: %d, %s:%s, value: 0x%x...", procId,
+                              (String)replyMsg->instanceName,
+                              (String)replyMsg->name, *(UInt32 *)value);
+                }
+                else {
+                    memcpy(value, replyMsg->valueBuf, *len);
+                    GT_4trace(curTrace, GT_1CLASS, "NameServer_getRemote: "
+                              "Reply from: %d, %s:%s, value buffer at address:"
+                              " 0x%p...", procId,
+                              (String)replyMsg->instanceName,
+                              (String)replyMsg->name, value);
+                }
 
-            /* set the contents of value */
-            if (*len <= sizeof (Bits32)) {
-                *(UInt32 *)value = (UInt32)replyMsg->value;
-                LOG2("NameServer_getRemote: Reply from: %d, %s:",
-                    procId, (String)replyMsg->instanceName)
-                LOG2("%s, value: 0x%x...\n",
-                    (String)replyMsg->name, *(UInt32 *)value)
+                goto exit;
             }
             else {
-                memcpy(value, replyMsg->valueBuf, *len);
-                LOG2("NameServer_getRemote: Reply from: %d, %s:",
-                    procId, (String)replyMsg->instanceName)
-                LOG2("%s, value buffer at address: 0x%p...\n",
-                    (String)replyMsg->name, value)
+                /* name is not found */
+                GT_2trace(curTrace, GT_3CLASS, "NameServer_getRemote: "
+                          "value for %s:%s not found.",
+                          (String)replyMsg->instanceName,
+                          (String)replyMsg->name);
+
+                /* set status to not found */
+                status = NameServer_E_NOTFOUND;
             }
-
-            goto exit;
-        }
-        else {
-            /* name is not found */
-            LOG2("NameServer_getRemote: value for %s:%s not found.\n",
-                 (String)replyMsg->instanceName, (String)replyMsg->name)
-
-            /* set status to not found */
-            status = NameServer_E_NOTFOUND;
         }
+        done = TRUE;
     }
-
 exit:
     pthread_mutex_unlock(&NameServer_module->modGate);
 
@@ -946,7 +1040,8 @@ Int NameServer_get(NameServer_Handle handle,
             }
 
             if ((status >= 0) ||
-                ((status < 0) && (status != NameServer_E_NOTFOUND))) {
+                ((status < 0) && (status != NameServer_E_NOTFOUND)
+                && (status != NameServer_E_TIMEOUT))) {
                 break;
             }
 
@@ -1044,11 +1139,12 @@ Int NameServer_getLocal(NameServer_Handle handle,
     pthread_mutex_unlock(&handle->gate);
 
     if (done == FALSE) {
-        LOG1("NameServer_getLocal: entry key: '%s' not found!\n", name)
+        GT_1trace(curTrace, GT_1CLASS,
+                  "NameServer_getLocal: entry key: '%s' not found!", name);
     }
     else {
-        LOG2("NameServer_getLocal: Found entry key: '%s', data: 0x%x\n",
-             node->name, (UInt32)node->value)
+        GT_2trace(curTrace, GT_1CLASS, "NameServer_getLocal: Found entry key: "
+                  "'%s', data: 0x%x", node->name, (UInt32)node->value);
         status = NameServer_S_SUCCESS;
     }
 
@@ -1078,12 +1174,51 @@ Int NameServer_getLocalUInt32(NameServer_Handle handle, String name, Ptr value)
     assert(value  != NULL);
     assert(NameServer_module->refCount != 0);
 
-    LOG0("NameServer_getLocalUInt32: calling NameServer_getLocal()...\n")
+    GT_0trace(curTrace, GT_1CLASS,
+              "NameServer_getLocalUInt32: calling NameServer_getLocal()...");
     status = NameServer_getLocal(handle, name, value, &len);
 
     return (status);
 }
 
+Void NameServer_preRecovery(Void)
+{
+    Int status;
+
+    pthread_mutex_lock(&NameServer_module->modGate);
+
+    if (NameServer_module->mq != NULL) {
+        status = MessageQCopy_delete(&NameServer_module->mq);
+        if (status < 0) {
+            GT_setFailureReason(curTrace, GT_3CLASS, "NameServer_preRecovery", status,
+                                "Cannot delete MessageQCopy");
+        }
+        NameServer_module->mq = NULL;
+    }
+
+    pthread_mutex_unlock(&NameServer_module->modGate);
+}
+
+Int NameServer_postRecovery(Void)
+{
+    Int status = NameServer_S_SUCCESS;
+
+    pthread_mutex_lock(&NameServer_module->modGate);
+
+    /* Create the MessageQCopy for receiving messages from all remote proc */
+    NameServer_module->mq = MessageQCopy_create(NAME_SERVER_RPMSG_ADDR,
+        NULL, _listener_cb, NULL, &NameServer_module->recvAddr);
+
+    if (NameServer_module->mq == NULL) {
+        status = NameServer_E_FAIL;
+        GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_postRecovery", status,
+                            "failed to create MessageQCopy instance.");
+    }
+
+    pthread_mutex_unlock(&NameServer_module->modGate);
+
+    return (status);
+}
 
 #if defined (__cplusplus)
 }