Index: /trunk/packages/vizservers/pymolproxy/pymolproxy.c
===================================================================
--- /trunk/packages/vizservers/pymolproxy/pymolproxy.c	(revision 2418)
+++ /trunk/packages/vizservers/pymolproxy/pymolproxy.c	(revision 2419)
@@ -107,18 +107,19 @@
 
 typedef struct Image {
-    struct Image *nextPtr;	/* Next image in chain of images. The list is
-				 * ordered by the most recently received image
-				 * from the pymol server to the least. */
-    struct Image *prevPtr;	/* Previous image in chain of images. The list
-				 * is ordered by the most recently received
-				 * image from the pymol server to the
-				 * least. */
-    ssize_t nWritten;		/* Number of bytes of image data already
-				 * delivered.*/
-    size_t bytesLeft;		/* Number of bytes of image data left to
-				 * delivered to the client. */
-    char data[1];		/* Start of image data. We allocate the size
-				 * of the Image structure plus the size of the
-				 * image data. */
+    struct Image *nextPtr;		/* Next image in chain of images. The
+					 * list is ordered by the most
+					 * recently received image from the
+					 * pymol server to the least. */
+    struct Image *prevPtr;		/* Previous image in chain of
+					 * images. The list is ordered by the
+					 * most recently received image from
+					 * the pymol server to the least. */
+    ssize_t nWritten;			/* Number of bytes of image data
+					 * already delivered.*/
+    size_t bytesLeft;			/* Number of bytes of image data left
+					 * to delivered to the client. */
+    char data[1];			/* Start of image data. We allocate
+					 * the size of the Image structure
+					 * plus the size of the image data. */
 } Image;
 
@@ -2075,26 +2076,26 @@
     close(proxy.sin);
 
-    status = waitpid(child, &result, WNOHANG);
-    if (status == -1) {
+    if (waitpid(child, &result, 0) < 0) {
         ERROR("error waiting on pymol server to exit: %s", strerror(errno));
-    } else if (status == 0) {
-        ERROR("attempting to signal (SIGTERM) pymol server.");
-        kill(-child, SIGTERM);		// Kill process group
-        alarm(5);
-        status = waitpid(child, &result, 0);
-        alarm(0);
-	
-        while ((status == -1) && (errno == EINTR)) {
-	    ERROR("Attempting to signal (SIGKILL) pymol server.");
-	    kill(-child, SIGKILL);	// Kill process group
-	    alarm(10);
-	    status = waitpid(child, &result, 0);
-	    alarm(0); 
-	}
-    }
+    }
+    INFO("attempting to signal (SIGTERM) pymol server.");
+    kill(-child, SIGTERM);		// Kill process group
+    alarm(5);
     
-    ERROR("pymol server process ended (result=%d)", result);
+    if (waitpid(child, &result, 0) < 0) {
+        ERROR("error waiting on pymol server to exit after SIGTERM: %s", 
+	      strerror(errno));
+    }
+    status = -1;
+    while ((status == -1) && (errno == EINTR)) {
+	ERROR("Attempting to signal (SIGKILL) pymol server.");
+	kill(-child, SIGKILL);	// Kill process group
+	alarm(10);
+	status = waitpid(child, &result, 0);
+	alarm(0); 
+    }
+    INFO("pymol server process ended (result=%d)", result);
+
     DestroyTmpDir();
-
     Tcl_DeleteInterp(interp);
     
@@ -2117,11 +2118,13 @@
     fcntl(proxyPtr->cin, F_SETFL, flags|O_NONBLOCK);
 
-    pollResults[0].fd = proxyPtr->cout;
-    pollResults[1].fd = proxyPtr->sout;
-    pollResults[2].fd = proxyPtr->serr;
+    /* Read file descriptors. */
+    pollResults[0].fd = proxyPtr->cout;	/* Client standard output  */
+    pollResults[1].fd = proxyPtr->sout;	/* Server standard error.  */
+    pollResults[2].fd = proxyPtr->serr;	/* Server standard error.  */
     pollResults[0].events = pollResults[1].events = 
 	pollResults[2].events = POLLIN;
 
-    pollResults[3].fd = proxyPtr->cin;
+    /* Write file descriptors. */
+    pollResults[3].fd = proxyPtr->cin;	/* Client standard input. */
     pollResults[3].events = POLLOUT;
 
@@ -2163,5 +2166,5 @@
 	    } else {
 		ERROR("Failed reading pymol stdout (nBytes=%d)\n", nBytes);
-		goto error;	/* Get out on EOF or error. */
+		goto error;		/* Get out on EOF or error. */
 	    }
 	}
@@ -2180,5 +2183,5 @@
 		if (errno != EINTR) { 
 		    ERROR("lost connection (stderr) to pymol server.");
-		    return;
+		    goto error;
 		}
 	    }
