Changeset 4589

Show
Ignore:
Timestamp:
02/26/10 10:37:57 (5 months ago)
Author:
phk
Message:

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

Use VSS_open() instead of home-rolling.

Location:
trunk/varnish-cache/bin/varnishadm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/varnish-cache/bin/varnishadm/varnishadm.1

    r4025 r4589  
    3737.Sh SYNOPSIS 
    3838.Nm 
     39.Op Fl t Ar timeout 
    3940.Fl T Ar address Ns : Ns Ar port 
    4041.Cm command 
     
    4950The following options are available: 
    5051.Bl -tag -width Fl 
     52.It Fl t Ar timeout  
     53Wait no longer than this many seconds for an operation to finish. 
    5154.It Fl T Ar address Ns : Ns Ar port 
    5255Connect to the management interface at the specified address and port. 
  • trunk/varnish-cache/bin/varnishadm/varnishadm.c

    r4587 r4589  
    4343#include "vss.h" 
    4444 
     45static double timeout = 5; 
     46 
    4547/* 
    4648 * This function establishes a connection to the specified ip and port and 
     
    5254telnet_mgt(const char *T_arg, int argc, char *argv[]) 
    5355{ 
    54         struct vss_addr **ta; 
    55         char *addr, *port; 
    56         int i, n; 
     56        int i; 
    5757        int sock; 
    5858        unsigned status; 
    5959        char *answer = NULL; 
    6060 
    61         XXXAZ(VSS_parse(T_arg, &addr, &port)); 
    62         XXXAN(n = VSS_resolve(addr, port, &ta)); 
    63         free(addr); 
    64         free(port); 
    65         if (n == 0) { 
    66                 fprintf(stderr, "Could not resolve '%s'\n", T_arg); 
    67                 exit(2); 
     61        sock = VSS_open(T_arg, timeout); 
     62        if (sock < 0) { 
     63                fprintf(stderr, "Connection failed\n"); 
     64                exit(1); 
    6865        } 
    6966 
    70         sock = VSS_connect(ta[0], 0); 
    71  
    72         for (i = 0; i < n; ++i) { 
    73                 free(ta[i]); 
    74                 ta[i] = NULL; 
    75         } 
    76         free(ta); 
    77  
    78         cli_readres(sock, &status, &answer, 2000); 
     67        cli_readres(sock, &status, &answer, timeout); 
    7968        if (status == CLIS_AUTH) { 
    8069                fprintf(stderr, "Authentication required\n"); 
     
    8776 
    8877        write(sock, "ping\n", 5); 
    89         cli_readres(sock, &status, &answer, 2000); 
     78        cli_readres(sock, &status, &answer, timeout); 
    9079        if (status != CLIS_OK || strstr(answer, "PONG") == NULL) { 
    9180                fprintf(stderr, "No pong received from server\n"); 
     
    118107{ 
    119108        fprintf(stderr, 
    120             "usage: varnishadm -T [address]:port command [...]\n"); 
     109            "usage: varnishadm [-t timeout] -T [address]:port command [...]\n"); 
    121110        exit(1); 
    122111} 
     
    128117        int opt; 
    129118 
    130         while ((opt = getopt(argc, argv, "T:")) != -1) { 
     119        while ((opt = getopt(argc, argv, "T:t:")) != -1) { 
    131120                switch (opt) { 
    132121                case 'T': 
    133122                        T_arg = optarg; 
     123                        break; 
     124                case 't': 
     125                        timeout = strtod(optarg, NULL); 
    134126                        break; 
    135127                default: