*/
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <sys/mman.h>
+#include "libvarnish.h"
#include "shmlog.h"
#include "heritage.h"
+struct varnish_stats *VSL_stats;
+
static struct shmloghead *loghead;
static unsigned char *logstart, *logend;
/* XXX check sanity of loghead */
logstart = (unsigned char *)loghead + loghead->start;
logend = logstart + loghead->size;
+ VSL_stats = &loghead->stats;
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VSL_MgtInit(const char *fn, unsigned size)
+{
+ struct shmloghead slh;
+ int i;
+
+ heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600);
+ if (heritage.vsl_fd < 0) {
+ fprintf(stderr, "Could not open %s: %s\n",
+ fn, strerror(errno));
+ exit (1);
+ }
+ i = read(heritage.vsl_fd, &slh, sizeof slh);
+ if (i != sizeof slh || slh.magic != SHMLOGHEAD_MAGIC) {
+ /* XXX more checks */
+
+ slh.magic = SHMLOGHEAD_MAGIC;
+ slh.size = size;
+ slh.ptr = 0;
+ slh.start = sizeof slh;
+ AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
+ i = write(heritage.vsl_fd, &slh, sizeof slh);
+ assert(i == sizeof slh);
+ AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
+ heritage.vsl_size = slh.size + slh.start;
+ } else {
+ heritage.vsl_size = slh.size + slh.start;
+ }
+
+ /*
+ * Call VSL_Init so that we get a VSL_stats pointer in the
+ * management process as well.
+ */
+ VSL_Init();
+ memset(VSL_stats, 0, sizeof *VSL_stats);
}
+
#include "mgt.h"
#include "heritage.h"
+#include "shmlog.h"
#include "cli_event.h"
/*--------------------------------------------------------------------*/
}
static void
-cli_func_passthrough(struct cli *cli, char **av __unused, void *priv)
+m_cli_func_passthrough(struct cli *cli, char **av __unused, void *priv)
{
cli_suspend(cli);
}
static void
-cli_func_config_inline(struct cli *cli, char **av, void *priv __unused)
+m_cli_func_config_inline(struct cli *cli, char **av, void *priv __unused)
{
char *vf;
struct sbuf *sb;
/*--------------------------------------------------------------------*/
static void
-cli_func_server_start(struct cli *cli, char **av __unused, void *priv __unused)
+m_cli_func_server_start(struct cli *cli, char **av __unused, void *priv __unused)
{
mgt_child_start();
/*--------------------------------------------------------------------*/
static void
-cli_func_server_stop(struct cli *cli, char **av __unused, void *priv __unused)
+m_cli_func_server_stop(struct cli *cli, char **av __unused, void *priv __unused)
{
mgt_child_stop();
/*--------------------------------------------------------------------*/
static void
-cli_func_verbose(struct cli *cli, char **av __unused, void *priv)
+m_cli_func_verbose(struct cli *cli, char **av __unused, void *priv)
{
cli->verbose = !cli->verbose;
static void
-cli_func_ping(struct cli *cli, char **av, void *priv __unused)
+m_cli_func_ping(struct cli *cli, char **av, void *priv __unused)
{
time_t t;
/*--------------------------------------------------------------------*/
+static void
+m_cli_func_stats(struct cli *cli, char **av, void *priv __unused)
+{
+
+ assert (VSL_stats != NULL);
+#define MAC_STAT(n,t,f,d) \
+ cli_out(cli, "%12ju " d "\n", (VSL_stats->n));
+#include "stat_field.h"
+#undef MAC_STAT
+}
+
+/*--------------------------------------------------------------------*/
+
static struct cli_proto cli_proto[] = {
/* URL manipulation */
- { CLI_URL_QUERY, cli_func_passthrough, NULL },
- { CLI_URL_PURGE, cli_func_passthrough, NULL },
- { CLI_URL_STATUS, cli_func_passthrough, NULL },
+ { CLI_URL_QUERY, m_cli_func_passthrough, NULL },
+ { CLI_URL_PURGE, m_cli_func_passthrough, NULL },
+ { CLI_URL_STATUS, m_cli_func_passthrough, NULL },
{ CLI_CONFIG_LOAD, m_cli_func_config_load, NULL },
- { CLI_CONFIG_INLINE, cli_func_config_inline, NULL },
- { CLI_CONFIG_UNLOAD, cli_func_passthrough, NULL },
- { CLI_CONFIG_LIST, cli_func_passthrough, NULL },
- { CLI_CONFIG_USE, cli_func_passthrough, NULL },
- { CLI_SERVER_FREEZE, cli_func_passthrough, NULL },
- { CLI_SERVER_THAW, cli_func_passthrough, NULL },
- { CLI_SERVER_SUSPEND, cli_func_passthrough, NULL },
- { CLI_SERVER_RESUME, cli_func_passthrough, NULL },
- { CLI_SERVER_STOP, cli_func_server_stop, NULL },
- { CLI_SERVER_START, cli_func_server_start, NULL },
+ { CLI_CONFIG_INLINE, m_cli_func_config_inline, NULL },
+ { CLI_CONFIG_UNLOAD, m_cli_func_passthrough, NULL },
+ { CLI_CONFIG_LIST, m_cli_func_passthrough, NULL },
+ { CLI_CONFIG_USE, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_FREEZE, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_THAW, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_SUSPEND, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_RESUME, m_cli_func_passthrough, NULL },
+ { CLI_SERVER_STOP, m_cli_func_server_stop, NULL },
+ { CLI_SERVER_START, m_cli_func_server_start, NULL },
{ CLI_SERVER_RESTART },
- { CLI_PING, cli_func_ping, NULL },
- { CLI_STATS },
+ { CLI_PING, m_cli_func_ping, NULL },
+ { CLI_STATS, m_cli_func_stats, NULL },
{ CLI_ZERO },
{ CLI_HELP, cli_func_help, cli_proto },
- { CLI_VERBOSE, cli_func_verbose, NULL },
+ { CLI_VERBOSE, m_cli_func_verbose, NULL },
{ CLI_EXIT },
{ CLI_QUIT },
{ CLI_BYE },
/*--------------------------------------------------------------------*/
-#include "shmlog.h"
-
-static void
-init_vsl(const char *fn, unsigned size)
-{
- struct shmloghead slh;
- int i;
-
- heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600);
- if (heritage.vsl_fd < 0) {
- fprintf(stderr, "Could not open %s: %s\n",
- fn, strerror(errno));
- exit (1);
- }
- i = read(heritage.vsl_fd, &slh, sizeof slh);
- if (i == sizeof slh && slh.magic == SHMLOGHEAD_MAGIC) {
- /* XXX more checks */
- heritage.vsl_size = slh.size + slh.start;
- return;
- }
- slh.magic = SHMLOGHEAD_MAGIC;
- slh.size = size;
- slh.ptr = 0;
- slh.start = sizeof slh;
- AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
- i = write(heritage.vsl_fd, &slh, sizeof slh);
- assert(i == sizeof slh);
- AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
- heritage.vsl_size = slh.size + slh.start;
-}
-
-/*--------------------------------------------------------------------*/
-
/* for development purposes */
#include <printf.h>
#include <err.h>
*/
open_tcp(portnumber);
- init_vsl(SHMLOG_FILENAME, 1024*1024);
+ VSL_MgtInit(SHMLOG_FILENAME, 1024*1024);
testme();