main.c revision 958e5ae51a755558b6d022a39b194614726b4225
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic ARRAY(enum director_socket_type) listener_socket_types;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void director_refresh_proctitle_timeout(void *context ATTR_UNUSED)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen static uint64_t prev_requests = 0, prev_input = 0, prev_output;
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainen str_printfa(str, "[%u users", user_directory_count(director->users));
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen (unsigned long)(director->num_requests - prev_requests));
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen (unsigned long long)(director->ring_traffic_input - prev_input)/1024,
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen (unsigned long long)(director->ring_traffic_output - prev_output)/1024);
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainendirector_socket_type_get_from_name(const char *path)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenlistener_get_socket_type_fallback(int listen_fd)
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen if (net_getsockname(listen_fd, NULL, &local_port) == 0 &&
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* TCP/IP connection */
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainenstatic void listener_sockets_init(struct ip_addr *listen_ip_r,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unsigned int i, socket_count;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen socket_count = master_service_get_socket_count(master_service);
242abe3ad2423776e9cf05e1304eb8fda4831b23Timo Sirainen for (i = 0; i < socket_count; i++) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen name = master_service_get_socket_name(master_service, listen_fd);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen type = director_socket_type_get_from_name(name);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* mainly for backwards compatibility */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen type = listener_get_socket_type_fallback(listen_fd);
b6b9c99fefbbc662bd9a0006566133c4480bf0e8Timo Sirainen if (type == DIRECTOR_SOCKET_TYPE_RING && *listen_port_r == 0 &&
b6b9c99fefbbc662bd9a0006566133c4480bf0e8Timo Sirainen net_getsockname(listen_fd, &ip, &port) == 0 && port > 0) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen array_idx_set(&listener_socket_types, listen_fd, &type);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic int director_client_connected(int fd, const struct ip_addr *ip)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen i_warning("Connection from %s: Server not listed in "
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen "director_servers, dropping", net_ip2addr(ip));
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen (void)director_connection_init_in(director, fd, ip);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void client_connected(struct master_service_connection *conn)
edd318d5866ac3fbc6e8df28fb24a4dfef93c884Timo Sirainen i_error("Received another proxy-notify connection");
69b22a0c0c84087e5bdeec71faae7ea77295240fTimo Sirainen master_service_client_connection_accept(conn);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen notify_conn = notify_connection_init(director, conn->fd);
8dd76854cc680053986142d5f5e823f637447929Timo Sirainen typep = array_idx(&listener_socket_types, conn->listen_fd);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* a) userdb connection, probably for lmtp proxy
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen b) login connection
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen Both of them are handled exactly the same, except for which
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen auth socket they connect to. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen userdb = *typep == DIRECTOR_SOCKET_TYPE_USERDB;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen socket_path = userdb ? AUTH_USERDB_SOCKET_PATH :
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen master_service_client_connection_accept(conn);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen (void)login_connection_init(director, conn->fd, auth,
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen master_service_client_connection_accept(conn);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen (void)login_connection_init(director, conn->fd, NULL,
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen if (director_client_connected(conn->fd, &conn->remote_ip) == 0)
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen master_service_client_connection_accept(conn);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen master_service_client_connection_accept(conn);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen (void)doveadm_connection_init(director, conn->fd);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void director_state_changed(struct director *dir)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ARRAY(struct director_request *) new_requests;
1df39b899804fd1dbc560f75382364822935c857Timo Sirainen if (!dir->ring_synced || !mail_hosts_have_usable(dir->mail_hosts))
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen /* if there are any pending client requests, finish them now */
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen array_foreach(&dir->pending_requests, requestp) {
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen /* a) request for a user being killed
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen b) user is weak */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen array_append_array(&dir->pending_requests, &new_requests);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if (dir->to_request != NULL && array_count(&new_requests) == 0)
static void main_preinit(void)
(void *)NULL);
static void main_deinit(void)
const char *error;
return FATAL_DEFAULT;
&error) < 0)
main_preinit();
main_deinit();