Commit b530ed43 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp
parents 1ebd8615 7058d471
......@@ -55,9 +55,9 @@ SVNID("$Id$")
do { \
rl_callback_handler_remove(); \
exit(status); \
} while (0);
} while (0)
#else
#define RL_EXIT(status) exit(status);
#define RL_EXIT(status) exit(status)
#endif
static double timeout = 5;
......@@ -193,7 +193,9 @@ pass(int sock)
{
struct pollfd fds[2];
char buf[1024];
int i, n, m;
int i, n;
char *answer = NULL;
unsigned u, status;
#ifdef HAVE_LIBEDIT
_line_sock = sock;
......@@ -214,21 +216,25 @@ pass(int sock)
i = poll(fds, 2, -1);
assert(i > 0);
if (fds[0].revents & POLLIN) {
n = read(fds[0].fd, buf, sizeof buf);
if (n == 0)
RL_EXIT(0);
if (n < 0) {
perror("Read error reading CLI socket");
RL_EXIT(1);
}
assert(n > 0);
/* Get rid of the prompt, kinda hackish */
write(1, "\r \r", 13);
m = write(1, buf, n);
if (n != m) {
perror("Write error writing stdout");
u = write(1, "\r \r", 13);
u = cli_readres(fds[0].fd, &status, &answer, timeout);
if (u) {
if (status == CLIS_COMMS)
RL_EXIT(0);
if (answer)
fprintf(stderr, "%s\n", answer);
RL_EXIT(1);
}
sprintf(buf, "%u\n", status);
u = write(1, buf, strlen(buf));
if (answer) {
u = write(1, answer, strlen(answer));
u = write(1, "\n", 1);
free(answer);
answer = NULL;
}
#ifdef HAVE_LIBEDIT
rl_forced_update_display();
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment