<commit_before>/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "restrict-access.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "settings-parser.h"
#include "client-connection.h"
#include "doveadm-settings.h"
#include "doveadm-mail.h"
#include "doveadm-print-private.h"
#include "doveadm-server.h"

const struct doveadm_print_vfuncs *doveadm_print_vfuncs_all[] = {
	&doveadm_print_server_vfuncs,
	NULL
};

struct client_connection *doveadm_client;
int doveadm_exit_code = 0;

static void doveadm_die(void)
{
	/* do nothing. doveadm connections should be over soon. */
}

static void client_connected(struct master_service_connection *conn)
{
	if (doveadm_client != NULL) {
		i_error("doveadm server can handle only a single client");
		return;
	}

	master_service_client_connection_accept(conn);
	doveadm_client = client_connection_create(conn->fd, conn->listen_fd);
}

static void main_preinit(void)
{
	restrict_access_by_env(NULL, FALSE);
	restrict_access_allow_coredumps(TRUE);
}

static void main_init(void)
{
	doveadm_server = TRUE;
	doveadm_settings = master_service_settings_get_others(master_service)[0];
	doveadm_settings = settings_dup(&doveadm_setting_parser_info,
					doveadm_settings,
					pool_datastack_create());

	doveadm_mail_init();
	doveadm_load_modules();
	doveadm_print_init(DOVEADM_PRINT_TYPE_SERVER);
}

static void main_deinit(void)
{
	if (doveadm_client != NULL)
		client_connection_destroy(&doveadm_client);
	doveadm_mail_deinit();
	doveadm_unload_modules();
}

int main(int argc, char *argv[])
{
	const struct setting_parser_info *set_roots[] = {
		&doveadm_setting_parser_info,
		NULL
	};
	const char *error;

	master_service = master_service_init("doveadm", 0, &argc, &argv, NULL);
	if (master_getopt(master_service) > 0)
		return FATAL_DEFAULT;

	if (master_service_settings_read_simple(master_service, set_roots,
						&error) < 0)
		i_fatal("Error reading configuration: %s", error);

	master_service_init_log(master_service, "doveadm: ");
	main_preinit();
	master_service_init_finish(master_service);
	master_service_set_die_callback(master_service, doveadm_die);

	main_init();
	master_service_run(master_service, client_connected);

	main_deinit();
	master_service_deinit(&master_service);
        return 0;
}
<commit_msg>doveadm server: Keep config socket open while running.<commit_after>/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "restrict-access.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "settings-parser.h"
#include "client-connection.h"
#include "doveadm-settings.h"
#include "doveadm-mail.h"
#include "doveadm-print-private.h"
#include "doveadm-server.h"

const struct doveadm_print_vfuncs *doveadm_print_vfuncs_all[] = {
	&doveadm_print_server_vfuncs,
	NULL
};

struct client_connection *doveadm_client;
int doveadm_exit_code = 0;

static void doveadm_die(void)
{
	/* do nothing. doveadm connections should be over soon. */
}

static void client_connected(struct master_service_connection *conn)
{
	if (doveadm_client != NULL) {
		i_error("doveadm server can handle only a single client");
		return;
	}

	master_service_client_connection_accept(conn);
	doveadm_client = client_connection_create(conn->fd, conn->listen_fd);
}

static void main_preinit(void)
{
	restrict_access_by_env(NULL, FALSE);
	restrict_access_allow_coredumps(TRUE);
}

static void main_init(void)
{
	doveadm_server = TRUE;
	doveadm_settings = master_service_settings_get_others(master_service)[0];
	doveadm_settings = settings_dup(&doveadm_setting_parser_info,
					doveadm_settings,
					pool_datastack_create());

	doveadm_mail_init();
	doveadm_load_modules();
	doveadm_print_init(DOVEADM_PRINT_TYPE_SERVER);
}

static void main_deinit(void)
{
	if (doveadm_client != NULL)
		client_connection_destroy(&doveadm_client);
	doveadm_mail_deinit();
	doveadm_unload_modules();
}

int main(int argc, char *argv[])
{
	const struct setting_parser_info *set_roots[] = {
		&doveadm_setting_parser_info,
		NULL
	};
	enum master_service_flags service_flags =
		MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN;
	const char *error;

	master_service = master_service_init("doveadm", service_flags,
					     &argc, &argv, NULL);
	if (master_getopt(master_service) > 0)
		return FATAL_DEFAULT;

	if (master_service_settings_read_simple(master_service, set_roots,
						&error) < 0)
		i_fatal("Error reading configuration: %s", error);

	master_service_init_log(master_service, "doveadm: ");
	main_preinit();
	master_service_init_finish(master_service);
	master_service_set_die_callback(master_service, doveadm_die);

	main_init();
	master_service_run(master_service, client_connected);

	main_deinit();
	master_service_deinit(&master_service);
        return 0;
}

{'fraction_non_alphanumeric': 0.10757136946628051, 'fraction_numerical': 0.005585436491518411, 'mean_word_length': 6.662440570522979, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3993028', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1719, 'n_words': 315}