]> err.no Git - varnish/commitdiff
Add -T <telnetport> option.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 Aug 2006 13:41:28 +0000 (13:41 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 Aug 2006 13:41:28 +0000 (13:41 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@812 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/mgt.h
varnish-cache/bin/varnishd/mgt_child.c
varnish-cache/bin/varnishd/mgt_cli.c
varnish-cache/bin/varnishd/tcp.c
varnish-cache/bin/varnishd/varnishd.c

index 78ecb50128894014b147ced55594149d4814f2e3..e6a13041c03d7db35901f54dee9c55d7ddb2935d 100644 (file)
@@ -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"
 
index 2230d401afa72a5216bf757745511a4e8e5dbc60..f52e64b56e25fde9e959d1ac8e7d936c397144da 100644 (file)
@@ -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;
index 2a2e32855c882de48ac596a55c4c24ff7ce0260f..4684310702b1f959bad06519d75f21681233a6a1 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/socket.h>
 
 #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);
+}
index 29fc2c3f4a751339b519ccc141212271a1f5f732..9bf6f7b227fb403e762e2988881b0bf1c7284f27 100644 (file)
@@ -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);
 }
index 915a0c5a588784963b3cc14718d11164984e1ca3..bd503006ddfd3fece83b92ebac0bc7290c0419fc 100644 (file)
@@ -154,6 +154,7 @@ usage(void)
        fprintf(stderr, "    %-28s # %s\n", "",
            "  -s file,<dir_or_file>,<size>");
        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);
 }