bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
db693bf6fcae96d834567f1782257517b7207655Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
c405d7235ba2e21a306eacc9fc0f15e66f9ee718Timo Sirainen bool master = conn->listen_fd == MASTER_LISTEN_FD_FIRST;
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen master_service_client_connection_accept(conn);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen (void)anvil_connection_create(conn->fd, master, conn->fifo);
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen /* master wants us to replace the log fd */
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen ret = fd_read(MASTER_ANVIL_LOG_FDPASS_FD, &c, 1, &fd);
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen else if (ret == 0) {
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen /* master died. lib-master should notice it soon. */
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen i_fatal("dup2(fd_read log fd, stderr) failed: %m");
737f6f1c3c591a47b8b48d54563d6ad1b694f256Timo Sirainen const enum master_service_flags service_flags =
737f6f1c3c591a47b8b48d54563d6ad1b694f256Timo Sirainen master_service = master_service_init("anvil", service_flags,
737f6f1c3c591a47b8b48d54563d6ad1b694f256Timo Sirainen if (master_service_settings_read_simple(master_service,
737f6f1c3c591a47b8b48d54563d6ad1b694f256Timo Sirainen i_fatal("Error reading configuration: %s", error);
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen master_service_init_log(master_service, "anvil: ");
816d20be0cf95fc4eb1a8aa716639e73b8ba525eMartti Rannanjärvi restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL);
ab96e72a574ff5e579500513cd62f14ec142e467Timo Sirainen anvil_restarted = getenv("ANVIL_RESTARTED") != NULL;
8787860a1e0519f19ac2cdc270cecd4673fad541Timo Sirainen /* delay dying until all of our clients are gone */
8787860a1e0519f19ac2cdc270cecd4673fad541Timo Sirainen master_service_set_die_with_master(master_service, FALSE);
230ef558135f16a66b86cbe3762524eaa9ae9d81Timo Sirainen log_fdpass_io = io_add(MASTER_ANVIL_LOG_FDPASS_FD, IO_READ,