main.c revision 47a5a7e8296f3b8f2fac9a0659d4de3f2723ba4a
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2010-2017 Dovecot authors, see the included COPYING file */
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainenstatic ARRAY(enum director_socket_type) listener_socket_types;
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainenstatic unsigned int director_total_users_count(void)
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen unsigned int count = 0;
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen array_foreach(mail_hosts_get_tags(director->mail_hosts), tagp)
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen count += user_directory_count((*tagp)->users);
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainenstatic void director_refresh_proctitle_timeout(void *context ATTR_UNUSED)
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen static uint64_t prev_requests = 0, prev_input = 0, prev_output;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen str_printfa(str, "[%u users", director_total_users_count());
8e7da21696c9f8a6d5e601243fb6172ec85d47b2Timo Sirainen str_printfa(str, ", %u moving", director->users_moving_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen str_printfa(str, ", %"PRIu64"+%"PRIu64" kB/s",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (director->ring_traffic_input - prev_input)/1024,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (director->ring_traffic_output - prev_output)/1024);
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainendirector_socket_type_get_from_name(const char *path)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenlistener_get_socket_type_fallback(int listen_fd)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (net_getsockname(listen_fd, NULL, &local_port) == 0 &&
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* TCP/IP connection */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void listener_sockets_init(struct ip_addr *listen_ip_r,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int i, socket_count;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen socket_count = master_service_get_socket_count(master_service);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen for (i = 0; i < socket_count; i++) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen name = master_service_get_socket_name(master_service, listen_fd);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen type = director_socket_type_get_from_name(name);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* mainly for backwards compatibility */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen type = listener_get_socket_type_fallback(listen_fd);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (type == DIRECTOR_SOCKET_TYPE_RING && *listen_port_r == 0 &&
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen net_getsockname(listen_fd, &ip, &port) == 0 && port > 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen array_idx_set(&listener_socket_types, listen_fd, &type);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic int director_client_connected(int fd, const struct ip_addr *ip)
b9ce555e8624a5593b3bfd81b572b7d2e1e1fca5Timo Sirainen i_warning("Connection from %s: Server not listed in "
b9ce555e8624a5593b3bfd81b572b7d2e1e1fca5Timo Sirainen "director_servers, dropping", net_ip2addr(ip));
1b62b06d6fa688368f661b72d14de6518b5d1789Timo Sirainen (void)director_connection_init_in(director, fd, ip);
1b62b06d6fa688368f661b72d14de6518b5d1789Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen i_error("Received another proxy-notify connection");
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen master_service_client_connection_accept(conn);
633e6afa5de9ad8108ff8dbdee889ecf6170026eTimo Sirainen notify_conn = notify_connection_init(director, conn->fd);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen typep = array_idx(&listener_socket_types, conn->listen_fd);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* a) userdb connection, probably for lmtp proxy
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen b) login connection
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Both of them are handled exactly the same, except for which
5ec0ca7ff13595daf0d096c17100afb352e6294aTimo Sirainen auth socket they connect to. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen userdb = *typep == DIRECTOR_SOCKET_TYPE_USERDB;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen socket_path = userdb ? AUTH_USERDB_SOCKET_PATH :
bool ret;
if (!ret) {
static void main_preinit(void)
(void *)NULL);
static void main_deinit(void)
const char *error;
return FATAL_DEFAULT;
&error) < 0)
main_preinit();
main_deinit();