main.c revision 237a6211c7fc4d6dbb58dd0467da6dba1b8f21f6
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen#include "lib.h"
76a58bc863893374000881e69d6dd4e3dccadddeTimo Sirainen#include "restrict-access.h"
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen#include "master-service.h"
76a58bc863893374000881e69d6dd4e3dccadddeTimo Sirainen#include "master-service-settings.h"
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen#include "settings-parser.h"
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen#include "client-connection.h"
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen#include "doveadm-settings.h"
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen#include "doveadm-mail.h"
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen#include "doveadm-print-private.h"
76d4ff1c1b31a1a09f6cbfe613a8d0efe62cbfd2Timo Sirainen#include "doveadm-server.h"
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainenconst struct doveadm_print_vfuncs *doveadm_print_vfuncs_all[] = {
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen &doveadm_print_server_vfuncs,
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainen NULL
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen};
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainenstruct client_connection *doveadm_client;
f1ed4fa248aaf6841ba638b9d66b2738d9f7aa18Timo Sirainenint doveadm_exit_code = 0;
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainenstatic void doveadm_die(void)
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen{
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen /* do nothing. doveadm connections should be over soon. */
be6ad6e46ecb8c7126b421819046e7f4857a2babTimo Sirainen}
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,
conn->ssl);
}
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();
doveadm_print_deinit();
}
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, "");
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;
}