Here's a patch for a very old bug. It is not the first time that I try
to tackle it, but it only occured to me today that the existing code
tests a value of errno that is probably the result of another IO action
done in the execution of the lfun (buffer-write, for example).

The patch is tested and works. But since I do not really now much about
pipes and read(), I'll wait a few days before committing.

JMarc

PS: this is a candidate for 1.5.x branch too.

svndiff

Index: src/Server.cpp
===================================================================
--- src/Server.cpp	(revision 26670)
+++ src/Server.cpp	(working copy)
@@ -257,7 +257,7 @@ void LyXComm::read_ready()
 	// the single = is intended here.
 	while ((status = ::read(infd_, charbuf, charbuf_size - 1))) {
 
-		if (status > 0) {
+		if (status >= 0) {
 			charbuf[status] = '\0'; // turn it into a c string
 			read_buffer_ += rtrim(charbuf, "\r");
 			// commit any commands read
@@ -273,25 +273,22 @@ void LyXComm::read_ready()
 					clientcb_(client_, cmd);
 					//\n or not \n?
 			}
-		}
-		if (errno == EAGAIN) {
-			errno = 0;
-			return;
-		}
-		if (errno != 0) {
+		} else {
+			if (errno == EAGAIN) {
+				errno = 0;
+				return;
+			}
 			LYXERR0("LyXComm: " << strerror(errno));
+			// reset connection
+			closeConnection();
+			openConnection();
 			if (!read_buffer_.empty()) {
 				LYXERR0("LyXComm: truncated command: " << read_buffer_);
 				read_buffer_.erase();
 			}
-			break; // reset connection
+			break;
 		}
 	}
-
-	// The connection gets reset in errno != EAGAIN
-	// Why does it need to be reset if errno == 0?
-	closeConnection();
-	openConnection();
 	errno = 0;
 }
 

Reply via email to