dovecot-2.0: dict server works again.

dovecot at dovecot.org dovecot at dovecot.org
Fri May 29 19:34:04 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/aa08a4506d89
changeset: 9405:aa08a4506d89
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 29 12:33:58 2009 -0400
description:
dict server works again.

diffstat:

6 files changed, 54 insertions(+), 116 deletions(-)
dovecot-master-example.conf |    9 +++
src/dict/Makefile.am        |    7 +-
src/dict/dict-settings.c    |   30 ----------
src/dict/dict-settings.h    |    3 -
src/dict/main.c             |  119 +++++++++++++------------------------------
src/lib-dict/dict-client.h  |    2 

diffs (284 lines):

diff -r 11b8d0210b7a -r aa08a4506d89 dovecot-master-example.conf
--- a/dovecot-master-example.conf	Thu May 28 14:42:21 2009 -0400
+++ b/dovecot-master-example.conf	Fri May 29 12:33:58 2009 -0400
@@ -113,3 +113,12 @@ service lmtp {
     mode = 0666
   }
 }
+
+service dict {
+  executable = dict
+
+  unix_listener {
+    path = dict
+    mode = 0666
+  }
+}
diff -r 11b8d0210b7a -r aa08a4506d89 src/dict/Makefile.am
--- a/src/dict/Makefile.am	Thu May 28 14:42:21 2009 -0400
+++ b/src/dict/Makefile.am	Fri May 29 12:33:58 2009 -0400
@@ -4,6 +4,7 @@ pkglibexec_PROGRAMS = dict
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
+	-I$(top_srcdir)/src/lib-master \
 	-I$(top_srcdir)/src/lib-settings \
 	-I$(top_srcdir)/src/lib-dict \
 	-I$(top_srcdir)/src/lib-sql \
@@ -25,10 +26,12 @@ dict_DEPENDENCIES = $(libs)
 dict_DEPENDENCIES = $(libs)
 
 dict_SOURCES = \
-	dict-server.c \
+	dict-connection.c \
+	dict-commands.c \
 	dict-settings.c \
 	main.c
 
 noinst_HEADERS = \
-	dict-server.h \
+	dict-connection.h \
+	dict-commands.h \
 	dict-settings.h
diff -r 11b8d0210b7a -r aa08a4506d89 src/dict/dict-settings.c
--- a/src/dict/dict-settings.c	Thu May 28 14:42:21 2009 -0400
+++ b/src/dict/dict-settings.c	Fri May 29 12:33:58 2009 -0400
@@ -33,33 +33,3 @@ struct setting_parser_info dict_setting_
 };
 
 struct dict_settings *dict_settings;
-
-static pool_t settings_pool = NULL;
-
-struct dict_settings *dict_settings_read(void)
-{
-	struct setting_parser_context *parser;
-	struct dict_settings *set;
-	const char *error;
-
-	if (settings_pool == NULL)
-		settings_pool = pool_alloconly_create("auth settings", 1024);
-	else
-		p_clear(settings_pool);
-
-	parser = settings_parser_init(settings_pool,
-				      &dict_setting_parser_info,
-				      SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS);
-
-	if (settings_parse_environ(parser) < 0) {
-		i_fatal("Error reading configuration: %s",
-			settings_parser_get_error(parser));
-	}
-
-	if (!settings_parser_check(parser, settings_pool, &error))
-		i_fatal("Invalid settings: %s", error);
-
-	set = settings_parser_get(parser);
-	settings_parser_deinit(&parser);
-	return set;
-}
diff -r 11b8d0210b7a -r aa08a4506d89 src/dict/dict-settings.h
--- a/src/dict/dict-settings.h	Thu May 28 14:42:21 2009 -0400
+++ b/src/dict/dict-settings.h	Fri May 29 12:33:58 2009 -0400
@@ -6,8 +6,7 @@ struct dict_settings {
 	ARRAY_DEFINE(dicts, const char *);
 };
 
+extern struct setting_parser_info dict_setting_parser_info;
 extern struct dict_settings *dict_settings;
 
-struct dict_settings *dict_settings_read(void);
-
 #endif
diff -r 11b8d0210b7a -r aa08a4506d89 src/dict/main.c
--- a/src/dict/main.c	Thu May 28 14:42:21 2009 -0400
+++ b/src/dict/main.c	Fri May 29 12:33:58 2009 -0400
@@ -1,55 +1,30 @@
 /* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "lib-signals.h"
-#include "ioloop.h"
-#include "env-util.h"
-#include "fd-close-on-exec.h"
 #include "restrict-access.h"
 #include "randgen.h"
+#include "env-util.h"
+#include "module-dir.h"
+#include "master-service.h"
+#include "master-service-settings.h"
 #include "sql-api.h"
 #include "dict.h"
 #include "dict-client.h"
-#include "dict-server.h"
+#include "dict-connection.h"
 #include "dict-settings.h"
-#include "module-dir.h"
 
 #include <stdlib.h>
 #include <unistd.h>
 
-#define DICT_MASTER_LISTENER_FD 3
+static struct module *modules;
 
-static struct ioloop *ioloop;
-static struct io *log_io;
-static struct module *modules;
-static struct dict_server *dict_server;
-
-static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED)
+static void client_connected(const struct master_service_connection *conn)
 {
-	/* warn about being killed because of some signal, except SIGINT (^C)
-	   which is too common at least while testing :) */
-	if (si->si_signo != SIGINT) {
-		i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)",
-			  si->si_signo, dec2str(si->si_pid),
-			  dec2str(si->si_uid),
-			  lib_signal_code_to_str(si->si_signo, si->si_code));
-	}
-	io_loop_stop(ioloop);
+	dict_connection_create(conn->fd);
 }
 
-static void log_error_callback(void *context ATTR_UNUSED)
+static void main_preinit(void)
 {
-	/* the log fd is closed, don't die when trying to log later */
-	i_set_failure_ignore_errors(TRUE);
-
-	io_loop_stop(ioloop);
-}
-
-static void drop_privileges(void)
-{
-	/* Log file or syslog opening probably requires roots */
-	i_set_failure_internal();
-
 	/* Maybe needed. Have to open /dev/urandom before possible
 	   chrooting. */
 	random_init();
@@ -64,23 +39,10 @@ static void drop_privileges(void)
 
 static void main_init(void)
 {
-	const char *version, *path;
-	int fd;
+	void **sets;
 
-	version = getenv("DOVECOT_VERSION");
-	if (version != NULL && strcmp(version, PACKAGE_VERSION) != 0) {
-		i_fatal("Dovecot version mismatch: "
-			"Master is v%s, dict is v"PACKAGE_VERSION" "
-			"(if you don't care, set version_ignore=yes)", version);
-	}
-
-	lib_signals_init();
-        lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
-        lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
-        lib_signals_ignore(SIGPIPE, TRUE);
-        lib_signals_ignore(SIGALRM, FALSE);
-
-	dict_settings = dict_settings_read();
+	sets = master_service_settings_get_others(master_service);
+	dict_settings = sets[0];
 
 	if (*dict_settings->dict_db_config != '\0') {
 		/* for berkeley db library */
@@ -88,58 +50,53 @@ static void main_init(void)
 				    NULL));
 	}
 
-	/* If master dies, the log fd gets closed and we'll quit */
-	log_io = io_add(STDERR_FILENO, IO_ERROR, log_error_callback, NULL);
-
-	modules = module_dir_load(DICT_MODULE_DIR, NULL, TRUE, version);
+	modules = module_dir_load(DICT_MODULE_DIR, NULL, TRUE,
+			master_service_get_version_string(master_service));
 	module_dir_init(modules);
 
 	/* Register only after loading modules. They may contain SQL drivers,
 	   which we'll need to register. */
 	dict_drivers_register_all();
-
-	path = getenv("DICT_LISTEN_FROM_FD");
-	fd = path == NULL ? -1 : DICT_MASTER_LISTENER_FD;
-	if (path == NULL)
-		path = DEFAULT_DICT_SERVER_SOCKET_PATH;
-
-	dict_server = dict_server_init(path, fd);
 }
 
 static void main_deinit(void)
 {
-	io_remove(&log_io);
-	dict_server_deinit(dict_server);
-
+	dict_connections_destroy_all();
 	module_dir_unload(&modules);
 
 	dict_drivers_unregister_all();
 
 	sql_drivers_deinit();
 	random_deinit();
-	lib_signals_deinit();
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
-#ifdef DEBUG
-	if (getenv("GDB") == NULL)
-		fd_debug_verify_leaks(DICT_MASTER_LISTENER_FD+1, 1024);
-#endif
+	const struct setting_parser_info *set_roots[] = {
+		&dict_setting_parser_info,
+		NULL
+	};
+	const char *error;
+	int c;
 
-	/* NOTE: we start rooted, so keep the code minimal until
-	   restrict_access_by_env() is called */
-	lib_init();
-	drop_privileges();
+	master_service = master_service_init("dict", 0, argc, argv);
+	while ((c = getopt(argc, argv, master_service_getopt_string())) > 0) {
+		if (!master_service_parse_option(master_service, c, optarg))
+			exit(FATAL_DEFAULT);
+	}
 
-	ioloop = io_loop_create();
+	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, "dict: ", 0);
+	main_preinit();
+	master_service_init_finish(master_service);
 
 	main_init();
-        io_loop_run(ioloop);
+	master_service_run(master_service, client_connected);
+
 	main_deinit();
-
-	io_loop_destroy(&ioloop);
-	lib_deinit();
-
-	return 0;
+	master_service_deinit(&master_service);
+        return 0;
 }
diff -r 11b8d0210b7a -r aa08a4506d89 src/lib-dict/dict-client.h
--- a/src/lib-dict/dict-client.h	Thu May 28 14:42:21 2009 -0400
+++ b/src/lib-dict/dict-client.h	Fri May 29 12:33:58 2009 -0400
@@ -3,7 +3,7 @@
 
 #include "dict.h"
 
-#define DEFAULT_DICT_SERVER_SOCKET_PATH PKG_RUNDIR"/dict-server"
+#define DEFAULT_DICT_SERVER_SOCKET_PATH PKG_RUNDIR"/dict"
 
 #define DICT_CLIENT_PROTOCOL_MAJOR_VERSION 2
 #define DICT_CLIENT_PROTOCOL_MINOR_VERSION 0


More information about the dovecot-cvs mailing list