2 * Original author : tridge@samba.org, January 2002
4 * Copyright (c) 2005 Christophe Varoqui
5 * Copyright (c) 2005 Benjamin Marzinski, Redhat
13 #include <sys/ioctl.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
18 #include <readline/readline.h>
19 #include <readline/history.h>
21 #include "mpath_cmd.h"
30 static void print_reply(char *s)
39 /* strip ANSI color markers */
41 if ((*s == 0x1b) && (*(s+1) == '['))
42 while ((*s++ != 'm') && (*s != '\0')) {};
47 static int need_quit(char *str, size_t len)
50 size_t trimed_len = len;
52 for (ptr = str; trimed_len && isspace(*ptr);
58 for (ptr = str + len - 1; trimed_len && isspace(*ptr);
62 if ((trimed_len == 4 && !strncmp(start, "exit", 4)) ||
63 (trimed_len == 4 && !strncmp(start, "quit", 4)))
72 static void process(int fd, unsigned int timeout)
79 rl_readline_name = "multipathd";
80 rl_completion_entry_function = key_generator;
81 while ((line = readline("multipathd> "))) {
82 size_t llen = strlen(line);
89 if (need_quit(line, llen))
92 if (send_packet(fd, line) != 0) break;
93 ret = recv_packet(fd, &reply, timeout);
106 static int process_req(int fd, char * inbuf, unsigned int timeout)
111 if (send_packet(fd, inbuf) != 0) {
112 printf("cannot send packet\n");
115 ret = recv_packet(fd, &reply, timeout);
117 if (ret == -ETIMEDOUT)
118 printf("timeout receiving packet\n");
120 printf("error %d receiving packet\n", ret);
124 ret = (strcmp(reply, "fail\n") == 0);
133 int uxclnt(char * inbuf, unsigned int timeout)
137 fd = mpath_connect();
142 ret = process_req(fd, inbuf, timeout);
144 process(fd, timeout);
145 mpath_disconnect(fd);