[dovecot-cvs] dovecot/src/master dict-process.c, 1.7, 1.7.2.1 dict-process.h, 1.1, 1.1.2.1 log.c, 1.7, 1.7.2.1 log.h, 1.3, 1.3.2.1 main.c, 1.80.2.4, 1.80.2.5 master-settings.c, 1.125.2.3, 1.125.2.4 master-settings.h, 1.83.2.1, 1.83.2.2

cras at dovecot.org cras at dovecot.org
Sat Jun 17 15:24:42 EEST 2006


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv18929/src/master

Modified Files:
      Tag: branch_1_0
	dict-process.c dict-process.h log.c log.h main.c 
	master-settings.c master-settings.h 
Log Message:
Instead of passing URIs directly to dictionary server, it now accepts only
named dictionaries which are configured in config file. SIGHUPing master now
restarts dict server.



Index: dict-process.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/dict-process.c,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -u -d -r1.7 -r1.7.2.1
--- dict-process.c	2 Feb 2006 21:29:15 -0000	1.7
+++ dict-process.c	17 Jun 2006 12:24:31 -0000	1.7.2.1
@@ -1,6 +1,7 @@
 /* Copyright (C) 2006 Timo Sirainen */
 
 #include "common.h"
+#include "array.h"
 #include "ioloop.h"
 #include "network.h"
 #include "fd-close-on-exec.h"
@@ -17,6 +18,8 @@
 struct dict_process {
 	char *path;
 	int fd;
+
+	struct log_io *log;
 	struct io *io;
 };
 
@@ -27,8 +30,9 @@
 static int dict_process_start(struct dict_process *process)
 {
 	struct log_io *log;
-	const char *executable;
-	int i, log_fd;
+	const char *executable, *const *dicts;
+	unsigned int i, count;
+	int log_fd;
 	pid_t pid;
 
 	log_fd = log_create_pipe(&log, 0);
@@ -51,6 +55,8 @@
 		log_set_prefix(log, "dict: ");
 		(void)close(log_fd);
 
+		process->log = log;
+		log_ref(process->log);
                 dict_process_unlisten(process);
 		return 0;
 	}
@@ -75,6 +81,11 @@
 	child_process_init_env();
 	env_put(t_strconcat("DICT_LISTEN_FROM_FD=", process->path, NULL));
 
+	dicts = array_get(&settings_root->dicts, &count);
+	i_assert((count % 2) == 0);
+	for (i = 0; i < count; i += 2)
+		env_put(t_strdup_printf("DICT_%s=%s", dicts[i], dicts[i+1]));
+
 	/* make sure we don't leak syslog fd, but do it last so that
 	   any errors above will be logged */
 	closelog();
@@ -89,6 +100,7 @@
 {
 	struct dict_process *process = context;
 
+	i_assert(process->log == NULL);
 	dict_process_start(process);
 }
 
@@ -157,6 +169,8 @@
 void dict_process_deinit(void)
 {
 	dict_process_unlisten(process);
+	if (process->log != NULL)
+		log_unref(process->log);
 	i_free(process->path);
 	i_free(process);
 }
@@ -166,3 +180,11 @@
 	dict_process_deinit();
 	dict_process_init();
 }
+
+void dict_process_kill(void)
+{
+	if (process->log != NULL) {
+		log_unref(process->log);
+		process->log = NULL;
+	}
+}

Index: dict-process.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/dict-process.h,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- dict-process.h	12 Jan 2006 10:54:27 -0000	1.1
+++ dict-process.h	17 Jun 2006 12:24:31 -0000	1.1.2.1
@@ -4,5 +4,6 @@
 void dict_process_init(void);
 void dict_process_deinit(void);
 void dict_process_restart(void);
+void dict_process_kill(void);
 
 #endif

Index: log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/log.c,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -u -d -r1.7 -r1.7.2.1
--- log.c	26 Feb 2006 10:05:27 -0000	1.7
+++ log.c	17 Jun 2006 12:24:31 -0000	1.7.2.1
@@ -10,6 +10,8 @@
 
 struct log_io {
 	struct log_io *prev, *next;
+	int refcount;
+
 	struct io *io;
 	struct istream *stream;
 
@@ -29,7 +31,6 @@
 
 static int log_it(struct log_io *log_io, const char *line, bool continues);
 static void log_read(void *context);
-static void log_io_free(struct log_io *log_io);
 static void log_throttle_timeout(void *context);
 
 static bool log_write_pending(struct log_io *log_io)
@@ -132,7 +133,7 @@
 	if (ret < 0) {
 		if (ret == -1) {
 			/* closed */
-			log_io_free(log_io);
+			log_unref(log_io);
 			return;
 		}
 
@@ -166,6 +167,7 @@
 	fd_close_on_exec(fd[1], TRUE);
 
 	log_io = i_new(struct log_io, 1);
+	log_io->refcount = 1;
 	log_io->stream = i_stream_create_file(fd[0], default_pool, 1024, TRUE);
 	log_io->max_lines_per_sec =
 		max_lines_per_sec != 0 ? max_lines_per_sec : (unsigned int)-1;
@@ -189,11 +191,19 @@
 	log->prefix = i_strdup(prefix);
 }
 
-static void log_io_free(struct log_io *log_io)
+void log_ref(struct log_io *log_io)
+{
+	log_io->refcount++;
+}
+
+static void log_close(struct log_io *log_io)
 {
 	const unsigned char *data;
 	size_t size;
 
+	if (log_io->destroying)
+		return;
+
 	/* if there was something in buffer, write it */
 	log_io->destroying = TRUE;
 	(void)log_write_pending(log_io);
@@ -218,6 +228,17 @@
 	else
 		throttle_count--;
 	i_stream_destroy(&log_io->stream);
+}
+
+void log_unref(struct log_io *log_io)
+{
+	i_assert(log_io->refcount > 0);
+
+	log_close(log_io);
+
+	if (--log_io->refcount > 0)
+		return;
+
 	i_free(log_io->prefix);
 	i_free(log_io);
 }
@@ -255,7 +276,7 @@
 
 	while (log_ios != NULL) {
 		next = log_ios->next;
-		log_io_free(log_ios);
+		log_unref(log_ios);
 		log_ios = next;
 	}
 

Index: log.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/log.h,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -d -r1.3 -r1.3.2.1
--- log.h	9 Jan 2005 20:12:35 -0000	1.3
+++ log.h	17 Jun 2006 12:24:31 -0000	1.3.2.1
@@ -6,6 +6,9 @@
 int log_create_pipe(struct log_io **log_r, unsigned int max_lines_per_sec);
 void log_set_prefix(struct log_io *log, const char *prefix);
 
+void log_ref(struct log_io *log_io);
+void log_unref(struct log_io *log_io);
+
 void log_init(void);
 void log_deinit(void);
 

Index: main.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/main.c,v
retrieving revision 1.80.2.4
retrieving revision 1.80.2.5
diff -u -d -r1.80.2.4 -r1.80.2.5
--- main.c	16 Jun 2006 18:13:41 -0000	1.80.2.4
+++ main.c	17 Jun 2006 12:24:31 -0000	1.80.2.5
@@ -136,6 +136,7 @@
 	/* restart auth and login processes */
         login_processes_destroy_all();
         auth_processes_destroy_all();
+        dict_process_kill();
 
 	if (!master_settings_read(configfile, FALSE))
 		i_warning("Invalid configuration, keeping old one");

Index: master-settings.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/master-settings.c,v
retrieving revision 1.125.2.3
retrieving revision 1.125.2.4
diff -u -d -r1.125.2.3 -r1.125.2.4
--- master-settings.c	16 Jun 2006 18:13:41 -0000	1.125.2.3
+++ master-settings.c	17 Jun 2006 12:24:31 -0000	1.125.2.4
@@ -30,6 +30,7 @@
 	SETTINGS_TYPE_AUTH_USERDB,
         SETTINGS_TYPE_NAMESPACE,
 	SETTINGS_TYPE_SOCKET,
+	SETTINGS_TYPE_DICT,
 	SETTINGS_TYPE_PLUGIN
 };
 
@@ -1071,6 +1072,13 @@
 		return parse_setting_from_defs(settings_pool,
 					       socket_setting_defs,
 					       ctx->socket, key, value);
+	case SETTINGS_TYPE_DICT:
+		key = p_strdup(settings_pool, key);
+		value = p_strdup(settings_pool, value);
+
+		array_append(&ctx->server->dicts, &key, 1);
+		array_append(&ctx->server->dicts, &value, 1);
+		return NULL;
 	case SETTINGS_TYPE_PLUGIN:
 		key = p_strdup(settings_pool, key);
 		value = p_strdup(settings_pool, value);
@@ -1109,6 +1117,7 @@
 	*server->imap = *imap_defaults;
 	*server->pop3 = *pop3_defaults;
 
+	ARRAY_CREATE(&server->dicts, settings_pool, const char *, 4);
 	ARRAY_CREATE(&server->imap->plugin_envs, settings_pool,
 		     const char *, 8);
 	ARRAY_CREATE(&server->pop3->plugin_envs, settings_pool,
@@ -1257,6 +1266,17 @@
 		return ctx->namespace != NULL;
 	}
 
+	if (strcmp(type, "dict") == 0) {
+		if (ctx->type != SETTINGS_TYPE_ROOT &&
+		    ctx->type != SETTINGS_TYPE_SERVER) {
+			*errormsg = "Plugin section not allowed here";
+			return FALSE;
+		}
+
+		ctx->type = SETTINGS_TYPE_DICT;
+		return TRUE;
+	}
+
 	if (strcmp(type, "plugin") == 0) {
 		if (ctx->type != SETTINGS_TYPE_ROOT &&
 		    ctx->type != SETTINGS_TYPE_SERVER) {

Index: master-settings.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/master-settings.h,v
retrieving revision 1.83.2.1
retrieving revision 1.83.2.2
diff -u -d -r1.83.2.1 -r1.83.2.2
--- master-settings.h	12 May 2006 13:00:54 -0000	1.83.2.1
+++ master-settings.h	17 Jun 2006 12:24:31 -0000	1.83.2.2
@@ -223,6 +223,8 @@
 	struct auth_settings auth_defaults;
         struct namespace_settings *namespaces;
 
+	array_t ARRAY_DEFINE(dicts, const char *);
+
 	gid_t login_gid;
 };
 



More information about the dovecot-cvs mailing list