From be3802c841d6796971b5b1114d5246e5ac083e4b Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 11 Aug 2006 13:41:28 +0000 Subject: [PATCH] Add -T option. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@812 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/mgt.h | 5 +-- varnish-cache/bin/varnishd/mgt_child.c | 5 ++- varnish-cache/bin/varnishd/mgt_cli.c | 42 ++++++++++++++++++++++++-- varnish-cache/bin/varnishd/tcp.c | 11 ++++--- varnish-cache/bin/varnishd/varnishd.c | 13 +++++--- 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index 78ecb501..e6a13041 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -10,7 +10,7 @@ extern struct evbase *mgt_evb; /* mgt_child.c */ -void mgt_run(int dflag); +void mgt_run(int dflag, const char *Tflag); extern pid_t mgt_pid, child_pid; /* mgt_cli.c */ @@ -20,6 +20,7 @@ void mgt_cli_setup(int fdi, int fdo, int verbose); int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...); void mgt_cli_start_child(int fdi, int fdo); void mgt_cli_stop_child(void); +int mgt_cli_telnet(const char *port); /* mgt_vcc.c */ void mgt_vcc_init(void); @@ -27,7 +28,7 @@ int mgt_vcc_default(const char *bflag, const char *fflag); int mgt_push_vcls_and_start(unsigned *status, char **p); /* tcp.c */ -int open_tcp(const char *port); +int open_tcp(const char *port, int http); #include "stevedore.h" diff --git a/varnish-cache/bin/varnishd/mgt_child.c b/varnish-cache/bin/varnishd/mgt_child.c index 2230d401..f52e64b5 100644 --- a/varnish-cache/bin/varnishd/mgt_child.c +++ b/varnish-cache/bin/varnishd/mgt_child.c @@ -276,7 +276,7 @@ mgt_sigint(struct ev *e, int what) */ void -mgt_run(int dflag) +mgt_run(int dflag, const char *Tflag) { struct sigaction sac; struct ev *e; @@ -290,6 +290,9 @@ mgt_run(int dflag) if (dflag) mgt_cli_setup(0, 1, 1); + if (Tflag) + mgt_cli_telnet(Tflag); + e = ev_new(); assert(e != NULL); e->sig = SIGTERM; diff --git a/varnish-cache/bin/varnishd/mgt_cli.c b/varnish-cache/bin/varnishd/mgt_cli.c index 2a2e3285..46843107 100644 --- a/varnish-cache/bin/varnishd/mgt_cli.c +++ b/varnish-cache/bin/varnishd/mgt_cli.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifndef HAVE_VASPRINTF #include "compat/vasprintf.h" @@ -27,6 +28,8 @@ #include "shmlog.h" static int cli_i = -1, cli_o = -1; +static int telnet_sock; +static struct ev *telnet_ev; /*--------------------------------------------------------------------*/ @@ -134,7 +137,6 @@ mgt_cli_init(void) struct cli_proto *cp; unsigned u, v; - /* * Build the joint cli_proto by combining the manager process * entries with with the cache process entries. The latter @@ -165,8 +167,6 @@ mgt_cli_init(void) /* Fixup the entry for 'help' entry */ assert(!strcmp(cli_proto[0].request, "help")); cli_proto[0].priv = cli_proto; - - /* XXX: open listening sockets, contact cluster server etc */ } /*-------------------------------------------------------------------- @@ -325,3 +325,39 @@ mgt_cli_setup(int fdi, int fdo, int verbose) cp->ev->priv = cp; ev_add(mgt_evb, cp->ev); } + +static int +telnet_accept(struct ev *ev, int what) +{ + socklen_t l; + struct sockaddr addr[2]; /* XXX IPv6 hack */ + int i; + + (void)ev; + (void)what; + l = sizeof addr; + i = accept(telnet_sock, addr, &l); + if (i < 0) + return (0); + + mgt_cli_setup(i, i, 0); + return (0); +} + +int +mgt_cli_telnet(const char *port) +{ + + telnet_sock = open_tcp(port, 0); + if (telnet_sock < 0) { + fprintf(stderr, "Could not open TELNET port\n"); + exit (2); + } + telnet_ev = ev_new(); + assert(telnet_ev != NULL); + telnet_ev->fd = telnet_sock; + telnet_ev->fd_flags = POLLIN; + telnet_ev->callback = telnet_accept; + ev_add(mgt_evb, telnet_ev); + return (0); +} diff --git a/varnish-cache/bin/varnishd/tcp.c b/varnish-cache/bin/varnishd/tcp.c index 29fc2c3f..9bf6f7b2 100644 --- a/varnish-cache/bin/varnishd/tcp.c +++ b/varnish-cache/bin/varnishd/tcp.c @@ -16,7 +16,6 @@ #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif -#include "heritage.h" #include "mgt.h" /*--------------------------------------------------------------------*/ @@ -91,7 +90,7 @@ try_sock(int family, const char *port, struct addrinfo **resp) } int -open_tcp(const char *port) +open_tcp(const char *port, int http) { int sd, val; struct addrinfo *res; @@ -131,9 +130,11 @@ open_tcp(const char *port) return (-1); } #ifdef HAVE_ACCEPT_FILTERS - accept_filter(sd); + if (http) + accept_filter(sd); +#else + (void)http; #endif freeaddrinfo(res); - heritage.socket = sd; - return (0); + return (sd); } diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index 915a0c5a..bd503006 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -154,6 +154,7 @@ usage(void) fprintf(stderr, " %-28s # %s\n", "", " -s file,,"); fprintf(stderr, " %-28s # %s\n", "-t", "Default TTL"); + fprintf(stderr, " %-28s # %s\n", "-T port", "Telnet port"); fprintf(stderr, " %-28s # %s\n", "-V", "version"); fprintf(stderr, " %-28s # %s\n", "-w int[,int[,int]]", "Number of worker threads"); @@ -166,7 +167,6 @@ usage(void) #if 0 -c clusterid@cluster_controller -m memory_limit - -s kind[,storage-options] -l logfile,logsize -u uid -a CLI_port @@ -322,6 +322,7 @@ main(int argc, char *argv[]) const char *fflag = NULL; const char *sflag = "file"; const char *hflag = "classic"; + const char *Tflag = NULL; setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -334,7 +335,7 @@ main(int argc, char *argv[]) heritage.wthread_timeout = 10; heritage.mem_workspace = 4096; - while ((o = getopt(argc, argv, "b:df:h:p:s:t:Vw:")) != -1) + while ((o = getopt(argc, argv, "b:df:h:p:s:t:T:Vw:")) != -1) switch (o) { case 'b': bflag = optarg; @@ -357,6 +358,9 @@ main(int argc, char *argv[]) case 't': heritage.default_ttl = strtoul(optarg, NULL, 0); break; + case 'T': + Tflag = optarg; + break; case 'V': varnish_version("varnishd"); exit(0); @@ -397,7 +401,8 @@ main(int argc, char *argv[]) * but do not answer. That, on the other hand, would eliminate the * possibility of doing a "no-glitch" restart of the child process. */ - if (open_tcp(portnumber)) + heritage.socket = open_tcp(portnumber, 1); + if (heritage.socket < 0) exit (2); VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024); @@ -411,7 +416,7 @@ main(int argc, char *argv[]) mgt_cli_init(); - mgt_run(dflag); + mgt_run(dflag, Tflag); exit(0); } -- 2.39.5