~ubuntu-branches/ubuntu/saucy/varnish/saucy

« back to all changes in this revision

Viewing changes to bin/varnishd/mgt_cli.c

  • Committer: Bazaar Package Importer
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-03-21 10:16:07 UTC
  • mfrom: (24.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110321101607-528fzl583fqanas5
Tags: 2.1.5-2
ReleaseĀ forĀ unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "config.h"
33
33
 
34
34
#include "svnid.h"
35
 
SVNID("$Id: mgt_cli.c 4679 2010-04-19 11:24:21Z tfheen $")
 
35
SVNID("$Id$")
36
36
 
37
37
#include <sys/types.h>
38
38
 
68
68
static struct cls       *cls;
69
69
static const char       *secret_file;
70
70
 
71
 
#define MCF_NOAUTH      0
 
71
#define MCF_NOAUTH      0       /* NB: zero disables here-documents */
72
72
#define MCF_AUTH        16
73
73
 
74
74
/*--------------------------------------------------------------------*/
97
97
        (void)av;
98
98
        (void)priv;
99
99
        cli_out(cli, "-----------------------------\n");
100
 
        cli_out(cli, "Varnish HTTP accelerator CLI.\n");
 
100
        cli_out(cli, "Varnish Cache CLI 1.0\n");
101
101
        cli_out(cli, "-----------------------------\n");
 
102
        cli_out(cli, "%s\n", vsb_data(vident) + 1);
 
103
        cli_out(cli, "\n");
102
104
        cli_out(cli, "Type 'help' for command list.\n");
103
105
        cli_out(cli, "Type 'quit' to close CLI session.\n");
104
106
        if (child_pid < 0)
154
156
        char *q;
155
157
        unsigned u;
156
158
 
157
 
        (void)av;
158
159
        (void)priv;
159
160
        /*
160
161
         * Command not recognized in master, try cacher if it is
177
178
        if (i != strlen(cli->cmd)) {
178
179
                cli_result(cli, CLIS_COMMS);
179
180
                cli_out(cli, "CLI communication error");
 
181
                MGT_Child_Cli_Fail();
180
182
                return;
181
183
        }
182
184
        i = write(cli_o, "\n", 1);
183
185
        if (i != 1) {
184
186
                cli_result(cli, CLIS_COMMS);
185
187
                cli_out(cli, "CLI communication error");
 
188
                MGT_Child_Cli_Fail();
186
189
                return;
187
190
        }
188
 
 
189
 
        assert(i == 1 || errno == EPIPE);
190
 
        (void)cli_readres(cli_i,
191
 
            &u, &q, params->cli_timeout);
 
191
        (void)cli_readres(cli_i, &u, &q, params->cli_timeout);
192
192
        cli_result(cli, u);
193
193
        cli_out(cli, "%s", q);
194
194
        free(q);
233
233
                        *status = CLIS_COMMS;
234
234
                if (resp != NULL)
235
235
                        *resp = strdup("CLI communication error");
 
236
                MGT_Child_Cli_Fail();
236
237
                return (CLIS_COMMS);
237
238
        }
238
239
 
239
240
        (void)cli_readres(cli_i, &u, resp, params->cli_timeout);
240
241
        if (status != NULL)
241
242
                *status = u;
 
243
        if (u == CLIS_COMMS)
 
244
                MGT_Child_Cli_Fail();
242
245
        return (u == CLIS_OK ? 0 : u);
243
246
}
244
247
 
440
443
        AN(vsb);
441
444
        TCP_myname(fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
442
445
        TCP_hisname(fd, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
443
 
        vsb_printf(vsb, "%s %s:%s %s:%s", pfx, abuf2, pbuf2, abuf1, pbuf1);
 
446
        vsb_printf(vsb, "%s %s %s %s %s", pfx, abuf2, pbuf2, abuf1, pbuf1);
444
447
        vsb_finish(vsb);
445
448
        AZ(vsb_overflowed(vsb));
446
449
        return (vsb);
532
535
mgt_cli_telnet(const char *T_arg)
533
536
{
534
537
        struct vss_addr **ta;
535
 
        char *addr, *port;
536
538
        int i, n, sock, good;
537
539
        struct telnet *tn;
538
540
 
539
 
        XXXAZ(VSS_parse(T_arg, &addr, &port));
540
 
        n = VSS_resolve(addr, port, &ta);
 
541
        n = VSS_resolve(T_arg, NULL, &ta);
541
542
        if (n == 0) {
542
543
                fprintf(stderr, "Could not open management port\n");
543
544
                exit(2);
560
561
        }
561
562
        free(ta);
562
563
        if (good == 0) {
563
 
                REPORT(LOG_ERR, "-T %s:%s could not be listened on.",
564
 
                    addr, port);
 
564
                REPORT(LOG_ERR, "-T %s could not be listened on.", T_arg);
565
565
                exit(2);
566
566
        }
567
 
        free(addr);
568
 
        free(port);
569
567
}
570
568
 
571
569
/* Reverse CLI ("Master") connections --------------------------------*/
572
570
 
573
571
static int M_fd = -1;
574
572
static struct vev *M_poker, *M_conn;
575
 
static char *M_addr, *M_port;
576
573
static struct vss_addr **M_ta;
577
574
static int M_nta, M_nxt;
578
575
static double M_poll = 0.1;
648
645
{
649
646
        (void)M_arg;
650
647
 
651
 
        if (VSS_parse(M_arg, &M_addr, &M_port) || M_port == NULL) {
652
 
                fprintf(stderr, "Could not parse -M argument\n");
653
 
                exit (1);
654
 
        }
655
 
        M_nta = VSS_resolve(M_addr, M_port, &M_ta);
 
648
        M_nta = VSS_resolve(M_arg, NULL, &M_ta);
656
649
        if (M_nta <= 0) {
657
650
                fprintf(stderr, "Could resolve -M argument to address\n");
658
651
                exit (1);