Update cli request processing
authorHannes Reinecke <hare@suse.de>
Tue, 28 Apr 2009 09:03:10 +0000 (11:03 +0200)
committerHannes Reinecke <hare@suse.de>
Fri, 13 May 2011 10:12:41 +0000 (12:12 +0200)
Add error checking to cli packet processing and some whitespace fixes.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/uxsock.c
multipathd/uxclnt.c
multipathd/uxlsnr.c

index d5d1be9..e786899 100644 (file)
@@ -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;
index 2882716..4e3ed26 100644 (file)
@@ -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;
 }
index a05719f..679651c 100644 (file)
@@ -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;
                                        }