Commit 0d54b705 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

The -T argument can be specified as :0 which will just find one or

two (IPv4/6) available sockets.  In this case, writing the :0 into
the VSM will not tell varnishadm where to look.

Write the actual socket addresses, one per line instead, and have
varnishadm try them all.

Make -n mutually exclusive with -S and -T on varnishadm.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5123 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4d01e174
......@@ -79,21 +79,23 @@ cli_sock(const char *T_arg, const char *S_arg)
sock = VSS_open(T_arg, timeout);
if (sock < 0) {
fprintf(stderr, "Connection failed\n");
exit(1);
fprintf(stderr, "Connection failed (%s)\n", T_arg);
return (-1);
}
(void)cli_readres(sock, &status, &answer, timeout);
if (status == CLIS_AUTH) {
if (S_arg == NULL) {
fprintf(stderr, "Authentication required\n");
exit(1);
AZ(close(sock));
return(-1);
}
fd = open(S_arg, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Cannot open \"%s\": %s\n",
S_arg, strerror(errno));
exit (1);
AZ(close(sock));
return (-1);
}
CLI_response(fd, answer, buf);
AZ(close(fd));
......@@ -106,7 +108,8 @@ cli_sock(const char *T_arg, const char *S_arg)
}
if (status != CLIS_OK) {
fprintf(stderr, "Rejected %u\n%s\n", status, answer);
exit(1);
AZ(close(sock));
return (-1);
}
free(answer);
......@@ -114,10 +117,12 @@ cli_sock(const char *T_arg, const char *S_arg)
(void)cli_readres(sock, &status, &answer, timeout);
if (status != CLIS_OK || strstr(answer, "PONG") == NULL) {
fprintf(stderr, "No pong received from server\n");
exit(1);
AZ(close(sock));
return(-1);
}
free(answer);
fprintf(stderr, "CLI connected to %s\n", T_arg);
return (sock);
}
......@@ -205,19 +210,61 @@ static void
usage(void)
{
fprintf(stderr,
"usage: varnishadm [-t timeout] [-S secretfile] "
"usage: varnishadm [-n ident] [-t timeout] [-S secretfile] "
"-T [address]:port command [...]\n");
fprintf(stderr, "\t-n is mutually exlusive with -S and -T\n");
exit(1);
}
static int
n_arg_sock(const char *n_arg)
{
char *T_arg = NULL;
char *S_arg = NULL;
struct VSM_data *vsd;
char *p;
int sock;
vsd = VSM_New();
assert(VSL_Arg(vsd, 'n', n_arg));
if (VSM_Open(vsd, 1)) {
fprintf(stderr, "Could not open shared memory\n");
return (-1);
}
if (T_arg == NULL) {
p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL);
if (p == NULL) {
fprintf(stderr, "No -T arg in shared memory\n");
return (-1);
}
T_arg = strdup(p);
}
if (S_arg == NULL) {
p = VSM_Find_Chunk(vsd, "Arg", "-S", "", NULL);
if (p != NULL)
S_arg = strdup(p);
}
sock = -1;
while (*T_arg) {
p = strchr(T_arg, '\n');
AN(p);
*p = '\0';
sock = cli_sock(T_arg, S_arg);
if (sock >= 0)
break;
T_arg = p + 1;
}
free(T_arg);
free(S_arg);
return (sock);
}
int
main(int argc, char * const *argv)
{
const char *T_arg = NULL;
const char *S_arg = NULL;
const char *n_arg = NULL;
struct VSM_data *vsd;
char *p;
int opt, sock;
while ((opt = getopt(argc, argv, "n:S:T:t:")) != -1) {
......@@ -243,29 +290,18 @@ main(int argc, char * const *argv)
argv += optind;
if (n_arg != NULL) {
vsd = VSM_New();
assert(VSL_Arg(vsd, 'n', n_arg));
if (!VSM_Open(vsd, 1)) {
if (T_arg == NULL) {
p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL);
if (p != NULL) {
T_arg = strdup(p);
}
}
if (S_arg == NULL) {
p = VSM_Find_Chunk(vsd, "Arg", "-S", "", NULL);
if (p != NULL) {
S_arg = strdup(p);
}
}
if (T_arg != NULL || S_arg != NULL) {
usage();
}
}
if (T_arg == NULL)
sock = n_arg_sock(n_arg);
if (sock < 0)
exit(2);
} else if (T_arg == NULL) {
usage();
assert(T_arg != NULL);
sock = cli_sock(T_arg, S_arg);
} else {
assert(T_arg != NULL);
sock = cli_sock(T_arg, S_arg);
}
if (argc > 0)
do_args(sock, argc, argv);
......
......@@ -545,23 +545,24 @@ mgt_cli_telnet(const char *T_arg)
int i, n, sock, good;
struct telnet *tn;
char *p;
/* Save in shmem */
i = strlen(T_arg);
p = VSM_Alloc(i + 1, "Arg", "-T", "");
AN(p);
strcpy(p, T_arg);
struct vsb *vsb;
char abuf[TCP_ADDRBUFSIZE];
char pbuf[TCP_PORTBUFSIZE];
n = VSS_resolve(T_arg, NULL, &ta);
if (n == 0) {
fprintf(stderr, "Could not open management port\n");
REPORT(LOG_ERR, "-T %s Could not be resolved\n", T_arg);
exit(2);
}
good = 0;
vsb = vsb_newauto();
XXXAN(vsb);
for (i = 0; i < n; ++i) {
sock = VSS_listen(ta[i], 10);
if (sock < 0)
continue;
TCP_myname(sock, abuf, sizeof abuf, pbuf, sizeof pbuf);
vsb_printf(vsb, "%s %s\n", abuf, pbuf);
good++;
tn = telnet_new(sock);
tn->ev = vev_new();
......@@ -578,6 +579,13 @@ mgt_cli_telnet(const char *T_arg)
REPORT(LOG_ERR, "-T %s could not be listened on.", T_arg);
exit(2);
}
vsb_finish(vsb);
AZ(vsb_overflowed(vsb));
/* Save in shmem */
p = VSM_Alloc(vsb_len(vsb) + 1, "Arg", "-T", "");
AN(p);
strcpy(p, vsb_data(vsb));
vsb_delete(vsb);
}
/* Reverse CLI ("Master") connections --------------------------------*/
......
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