Browse code

- ctl/binrpc modified not to complain if no reply was sent (happily send empty replies) and to parse empty messages/replies (until now an empty message was considered an error)

Andrei Pelinescu-Onciul authored on 03/11/2006 00:43:45
Showing 1 changed files
... ...
@@ -548,9 +548,15 @@ binrpc_err:
548 548
 }
549 549
 
550 550
 
551
+static int binrpc_errno=0;
551 552
 
552 553
 /* reads the whole reply
553
- * returns < 0 on error, reply size on success + initializes in_pkt */
554
+ * returns < 0 on error, reply size on success + initializes in_pkt
555
+ * if ret==-2 (parse error), sets binrpc_errno to the binrpc error
556
+ * error returns: -1 - read error (check errno)
557
+ *                -2 - binrpc parse error (chekc binrpc_errno) 
558
+ *                -3 - cookie error (the cookied doesn't match)
559
+ *                -4 - message too big */
554 560
 static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
555 561
 						int cookie, struct binrpc_parse_ctx* in_pkt,
556 562
 						unsigned char** body)
... ...
@@ -564,6 +570,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
564 564
 	
565 565
 	hdr_end=crt=reply_buf;
566 566
 	msg_end=reply_buf+max_reply_size;
567
+	binrpc_errno=0;
567 568
 	do{
568 569
 		n=read(s, crt, (int)(msg_end-crt));
569 570
 		if (n<0){
... ...
@@ -607,6 +614,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
607 607
 error_read:
608 608
 	return -1;
609 609
 error_parse:
610
+	binrpc_errno=ret;
610 611
 	return -2;
611 612
 error:
612 613
 	return -3;
... ...
@@ -817,11 +825,11 @@ static int run_binrpc_cmd(int s, struct binrpc_cmd * cmd, char* fmt)
817 817
 			case -1:
818 818
 				goto error_read;
819 819
 			case -2:
820
+				goto error_parse;
820 821
 			case -3:
822
+				goto error_cookie;
821 823
 			case -4:
822
-				goto error_parse;
823
-				goto error_parse;
824
-				goto error_parse;
824
+				goto error_toobig;
825 825
 		}
826 826
 		goto error;
827 827
 	}
... ...
@@ -849,8 +857,13 @@ binrpc_err:
849 849
 	goto error;
850 850
 error_parse:
851 851
 	fprintf(stderr, "ERROR while parsing the reply: %s\n", 
852
-				binrpc_error(ret));
852
+				binrpc_error(binrpc_errno));
853
+	goto error;
854
+error_cookie:
855
+	fprintf(stderr, "ERROR: cookie does not match\n");
853 856
 	goto error;
857
+error_toobig:
858
+	fprintf(stderr, "ERROR: reply too big\n");
854 859
 error_send:
855 860
 	fprintf(stderr, "ERROR: send packet failed: %s (%d)\n",
856 861
 			strerror(errno), errno);