r812 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Fri Aug 11 15:41:28 CEST 2006
Author: phk
Date: 2006-08-11 15:41:28 +0200 (Fri, 11 Aug 2006)
New Revision: 812
Modified:
trunk/varnish-cache/bin/varnishd/mgt.h
trunk/varnish-cache/bin/varnishd/mgt_child.c
trunk/varnish-cache/bin/varnishd/mgt_cli.c
trunk/varnish-cache/bin/varnishd/tcp.c
trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Add -T <telnetport> option.
Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h 2006-08-11 11:23:12 UTC (rev 811)
+++ trunk/varnish-cache/bin/varnishd/mgt.h 2006-08-11 13:41:28 UTC (rev 812)
@@ -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 @@
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_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"
Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c 2006-08-11 11:23:12 UTC (rev 811)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2006-08-11 13:41:28 UTC (rev 812)
@@ -276,7 +276,7 @@
*/
void
-mgt_run(int dflag)
+mgt_run(int dflag, const char *Tflag)
{
struct sigaction sac;
struct ev *e;
@@ -290,6 +290,9 @@
if (dflag)
mgt_cli_setup(0, 1, 1);
+ if (Tflag)
+ mgt_cli_telnet(Tflag);
+
e = ev_new();
assert(e != NULL);
e->sig = SIGTERM;
Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2006-08-11 11:23:12 UTC (rev 811)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2006-08-11 13:41:28 UTC (rev 812)
@@ -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 @@
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 @@
/* 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 @@
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);
+}
Modified: trunk/varnish-cache/bin/varnishd/tcp.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/tcp.c 2006-08-11 11:23:12 UTC (rev 811)
+++ trunk/varnish-cache/bin/varnishd/tcp.c 2006-08-11 13:41:28 UTC (rev 812)
@@ -16,7 +16,6 @@
#ifndef HAVE_STRLCPY
#include "compat/strlcpy.h"
#endif
-#include "heritage.h"
#include "mgt.h"
/*--------------------------------------------------------------------*/
@@ -91,7 +90,7 @@
}
int
-open_tcp(const char *port)
+open_tcp(const char *port, int http)
{
int sd, val;
struct addrinfo *res;
@@ -131,9 +130,11 @@
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);
}
Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-08-11 11:23:12 UTC (rev 811)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2006-08-11 13:41:28 UTC (rev 812)
@@ -154,6 +154,7 @@
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 @@
#if 0
-c clusterid at cluster_controller
-m memory_limit
- -s kind[,storage-options]
-l logfile,logsize
-u uid
-a CLI_port
@@ -322,6 +322,7 @@
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 @@
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 @@
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 @@
* 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 @@
mgt_cli_init();
- mgt_run(dflag);
+ mgt_run(dflag, Tflag);
exit(0);
}
More information about the varnish-commit
mailing list