Commit bf1c04bc authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

varnishadm: Only print the status in interactive mode

Or when the -p option is used.

Fixes #3687
parent 04455d6c
...@@ -76,6 +76,10 @@ ...@@ -76,6 +76,10 @@
exit(status); \ exit(status); \
} while (0) } while (0)
enum pass_mode_e {
pass_script,
pass_interactive,
};
static double timeout = 5; static double timeout = 5;
static int p_arg = 0; static int p_arg = 0;
...@@ -161,7 +165,7 @@ cli_sock(const char *T_arg, const char *S_arg) ...@@ -161,7 +165,7 @@ cli_sock(const char *T_arg, const char *S_arg)
} }
static unsigned static unsigned
pass_answer(int fd) pass_answer(int fd, enum pass_mode_e mode)
{ {
unsigned u, status; unsigned u, status;
char *answer = NULL; char *answer = NULL;
...@@ -180,7 +184,8 @@ pass_answer(int fd) ...@@ -180,7 +184,8 @@ pass_answer(int fd)
} else if (p_arg) { } else if (p_arg) {
printf("%-3u %-8u\n", status, 0U); printf("%-3u %-8u\n", status, 0U);
} else { } else {
printf("%u\n", status); if (mode == pass_interactive)
printf("%u\n", status);
if (answer != NULL) if (answer != NULL)
printf("%s\n", answer); printf("%s\n", answer);
if (status == CLIS_TRUNCATED) if (status == CLIS_TRUNCATED)
...@@ -204,7 +209,7 @@ do_args(int sock, int argc, char * const *argv) ...@@ -204,7 +209,7 @@ do_args(int sock, int argc, char * const *argv)
cli_write(sock, argv[i]); cli_write(sock, argv[i]);
} }
cli_write(sock, "\n"); cli_write(sock, "\n");
status = pass_answer(sock); status = pass_answer(sock, pass_script);
closefd(&sock); closefd(&sock);
if (status == CLIS_OK || status == CLIS_TRUNCATED) if (status == CLIS_OK || status == CLIS_TRUNCATED)
exit(0); exit(0);
...@@ -317,7 +322,7 @@ interactive(int sock) ...@@ -317,7 +322,7 @@ interactive(int sock)
if (fds[0].revents & POLLIN) { if (fds[0].revents & POLLIN) {
/* Get rid of the prompt, kinda hackish */ /* Get rid of the prompt, kinda hackish */
printf("\r \r"); printf("\r \r");
(void)pass_answer(fds[0].fd); (void)pass_answer(fds[0].fd, pass_interactive);
rl_forced_update_display(); rl_forced_update_display();
} }
if (fds[1].revents & POLLIN) { if (fds[1].revents & POLLIN) {
...@@ -348,7 +353,7 @@ pass(int sock) ...@@ -348,7 +353,7 @@ pass(int sock)
} }
assert(i > 0); assert(i > 0);
if (fds[0].revents & POLLIN) if (fds[0].revents & POLLIN)
(void)pass_answer(fds[0].fd); (void)pass_answer(fds[0].fd, pass_script);
if (fds[1].revents & POLLIN || fds[1].revents & POLLHUP) { if (fds[1].revents & POLLIN || fds[1].revents & POLLHUP) {
n = read(fds[1].fd, buf, sizeof buf - 1); n = read(fds[1].fd, buf, sizeof buf - 1);
if (n == 0) { if (n == 0) {
......
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