multipathd: set return code for multipathd commands
[multipath-tools/.git] / multipathd / uxclnt.c
index 08db0e8..a76f8e2 100644 (file)
@@ -103,14 +103,14 @@ static void process(int fd, unsigned int timeout)
        }
 }
 
-static void process_req(int fd, char * inbuf, unsigned int timeout)
+static int process_req(int fd, char * inbuf, unsigned int timeout)
 {
        char *reply;
        int ret;
 
        if (send_packet(fd, inbuf) != 0) {
                printf("cannot send packet\n");
-               return;
+               return 1;
        }
        ret = recv_packet(fd, &reply, timeout);
        if (ret < 0) {
@@ -118,9 +118,12 @@ static void process_req(int fd, char * inbuf, unsigned int timeout)
                        printf("timeout receiving packet\n");
                else
                        printf("error %d receiving packet\n", ret);
+               return 1;
        } else {
                printf("%s", reply);
+               ret = (strcmp(reply, "fail\n") == 0);
                FREE(reply);
+               return ret;
        }
 }
 
@@ -129,16 +132,16 @@ static void process_req(int fd, char * inbuf, unsigned int timeout)
  */
 int uxclnt(char * inbuf, unsigned int timeout)
 {
-       int fd;
+       int fd, ret = 0;
 
        fd = mpath_connect();
        if (fd == -1)
                exit(1);
 
        if (inbuf)
-               process_req(fd, inbuf, timeout);
+               ret = process_req(fd, inbuf, timeout);
        else
                process(fd, timeout);
        mpath_disconnect(fd);
-       return 0;
+       return ret;
 }