Index: /trunk/src/VBox/Main/ConsoleImpl-LiveMigration.cpp
===================================================================
--- /trunk/src/VBox/Main/ConsoleImpl-LiveMigration.cpp	(revision 23691)
+++ /trunk/src/VBox/Main/ConsoleImpl-LiveMigration.cpp	(revision 23692)
@@ -109,11 +109,13 @@
     void               *mpvVMCallbackTask;
     PRTTCPSERVER        mhServer;
+    PRTTIMERLR          mphTimerLR;
     int                 mRc;
 
-    MigrationStateDst(Console *pConsole, PVM pVM, IMachine *pMachine)
+    MigrationStateDst(Console *pConsole, PVM pVM, IMachine *pMachine, PRTTIMERLR phTimerLR)
         : MigrationState(pConsole, pVM, false /*fIsSource*/)
         , mpMachine(pMachine)
         , mpvVMCallbackTask(NULL)
         , mhServer(NULL)
+        , mphTimerLR(phTimerLR)
         , mRc(VINF_SUCCESS)
     {
@@ -190,24 +192,4 @@
 
 
-static int migrationTcpWriteACK(MigrationState *pState)
-{
-    int rc = RTTcpWrite(pState->mhSocket, "ACK\n", sizeof("ACK\n") - 1);
-    if (RT_FAILURE(rc))
-        LogRel(("Migration: RTTcpWrite(,ACK,) -> %Rrc\n", rc));
-    RTTcpFlush(pState->mhSocket);
-    return rc;
-}
-
-
-static int migrationTcpWriteNACK(MigrationState *pState)
-{
-    int rc = RTTcpWrite(pState->mhSocket, "NACK\n", sizeof("NACK\n") - 1);
-    if (RT_FAILURE(rc))
-        LogRel(("Migration: RTTcpWrite(,NACK,) -> %Rrc\n", rc));
-    RTTcpFlush(pState->mhSocket);
-    return rc;
-}
-
-
 /**
  * Reads an ACK or NACK.
@@ -228,6 +210,18 @@
     if (strcmp(szMsg, "ACK"))
     {
-        if (!strcmp(szMsg, "NACK"))
-            return setError(E_FAIL, pszNAckMsg ? pszNAckMsg : "NACK");
+        if (!strncmp(szMsg, "NACK=", sizeof("NACK=") - 1))
+        {
+            int32_t vrc2;
+            vrc = RTStrToInt32Full(&szMsg[sizeof("NACK=") - 1], 10, &vrc2);
+            if (vrc == VINF_SUCCESS)
+            {
+                if (pszNAckMsg)
+                {
+                    LogRel(("Migration: NACK=%Rrc (%d)\n", vrc2, vrc2));
+                    return setError(E_FAIL, pszNAckMsg);
+                }
+                return setError(E_FAIL, "NACK - %Rrc (%d)", vrc2, vrc2);
+            }
+        }
         return setError(E_FAIL, tr("Expected ACK or NACK, got '%s'"), szMsg);
     }
@@ -809,5 +803,5 @@
              * Do the job, when it returns we're done.
              */
-            MigrationStateDst State(this, pVM, pMachine);
+            MigrationStateDst State(this, pVM, pMachine, &hTimerLR);
             State.mstrPassword      = strPassword;
             State.mhServer          = hServer;
@@ -838,4 +832,26 @@
 
 
+static int migrationTcpWriteACK(MigrationStateDst *pState)
+{
+    int rc = RTTcpWrite(pState->mhSocket, "ACK\n", sizeof("ACK\n") - 1);
+    if (RT_FAILURE(rc))
+        LogRel(("Migration: RTTcpWrite(,ACK,) -> %Rrc\n", rc));
+    RTTcpFlush(pState->mhSocket);
+    return rc;
+}
+
+
+static int migrationTcpWriteNACK(MigrationStateDst *pState, int32_t rc2)
+{
+    char    szMsg[64];
+    size_t  cch = RTStrPrintf(szMsg, sizeof(szMsg), "NACK=%d\n", rc2);
+    int rc = RTTcpWrite(pState->mhSocket, szMsg, cch);
+    if (RT_FAILURE(rc))
+        LogRel(("Migration: RTTcpWrite(,%s,%zu) -> %Rrc\n", szMsg, cch, rc));
+    RTTcpFlush(pState->mhSocket);
+    return rc;
+}
+
+
 /**
  * @copydoc FNRTTCPSERVE
@@ -875,5 +891,5 @@
             else
                 LogRel(("Migration: Invalid password (off=%u)\n", off));
-            migrationTcpWriteNACK(pState);
+            migrationTcpWriteNACK(pState, VERR_AUTHENTICATION_FAILURE);
             return VINF_SUCCESS;
         }
@@ -883,5 +899,8 @@
     if (RT_FAILURE(vrc))
         return vrc;
+
     RTTcpServerShutdown(pState->mhServer);
+    RTTimerLRDestroy(*pState->mphTimerLR);
+    *pState->mphTimerLR = NIL_RTTIMERLR;
 
     /*
@@ -908,4 +927,5 @@
             {
                 LogRel(("Migration: VMR3LoadFromStream -> %Rrc\n", vrc));
+                migrationTcpWriteNACK(pState, vrc);
                 break;
             }
@@ -919,5 +939,5 @@
         else if (!strcmp(szCmd, "done"))
         {
-            migrationTcpWriteACK(pState);
+            vrc = migrationTcpWriteACK(pState);
             break;
         }
@@ -929,5 +949,7 @@
     }
 
+    pState->mRc = vrc;
     pState->mhSocket = NIL_RTSOCKET;
+    LogFlowFunc(("returns mRc=%Rrc\n", vrc));
     return VERR_TCP_SERVER_STOP;
 }
