Commit 187a7232 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give varnishadm a -t argument, to set a timeout for operations.

Use VSS_open() instead of home-rolling.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4589 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 72f9364a
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
.Nd Control a running varnish instance .Nd Control a running varnish instance
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl t Ar timeout
.Fl T Ar address Ns : Ns Ar port .Fl T Ar address Ns : Ns Ar port
.Cm command .Cm command
.Op Ar ... .Op Ar ...
...@@ -48,6 +49,8 @@ instance at the specified address and port and prints the results. ...@@ -48,6 +49,8 @@ instance at the specified address and port and prints the results.
.Pp .Pp
The following options are available: The following options are available:
.Bl -tag -width Fl .Bl -tag -width Fl
.It Fl t Ar timeout
Wait no longer than this many seconds for an operation to finish.
.It Fl T Ar address Ns : Ns Ar port .It Fl T Ar address Ns : Ns Ar port
Connect to the management interface at the specified address and port. Connect to the management interface at the specified address and port.
.El .El
......
...@@ -42,6 +42,8 @@ SVNID("$Id$") ...@@ -42,6 +42,8 @@ SVNID("$Id$")
#include "libvarnish.h" #include "libvarnish.h"
#include "vss.h" #include "vss.h"
static double timeout = 5;
/* /*
* This function establishes a connection to the specified ip and port and * This function establishes a connection to the specified ip and port and
* sends a command to varnishd. If varnishd returns an OK status, the result * sends a command to varnishd. If varnishd returns an OK status, the result
...@@ -51,31 +53,18 @@ SVNID("$Id$") ...@@ -51,31 +53,18 @@ SVNID("$Id$")
static void static void
telnet_mgt(const char *T_arg, int argc, char *argv[]) telnet_mgt(const char *T_arg, int argc, char *argv[])
{ {
struct vss_addr **ta; int i;
char *addr, *port;
int i, n;
int sock; int sock;
unsigned status; unsigned status;
char *answer = NULL; char *answer = NULL;
XXXAZ(VSS_parse(T_arg, &addr, &port)); sock = VSS_open(T_arg, timeout);
XXXAN(n = VSS_resolve(addr, port, &ta)); if (sock < 0) {
free(addr); fprintf(stderr, "Connection failed\n");
free(port); exit(1);
if (n == 0) {
fprintf(stderr, "Could not resolve '%s'\n", T_arg);
exit(2);
}
sock = VSS_connect(ta[0], 0);
for (i = 0; i < n; ++i) {
free(ta[i]);
ta[i] = NULL;
} }
free(ta);
cli_readres(sock, &status, &answer, 2000); cli_readres(sock, &status, &answer, timeout);
if (status == CLIS_AUTH) { if (status == CLIS_AUTH) {
fprintf(stderr, "Authentication required\n"); fprintf(stderr, "Authentication required\n");
exit(1); exit(1);
...@@ -86,7 +75,7 @@ telnet_mgt(const char *T_arg, int argc, char *argv[]) ...@@ -86,7 +75,7 @@ telnet_mgt(const char *T_arg, int argc, char *argv[])
} }
write(sock, "ping\n", 5); write(sock, "ping\n", 5);
cli_readres(sock, &status, &answer, 2000); cli_readres(sock, &status, &answer, timeout);
if (status != CLIS_OK || strstr(answer, "PONG") == NULL) { if (status != CLIS_OK || strstr(answer, "PONG") == NULL) {
fprintf(stderr, "No pong received from server\n"); fprintf(stderr, "No pong received from server\n");
exit(1); exit(1);
...@@ -117,7 +106,7 @@ static void ...@@ -117,7 +106,7 @@ static void
usage(void) usage(void)
{ {
fprintf(stderr, fprintf(stderr,
"usage: varnishadm -T [address]:port command [...]\n"); "usage: varnishadm [-t timeout] -T [address]:port command [...]\n");
exit(1); exit(1);
} }
...@@ -127,11 +116,14 @@ main(int argc, char *argv[]) ...@@ -127,11 +116,14 @@ main(int argc, char *argv[])
const char *T_arg = NULL; const char *T_arg = NULL;
int opt; int opt;
while ((opt = getopt(argc, argv, "T:")) != -1) { while ((opt = getopt(argc, argv, "T:t:")) != -1) {
switch (opt) { switch (opt) {
case 'T': case 'T':
T_arg = optarg; T_arg = optarg;
break; break;
case 't':
timeout = strtod(optarg, NULL);
break;
default: default:
usage(); usage();
} }
......
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