From 1e1152b740bf8cee5bf0891c8be78891c98a1a8b Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Wed, 30 Mar 2011 14:00:12 +0000
Subject: [PATCH] bug 1362: fixed ApplController -> RTCP control

---
 MAC/APL/Appl_Controller/ApplController.cc |  7 ++++---
 RTCP/IONProc/src/PLCClient.cc             | 14 +++++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/MAC/APL/Appl_Controller/ApplController.cc b/MAC/APL/Appl_Controller/ApplController.cc
index 1d3f2036f6c..48077933347 100644
--- a/MAC/APL/Appl_Controller/ApplController.cc
+++ b/MAC/APL/Appl_Controller/ApplController.cc
@@ -63,7 +63,8 @@ ApplController::ApplController(const string&	configID) :
 	itsIsRunning     (false),
 	itsStateEngine   (new StateEngine),
 	itsCurState      (StateNone),
-	itsCurACMsg		 (0)
+	itsCurACMsg		 (0),
+	itsNrOfProcs	 (0)
 {
 	LOG_TRACE_OBJ ("ApplController constructor");
 
@@ -398,8 +399,8 @@ void ApplController::createParSubsets()
 									fileName, 
 									nrProcs));
 			writeParSubset(basePS, procName, fileName);
-			// CN processes do not connect to the ApplController.
-			itsNrOfProcs -= nrProcs ? nrProcs : 1;
+			// CN processes do now connect to the ApplController.
+			//itsNrOfProcs -= nrProcs ? nrProcs : 1;
 		}
 	} // for processes
 }
diff --git a/RTCP/IONProc/src/PLCClient.cc b/RTCP/IONProc/src/PLCClient.cc
index 8f9ce121379..4060f43180b 100644
--- a/RTCP/IONProc/src/PLCClient.cc
+++ b/RTCP/IONProc/src/PLCClient.cc
@@ -174,7 +174,7 @@ template<> void FakeBlob::read<string>( Stream &s, string &str ) const {
 
   read( s, length );
 
-  cstr = new char[length];
+  cstr = new char[length+1];
 
   // make sure cstr won't leak if s.read throws
   struct D {
@@ -184,6 +184,7 @@ template<> void FakeBlob::read<string>( Stream &s, string &str ) const {
   (void)onDestruct;
 
   s.read( cstr, length );
+  cstr[length] = 0;
 
   str = cstr;
 }
@@ -266,7 +267,7 @@ PLCClient::PLCClient( Stream &s, PLCRunnable &job, const std::string &procID, un
   itsStartTime( time(0L) ),
   itsDefineCalled( false ),
   itsDone( false ),
-  itsLogPrefix( str(format("[PLC] [obs %u] ") % observationID) ),
+  itsLogPrefix( str(format("[obs %u] [PLC] ") % observationID) ),
   itsThread( 0 )
 {
   itsThread = new InterruptibleThread( this, &PLCClient::mainLoop, "[PLC] ", 65535 );
@@ -381,7 +382,14 @@ void PLCClient::mainLoop() {
     bool resultExpected = true;
     bool supported = true;
 
-    recvCmd( cmd, options );
+    try {
+      recvCmd( cmd, options );
+    } catch (SystemCallException &ex) {
+      if (itsDone)
+        LOG_INFO_STR( itsLogPrefix << "Lost connection to ApplController, but am quitting.");
+      else
+        throw;
+    }
 
     switch (cmd) {
       case PCCmdInfo:
-- 
GitLab