Parcourir la source

- applied Michal Matyska <[email protected]> patch: fixes sercmd/libbinrpc
getting stuck in infinite loop on EOF (ser shutdown).
Closes SER-295.

Andrei Pelinescu-Onciul il y a 18 ans
Parent
commit
c28261fc4c
2 fichiers modifiés avec 10 ajouts et 5 suppressions
  1. 9 4
      lib/binrpc/binrpc_api.c
  2. 1 1
      utils/sercmd/sercmd.c

+ 9 - 4
lib/binrpc/binrpc_api.c

@@ -451,12 +451,17 @@ static int get_reply(struct binrpc_handle *handle,
 	
 	do {		
 		n = read(handle->socket, crt, handle->buf_size - (crt-handle->buf));
-		if (n < 0){
+		if (n <= 0){
 			if (errno==EINTR)
 				continue;
-			snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
-				"get_reply: read reply failed: %s (%d)",
-				strerror(errno), errno);
+			if (n == 0)
+				snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
+					"get_reply: read unexpected EOF: received %d bytes"
+					" of reply", n);
+			else
+				snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
+					"get_reply: read reply failed: %s (%d)",
+					strerror(errno), errno);
 			return FATAL_ERROR;
 		}
 		if (verbose >= 3){

+ 1 - 1
utils/sercmd/sercmd.c

@@ -576,7 +576,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
 	binrpc_errno=0;
 	do{
 		n=read(s, crt, (int)(msg_end-crt));
-		if (n<0){
+		if (n<=0){
 			if (errno==EINTR)
 				continue;
 			goto error_read;