X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=client.c;h=a800f7d86af32e58a5039d4e2c74068f9f6ba077;hb=76c643313daf7a27a966d1f07be765a490c47153;hp=ce66ea7b7159c101d77896b09c77f433d1f05c54;hpb=adbf9f09c9bf2a680c61b1ef3541c04f1cde97cf;p=paraslash.git diff --git a/client.c b/client.c index ce66ea7b..a800f7d8 100644 --- a/client.c +++ b/client.c @@ -71,7 +71,7 @@ static char *rl_gets(void) /* * do several cleanups on sigint */ -static void sigint_handler(__unused int i) +static void sigint_handler(__a_unused int i) { rl_cleanup_after_signal(); rl_reset_after_signal(); @@ -240,7 +240,7 @@ interactive_loop: numbytes); buf[numbytes] = '\0'; PARA_ERROR_LOG("received the following instead: %s\n", buf); - goto write_out; + exit(EXIT_FAILURE); } PARA_INFO_LOG("<-- [challenge (%i bytes)]\n", numbytes); /* decrypt challenge number */ @@ -289,18 +289,16 @@ interactive_loop: if (send_buffer(sockfd, EOC_MSG "\n") < 0) exit(EXIT_FAILURE); PARA_NOTICE_LOG("%s", "command sent.\n"); -write_out: received = 0; - /* write server output to stdout */ - while ((numbytes = recv_bin_buffer(sockfd, buf, sizeof(buf))) > 0) { - int ret; - + while ((numbytes = recv_bin_buffer(sockfd, buf, sizeof(buf) - 1)) > 0) { + buf[numbytes] = '\0'; if (!received && strstr(buf, AWAITING_DATA_MSG)) { - PARA_NOTICE_LOG("%s", "<-- awaiting data\n"); - PARA_NOTICE_LOG("%s", "--> sending stdin\n"); + PARA_NOTICE_LOG("%s", "sending stdin\n"); while ((ret = read(STDIN_FILENO, buf, - sizeof(buf))) > 0) - send_bin_buffer(sockfd, buf, ret); + sizeof(buf))) > 0) { + if (send_bin_buffer(sockfd, buf, ret) < 0) + break; + } PARA_NOTICE_LOG("%s", "closing connection\n"); numbytes = 1; break; @@ -314,5 +312,5 @@ write_out: close(sockfd); if (interactive) goto interactive_loop; - return 0; + return ret >= 0? 0: 1; }