r4589 - trunk/varnish-cache/bin/varnishadm

phk at projects.linpro.no phk at projects.linpro.no
Fri Feb 26 10:37:57 CET 2010


Author: phk
Date: 2010-02-26 10:37:57 +0100 (Fri, 26 Feb 2010)
New Revision: 4589

Modified:
   trunk/varnish-cache/bin/varnishadm/varnishadm.1
   trunk/varnish-cache/bin/varnishadm/varnishadm.c
Log:
Give varnishadm a -t argument, to set a timeout for operations.

Use VSS_open() instead of home-rolling.



Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.1
===================================================================
--- trunk/varnish-cache/bin/varnishadm/varnishadm.1	2010-02-26 09:35:42 UTC (rev 4588)
+++ trunk/varnish-cache/bin/varnishadm/varnishadm.1	2010-02-26 09:37:57 UTC (rev 4589)
@@ -36,6 +36,7 @@
 .Nd Control a running varnish instance
 .Sh SYNOPSIS
 .Nm
+.Op Fl t Ar timeout
 .Fl T Ar address Ns : Ns Ar port
 .Cm command
 .Op Ar ...
@@ -48,6 +49,8 @@
 .Pp
 The following options are available:
 .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
 Connect to the management interface at the specified address and port.
 .El

Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c
===================================================================
--- trunk/varnish-cache/bin/varnishadm/varnishadm.c	2010-02-26 09:35:42 UTC (rev 4588)
+++ trunk/varnish-cache/bin/varnishadm/varnishadm.c	2010-02-26 09:37:57 UTC (rev 4589)
@@ -42,6 +42,8 @@
 #include "libvarnish.h"
 #include "vss.h"
 
+static double timeout = 5;
+
 /*
  * 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
@@ -51,31 +53,18 @@
 static void
 telnet_mgt(const char *T_arg, int argc, char *argv[])
 {
-	struct vss_addr **ta;
-	char *addr, *port;
-	int i, n;
+	int i;
 	int sock;
 	unsigned status;
 	char *answer = NULL;
 
-	XXXAZ(VSS_parse(T_arg, &addr, &port));
-	XXXAN(n = VSS_resolve(addr, port, &ta));
-	free(addr);
-	free(port);
-	if (n == 0) {
-		fprintf(stderr, "Could not resolve '%s'\n", T_arg);
-		exit(2);
+	sock = VSS_open(T_arg, timeout);
+	if (sock < 0) {
+		fprintf(stderr, "Connection failed\n");
+		exit(1);
 	}
 
-	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) {
 		fprintf(stderr, "Authentication required\n");
 		exit(1);
@@ -86,7 +75,7 @@
 	}
 
 	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) {
 		fprintf(stderr, "No pong received from server\n");
 		exit(1);
@@ -117,7 +106,7 @@
 usage(void)
 {
 	fprintf(stderr,
-	    "usage: varnishadm -T [address]:port command [...]\n");
+	    "usage: varnishadm [-t timeout] -T [address]:port command [...]\n");
 	exit(1);
 }
 
@@ -127,11 +116,14 @@
 	const char *T_arg = NULL;
 	int opt;
 
-	while ((opt = getopt(argc, argv, "T:")) != -1) {
+	while ((opt = getopt(argc, argv, "T:t:")) != -1) {
 		switch (opt) {
 		case 'T':
 			T_arg = optarg;
 			break;
+		case 't':
+			timeout = strtod(optarg, NULL);
+			break;
 		default:
 			usage();
 		}



More information about the varnish-commit mailing list