<commit_before>/*
 * $Id$
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>

#include <cli.h>
#include <cli_priv.h>

#include "libvarnish.h"
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
#include "cli_event.h"

static struct event ev_keepalive;

struct stevedore	*stevedore;

pthread_mutex_t	sessmtx;
struct varnish_stats *VSL_stats;

/*--------------------------------------------------------------------*/

static void
timer_keepalive(int a, short b, void *c)
{

	printf("%s(%d, %d, %p)\n", __func__, a, (int)b, c);
	printf("Heeellloooo ?   Ohh bother...\n");
	exit (1);
}

static void
arm_keepalive(void)
{
	struct timeval tv;

	tv.tv_sec = 30;
	tv.tv_usec = 0;

	evtimer_del(&ev_keepalive);
	evtimer_add(&ev_keepalive, &tv);
}

/*--------------------------------------------------------------------*/

static void
cli_func_url_query(struct cli *cli, char **av, void *priv)
{

	(void)priv;
	cli_out(cli, "url <%s>", av[2]);
	cli_result(cli, CLIS_UNIMPL);
}

/*--------------------------------------------------------------------*/

static void
cli_func_ping(struct cli *cli, char **av, void *priv)
{
	time_t t;

	(void)priv;
	VSL(SLT_CLI, 0, av[1]);
	arm_keepalive();
	if (av[2] != NULL) {
		/* XXX: check clock skew is pointless here */
	}
	time(&t);
	cli_out(cli, "PONG %ld\n", t);
}

/*--------------------------------------------------------------------*/

static struct cli_proto cli_proto[] = {
	{ CLI_URL_QUERY,	cli_func_url_query },
	{ CLI_URL_PURGE,	cli_func_url_purge },
	{ CLI_CONFIG_LOAD,	cli_func_config_load },
	{ CLI_CONFIG_LIST,	cli_func_config_list },
	{ CLI_CONFIG_UNLOAD,	cli_func_config_unload },
	{ CLI_CONFIG_USE,	cli_func_config_use },
	{ CLI_PING,		cli_func_ping },
	{ NULL }
};

/*--------------------------------------------------------------------
 * XXX: Think more about which order we start things
 */

void
child_main(void)
{
	struct event_base *eb;
	struct cli *cli;
	int i;

	/* XXX: SO_NOSIGPIPE does not work reliably :-( */
	signal(SIGPIPE, SIG_IGN);

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);
	printf("Child starts\n");

	CVCL_Load(heritage.vcl_file, "boot");
	AZ(pthread_mutex_init(&sessmtx, NULL));
	VBE_Init();
	VSL_Init();
	WRK_Init();

	VCA_Init();
	EXP_Init();
	HSH_Init();
	BAN_Init();

	eb = event_init();
	assert(eb != NULL);

	stevedore = heritage.stevedore;
	if (stevedore->open != NULL)
		stevedore->open(stevedore);

	cli = cli_setup(eb, heritage.fds[2], heritage.fds[1], 0, cli_proto);

	evtimer_set(&ev_keepalive, timer_keepalive, NULL);
	event_base_set(eb, &ev_keepalive);
	arm_keepalive();

	i = event_base_loop(eb, 0);
	if (i != 0)
		printf("event_dispatch() = %d\n", i);

	printf("Child dies\n");
}
<commit_msg>Add a printf when cached is ready for the benefit of varnishtester<commit_after>/*
 * $Id$
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>

#include <cli.h>
#include <cli_priv.h>

#include "libvarnish.h"
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
#include "cli_event.h"

static struct event ev_keepalive;

struct stevedore	*stevedore;

pthread_mutex_t	sessmtx;
struct varnish_stats *VSL_stats;

/*--------------------------------------------------------------------*/

static void
timer_keepalive(int a, short b, void *c)
{

	printf("%s(%d, %d, %p)\n", __func__, a, (int)b, c);
	printf("Heeellloooo ?   Ohh bother...\n");
	exit (1);
}

static void
arm_keepalive(void)
{
	struct timeval tv;

	tv.tv_sec = 30;
	tv.tv_usec = 0;

	evtimer_del(&ev_keepalive);
	evtimer_add(&ev_keepalive, &tv);
}

/*--------------------------------------------------------------------*/

static void
cli_func_url_query(struct cli *cli, char **av, void *priv)
{

	(void)priv;
	cli_out(cli, "url <%s>", av[2]);
	cli_result(cli, CLIS_UNIMPL);
}

/*--------------------------------------------------------------------*/

static void
cli_func_ping(struct cli *cli, char **av, void *priv)
{
	time_t t;

	(void)priv;
	VSL(SLT_CLI, 0, av[1]);
	arm_keepalive();
	if (av[2] != NULL) {
		/* XXX: check clock skew is pointless here */
	}
	time(&t);
	cli_out(cli, "PONG %ld\n", t);
}

/*--------------------------------------------------------------------*/

static struct cli_proto cli_proto[] = {
	{ CLI_URL_QUERY,	cli_func_url_query },
	{ CLI_URL_PURGE,	cli_func_url_purge },
	{ CLI_CONFIG_LOAD,	cli_func_config_load },
	{ CLI_CONFIG_LIST,	cli_func_config_list },
	{ CLI_CONFIG_UNLOAD,	cli_func_config_unload },
	{ CLI_CONFIG_USE,	cli_func_config_use },
	{ CLI_PING,		cli_func_ping },
	{ NULL }
};

/*--------------------------------------------------------------------
 * XXX: Think more about which order we start things
 */

void
child_main(void)
{
	struct event_base *eb;
	struct cli *cli;
	int i;

	/* XXX: SO_NOSIGPIPE does not work reliably :-( */
	signal(SIGPIPE, SIG_IGN);

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);
	printf("Child starts\n");

	CVCL_Load(heritage.vcl_file, "boot");
	AZ(pthread_mutex_init(&sessmtx, NULL));
	VBE_Init();
	VSL_Init();
	WRK_Init();

	VCA_Init();
	EXP_Init();
	HSH_Init();
	BAN_Init();

	eb = event_init();
	assert(eb != NULL);

	stevedore = heritage.stevedore;
	if (stevedore->open != NULL)
		stevedore->open(stevedore);

	cli = cli_setup(eb, heritage.fds[2], heritage.fds[1], 0, cli_proto);

	evtimer_set(&ev_keepalive, timer_keepalive, NULL);
	event_base_set(eb, &ev_keepalive);
	arm_keepalive();

	printf("Ready\n");
	i = event_base_loop(eb, 0);
	if (i != 0)
		printf("event_dispatch() = %d\n", i);

	printf("Child dies\n");
}

{'fraction_non_alphanumeric': 0.27106359847798517, 'fraction_numerical': 0.004710998369269795, 'mean_word_length': 2.6244254760341432, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2940622', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2140, 'n_words': 436}