[Avida-SVN] r1982 - in branches/uml: Avida.xcodeproj source/main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Wed Aug 22 08:15:29 PDT 2007


Author: dknoester
Date: 2007-08-22 11:15:29 -0400 (Wed, 22 Aug 2007)
New Revision: 1982

Modified:
   branches/uml/Avida.xcodeproj/project.pbxproj
   branches/uml/source/main/cTaskLib.cc
Log:
Stronger error checking on coprocess.

Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj	2007-08-22 14:47:31 UTC (rev 1981)
+++ branches/uml/Avida.xcodeproj/project.pbxproj	2007-08-22 15:15:29 UTC (rev 1982)
@@ -836,7 +836,7 @@
 		DCC315CE076253A5008F7A48 /* environment.rotate */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = environment.rotate; sourceTree = "<group>"; };
 		DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
 		DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
-		DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+		DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-08-22 14:47:31 UTC (rev 1981)
+++ branches/uml/source/main/cTaskLib.cc	2007-08-22 15:15:29 UTC (rev 1982)
@@ -40,6 +40,7 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <errno.h>
 
 // Various workarounds for Visual Studio shortcomings
 #if AVIDA_PLATFORM(WINDOWS)
@@ -3019,13 +3020,20 @@
 	pipe(from_subavida);
 	
 	pid_t subavida = fork();
+  if(subavida < 0) {
+    std::cerr << "ERROR: fork failed; errno=" << errno << std::endl;
+    assert(false);
+  }
 	if(subavida == 0) {
 		//child
 		close(to_subavida[1]);
 		close(from_subavida[0]);
 		dup2(to_subavida[0], STDIN_FILENO); //oldd, newd
 		dup2(from_subavida[1], STDOUT_FILENO);
-    execl("/usr/bin/java", "java", "-cp", ".", "-jar", "./hydraulic.jar", NULL);    
+    execl("/usr/bin/java", "java", "-cp", ".", "-jar", "./hydraulic.jar", NULL);
+    // There is no return if execl succeeds.
+    std::cerr << "ERROR: execl failed; errno=" << errno << std::endl;
+    assert(false);
 	} 
 	//parent
 	close(to_subavida[0]);
@@ -3038,8 +3046,9 @@
 	// Write the model to STDIN of subavida (be careful; write may not write all that you ask!)
 	do {
 		status = write(to_subavida[1], temp.c_str()+status_total, temp.size());	
-		if (status < 0) {
-			break;
+		if(status < 0) {
+      std::cerr << "ERROR: could not write to subavida; errno=" << errno << std::endl;
+			assert(false);
 		} else {
 			 status_total += status;
 		}
@@ -3054,6 +3063,10 @@
 	char line[read_size]={0};
 	do {
 		status = read(from_subavida[0], line, read_size-1);
+    if(status < 0) { 
+      std::cerr << "ERROR: could not read from subavida; errno=" << errno << std::endl;
+      assert(false);
+    }      
 		if(status > 0) {
 			subavida_output += line;
 			memset(line, 0, read_size);




More information about the Avida-cvs mailing list