bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2014-2018 Dovecot authors, see the included COPYING file */
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "lib.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "restrict-access.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "master-service.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "master-service-settings.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "imap-client.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "imap-hibernate-client.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen#include "imap-master-connection.h"
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic bool debug = FALSE;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen{
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen master_service_client_connection_accept(conn);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen imap_hibernate_client_create(conn->fd, debug);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen}
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainenint main(int argc, char *argv[])
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen{
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen enum master_service_flags service_flags =
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen MASTER_SERVICE_FLAG_UPDATE_PROCTITLE;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen const char *error;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen int c;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen master_service = master_service_init("imap-hibernate", service_flags,
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen &argc, &argv, "D");
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen while ((c = master_getopt(master_service)) > 0) {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen switch (c) {
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen case 'D':
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen debug = TRUE;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen break;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen default:
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen return FATAL_DEFAULT;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen }
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen }
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen if (master_service_settings_read_simple(master_service, NULL, &error) < 0)
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen i_fatal("Error reading configuration: %s", error);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen master_service_init_log(master_service, "imap-hibernate: ");
816d20be0cf95fc4eb1a8aa716639e73b8ba525eMartti Rannanjärvi restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen restrict_access_allow_coredumps(TRUE);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
17062405030a3fa095e43d5b8b71afc5536f0a22Timo Sirainen imap_clients_init();
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen imap_master_connections_init();
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen imap_hibernate_clients_init();
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen master_service_init_finish(master_service);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen master_service_run(master_service, client_connected);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen imap_master_connections_deinit();
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen imap_hibernate_clients_deinit();
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen imap_clients_deinit();
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen master_service_deinit(&master_service);
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen return 0;
5ef28f68edef46f69961b19b7c1dcd8ec5a955e8Timo Sirainen}