From: Hannes Reinecke Date: Tue, 28 Apr 2009 09:03:10 +0000 (+0200) Subject: Update cli request processing X-Git-Tag: upstream/0.5.0~106^2~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f86a09ad6e887be55f4a8ae90ebb8ff963a1076;p=platform%2Fupstream%2Fmultipath-tools.git Update cli request processing Add error checking to cli packet processing and some whitespace fixes. Signed-off-by: Hannes Reinecke --- diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c index d5d1be9..e786899 100644 --- a/libmultipath/uxsock.c +++ b/libmultipath/uxsock.c @@ -152,12 +152,22 @@ int send_packet(int fd, const char *buf, size_t len) */ int recv_packet(int fd, char **buf, size_t *len) { - if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1; + if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) { + (*buf) = NULL; + *len = 0; + return -1; + } + if (len == 0) { + (*buf) = NULL; + return 0; + } (*buf) = MALLOC(*len); if (!*buf) return -1; if (read_all(fd, *buf, *len) != *len) { FREE(*buf); + (*buf) = NULL; + *len = 0; return -1; } return 0; diff --git a/multipathd/uxclnt.c b/multipathd/uxclnt.c index 2882716..4e3ed26 100644 --- a/multipathd/uxclnt.c +++ b/multipathd/uxclnt.c @@ -1,6 +1,6 @@ /* * Original author : tridge@samba.org, January 2002 - * + * * Copyright (c) 2005 Christophe Varoqui * Copyright (c) 2005 Benjamin Marzinski, Redhat */ @@ -33,12 +33,12 @@ static void print_reply(char *s) /* strip ANSI color markers */ while (*s != '\0') { if ((*s == 0x1b) && (*(s+1) == '[')) - while ((*s++ != 'm') && (*s != '\0')) {}; + while ((*s++ != 'm') && (*s != '\0')) {}; putchar(*s++); } } /* - * process the client + * process the client */ static void process(int fd) { @@ -79,14 +79,18 @@ static void process_req(int fd, char * inbuf) char *reply; size_t len; - if (send_packet(fd, inbuf, strlen(inbuf) + 1) != 0) + if (send_packet(fd, inbuf, strlen(inbuf) + 1) != 0) { + printf("cannot send packet\n"); return; - if (recv_packet(fd, &reply, &len) == 0) { - print_reply(reply); + } + if (recv_packet(fd, &reply, &len) != 0) + printf("error receiving packet\n"); + else { + printf("%s", reply); FREE(reply); } } - + /* * entry point */ @@ -104,6 +108,6 @@ int uxclnt(char * inbuf) process_req(fd, inbuf); else process(fd); - + return 0; } diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c index a05719f..679651c 100644 --- a/multipathd/uxlsnr.c +++ b/multipathd/uxlsnr.c @@ -146,13 +146,14 @@ void * uxsock_listen(int (*uxsock_trigger)(char *, char **, int *, void *), inbuf[len - 1] = 0; condlog(4, "Got request [%s]", inbuf); uxsock_trigger(inbuf, &reply, &rlen, - trigger_data); - + trigger_data); if (reply) { if (send_packet(c->fd, reply, - rlen) != 0) { + rlen) != 0) { dead_client(c); } + condlog(4, "Reply [%d bytes]", + rlen); FREE(reply); reply = NULL; }