From 162bd361de7b1242b0e54e55e20c9ab8eeb4d445 Mon Sep 17 00:00:00 2001
From: unknown <joreland@mysql.com>
Date: Mon, 20 Sep 2004 09:24:25 +0200
Subject: [PATCH] bug#4590 Use ndb_mgm_listen_event to wait for backup messages

ndb/src/mgmclient/CommandInterpreter.cpp:
  Listen to backup event
  start backup
  wait until event related to backup arrives
ndb/src/mgmsrv/Services.cpp:
  Fix newline at end of reply
---
 ndb/src/mgmclient/CommandInterpreter.cpp | 36 ++++++++++++++++++++++--
 ndb/src/mgmsrv/Services.cpp              |  1 +
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp
index 816a84375f1..fbb74d7c151 100644
--- a/ndb/src/mgmclient/CommandInterpreter.cpp
+++ b/ndb/src/mgmclient/CommandInterpreter.cpp
@@ -1672,13 +1672,45 @@ CommandInterpreter::executeStartBackup(char* /*parameters*/)
   connect();
   struct ndb_mgm_reply reply;
   unsigned int backupId;
+
+  int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 };
+  int fd = ndb_mgm_listen_event(m_mgmsrv, filter);
   int result = ndb_mgm_start_backup(m_mgmsrv, &backupId, &reply);
   if (result != 0) {
     ndbout << "Start of backup failed" << endl;
     printError();
-  } else {
-    ndbout << "Backup started. Backup id " << backupId << "." << endl;
+    close(fd);
+    return;
+  }
+
+  char *tmp;
+  char buf[1024];
+  {
+    SocketInputStream in(fd);
+    int count = 0;
+    do {
+      tmp = in.gets(buf, 1024);
+      if(tmp)
+      {
+	ndbout << tmp;
+	int id;
+	if(sscanf(tmp, "%*[^:]: Backup %d ", &id) == 1 && id == backupId){
+	  count++;
+	}
+      }
+    } while(count < 2);
   }
+
+  SocketInputStream in(fd, 10);
+  do {
+    tmp = in.gets(buf, 1024);
+    if(tmp && tmp[0] != 0)
+    {
+      ndbout << tmp;
+    }
+  } while(tmp && tmp[0] != 0);
+  
+  close(fd);
 }
 
 void
diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp
index f7f4da4930a..684c10dbd4d 100644
--- a/ndb/src/mgmsrv/Services.cpp
+++ b/ndb/src/mgmsrv/Services.cpp
@@ -1411,6 +1411,7 @@ MgmApiSession::listen_event(Parser<MgmApiSession>::Context & ctx,
   m_output->println("result: %d", result);
   if(result != 0)
     m_output->println("msg: %s", msg.c_str());
+  m_output->println("");
 }
 
 template class MutexVector<int>;
-- 
2.30.9