dovecot-2.0: Require each service to have a unique name. Log ser...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 5 01:28:23 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/7b3accdf44f8
changeset: 9213:7b3accdf44f8
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 04 18:28:17 2009 -0400
description:
Require each service to have a unique name. Log service errors using service_error().

diffstat:

10 files changed, 105 insertions(+), 100 deletions(-)
src/master/master-settings.c     |   23 ++++++++++++++++++++---
src/master/master-settings.h     |    1 +
src/master/service-auth-server.c |   25 +++++++++++++------------
src/master/service-auth-source.c |   35 +++++++++++++++--------------------
src/master/service-listen.c      |   22 ++++++++++------------
src/master/service-log.c         |   14 +++++++-------
src/master/service-monitor.c     |   26 +++++++++++---------------
src/master/service-process.c     |   20 ++++++++++----------
src/master/service.c             |   35 +++++++++++++++--------------------
src/master/service.h             |    4 +++-

diffs (truncated from 559 to 300 lines):

diff -r 7b110aa9fac5 -r 7b3accdf44f8 src/master/master-settings.c
--- a/src/master/master-settings.c	Mon May 04 18:12:04 2009 -0400
+++ b/src/master/master-settings.c	Mon May 04 18:28:17 2009 -0400
@@ -82,6 +82,7 @@ static struct setting_parser_info inet_l
 
 static struct setting_define service_setting_defines[] = {
 	DEF(SET_INTERNAL, master_set),
+	DEF(SET_STR, name),
 	DEF(SET_STR, type),
 	DEF(SET_STR, executable),
 	DEF(SET_STR, user),
@@ -110,6 +111,7 @@ static struct service_settings service_d
 static struct service_settings service_default_settings = {
 	MEMBER(master_set) NULL,
 
+	MEMBER(name) "",
 	MEMBER(type) "",
 	MEMBER(executable) "",
 	MEMBER(user) "",
@@ -138,7 +140,7 @@ struct setting_parser_info service_setti
 	MEMBER(dynamic_parsers) NULL,
 
 	MEMBER(parent_offset) offsetof(struct service_settings, master_set),
-	MEMBER(type_offset) (size_t)-1,
+	MEMBER(type_offset) offsetof(struct service_settings, name),
 	MEMBER(struct_size) sizeof(struct service_settings)
 };
 
@@ -217,7 +219,7 @@ master_settings_verify(void *_set, pool_
 {
 	const struct master_settings *set = _set;
 	struct service_settings *const *services;
-	unsigned int i, count;
+	unsigned int i, j, count;
 
 	if (set->last_valid_uid != 0 &&
 	    set->first_valid_uid > set->last_valid_uid) {
@@ -238,6 +240,21 @@ master_settings_verify(void *_set, pool_
 		return FALSE;
 	}
 	for (i = 0; i < count; i++) {
+		if (*services[i]->name == '\0') {
+			*error_r = t_strdup_printf(
+				"Service #%d is missing name", i);
+			return FALSE;
+		}
+		for (j = 0; j < i; j++) {
+			if (strcmp(services[i]->name, services[j]->name) == 0) {
+				*error_r = t_strdup_printf(
+					"Duplicate service name: %s",
+					services[i]->name);
+				return FALSE;
+			}
+		}
+	}
+	for (i = 0; i < count; i++) {
 		if (*services[i]->executable != '/') {
 			services[i]->executable =
 				p_strconcat(pool, set->libexec_dir, "/",
@@ -253,7 +270,7 @@ master_settings_verify(void *_set, pool_
 		    *services[i]->chroot != '\0') {
 			*error_r = t_strdup_printf("service(%s): "
 				"drop_priv_before_exec=yes can't be "
-				"used with chroot", services[i]->executable);
+				"used with chroot", services[i]->name);
 			return FALSE;
 		}
 		fix_file_listener_paths(&services[i]->unix_listeners,
diff -r 7b110aa9fac5 -r 7b3accdf44f8 src/master/master-settings.h
--- a/src/master/master-settings.h	Mon May 04 18:12:04 2009 -0400
+++ b/src/master/master-settings.h	Mon May 04 18:28:17 2009 -0400
@@ -17,6 +17,7 @@ struct service_settings {
 struct service_settings {
 	struct master_settings *master_set;
 
+	const char *name;
 	const char *type;
 	const char *executable;
 	const char *user;
diff -r 7b110aa9fac5 -r 7b3accdf44f8 src/master/service-auth-server.c
--- a/src/master/service-auth-server.c	Mon May 04 18:12:04 2009 -0400
+++ b/src/master/service-auth-server.c	Mon May 04 18:28:17 2009 -0400
@@ -66,10 +66,10 @@ auth_process_lookup_request(struct servi
 
 	request = hash_table_lookup(process->auth_requests, POINTER_CAST(id));
 	if (request == NULL) {
-		i_error("service(%s): authentication service %s "
-			"sent reply with unknown ID %u",
-			process->process.service->name,
-			dec2str(process->process.pid), id);
+		service_error(process->process.service,
+			      "authentication service %s "
+			      "sent reply with unknown ID %u",
+			      dec2str(process->process.pid), id);
 		return NULL;
 	}
 
@@ -181,9 +181,10 @@ service_process_auth_server_input(struct
 		return;
 	case -2:
 		/* buffer full */
-		i_error("service(%s): authentication server process %s "
-			"sent us too long line", process->process.service->name,
-			dec2str(process->process.pid));
+		service_error(process->process.service,
+			      "authentication server process %s "
+			      "sent us too long line",
+			      dec2str(process->process.pid));
 		service_process_auth_server_close(process);
 		return;
 	}
@@ -197,11 +198,11 @@ service_process_auth_server_input(struct
 		if (strncmp(line, "VERSION\t", 8) != 0 ||
 		    atoi(t_strcut(line + 8, '\t')) !=
 		    AUTH_MASTER_PROTOCOL_MAJOR_VERSION) {
-			i_error("service(%s): authentication server process %s "
-				"not compatible with master process "
-				"(mixed old and new binaries?)",
-				process->process.service->name,
-				dec2str(process->process.pid));
+			service_error(process->process.service,
+				      "authentication server process %s "
+				      "not compatible with master process "
+				      "(mixed old and new binaries?)",
+				      dec2str(process->process.pid));
 			service_process_auth_server_close(process);
 			return;
 		}
diff -r 7b110aa9fac5 -r 7b3accdf44f8 src/master/service-auth-source.c
--- a/src/master/service-auth-source.c	Mon May 04 18:12:04 2009 -0400
+++ b/src/master/service-auth-source.c	Mon May 04 18:28:17 2009 -0400
@@ -128,22 +128,20 @@ auth_read_request(struct service_process
 			/* disconnected */
 		} else if (ret > 0) {
 			/* request wasn't fully read */
-			i_error("service(%s): fd_read() partial input (%d/%d)",
-				service->name, (int)ret, (int)sizeof(*req));
+			service_error(service, "fd_read() partial input (%d/%d)",
+				      (int)ret, (int)sizeof(*req));
 		} else {
 			if (errno == EAGAIN)
 				return 0;
 
-			i_error("service(%s): fd_read() failed: %m",
-				service->name);
+			service_error(service, "fd_read() failed: %m");
 		}
 		return -1;
 	}
 
 	if (req->data_size != 0) {
 		if (req->data_size > MASTER_AUTH_MAX_DATA_SIZE) {
-			i_error("service(%s): Too large auth data_size sent",
-				service->name);
+			service_error(service, "Too large auth data_size sent");
 			return -1;
 		}
 		/* @UNSAFE */
@@ -153,30 +151,28 @@ auth_read_request(struct service_process
 				/* disconnected */
 			} else if (ret > 0) {
 				/* request wasn't fully read */
-				i_error("service(%s): Data read partially %d/%u",
-					service->name, (int)ret, req->data_size);
+				service_error(service,
+					      "Data read partially %d/%u",
+					      (int)ret, req->data_size);
 			} else {
-				i_error("service(%s): read(data) failed: %m",
-					service->name);
+				service_error(service, "read(data) failed: %m");
 			}
 			return -1;
 		}
 	}
 
 	if (*client_fd_r == -1) {
-		i_error("service(%s): Auth request missing a file descriptor",
-			service->name);
+		service_error(service, "Auth request missing a file descriptor");
 		return -1;
 	}
 
 	if (fstat(*client_fd_r, &st) < 0) {
-		i_error("service(%s): fstat(auth dest fd) failed: %m",
-			service->name);
+		service_error(service, "fstat(auth dest fd) failed: %m");
 		return -1;
 	}
 	if (st.st_ino != req->ino) {
-		i_error("service(%s): Auth request inode mismatch: %s != %s",
-			service->name, dec2str(st.st_ino), dec2str(req->ino));
+		service_error(service, "Auth request inode mismatch: %s != %s",
+			      dec2str(st.st_ino), dec2str(req->ino));
 		return -1;
 	}
 	return 1;
@@ -210,9 +206,8 @@ service_process_auth_source_input(struct
 	/* we have a request. check its validity. */
 	auth_process = hash_table_lookup(service->list->pids, &req.auth_pid);
 	if (auth_process == NULL) {
-		i_error("service(%s): authentication request for unknown "
-			"auth server PID %s", service->name,
-			dec2str(req.auth_pid));
+		service_error(service, "authentication request for unknown "
+			      "auth server PID %s", dec2str(req.auth_pid));
 		service_process_auth_source_send_reply(process, req.tag, FALSE);
 		(void)close(client_fd);
 		return;
@@ -224,7 +219,7 @@ service_process_auth_source_input(struct
 		    ioloop_time - AUTH_BUSY_LOG_INTERVAL) {
 			i_warning("service(%s): authentication server PID "
 				  "%s too busy",
-				  auth_process->process.service->name,
+				  auth_process->process.service->set->name,
 				  dec2str(req.auth_pid));
                         auth_process->auth_busy_stamp = ioloop_time;
 		}
diff -r 7b110aa9fac5 -r 7b3accdf44f8 src/master/service-listen.c
--- a/src/master/service-listen.c	Mon May 04 18:12:04 2009 -0400
+++ b/src/master/service-listen.c	Mon May 04 18:28:17 2009 -0400
@@ -31,8 +31,8 @@ static int service_unix_listener_listen(
 		}
 
 		if (errno != EADDRINUSE) {
-			i_error("service(%s): net_listen_unix(%s) failed: %m",
-				service->name, set->path);
+			service_error(service, "net_listen_unix(%s) failed: %m",
+				      set->path);
 			return -1;
 		}
 
@@ -42,15 +42,15 @@ static int service_unix_listener_listen(
 		if (fd != -1 || errno != ECONNREFUSED || i >= 3) {
 			if (fd != -1)
 				(void)close(fd);
-			i_error("service(%s): Socket already exists: %s",
-				service->name, set->path);
+			service_error(service, "Socket already exists: %s",
+				      set->path);
 			return 0;
 		}
 
 		/* delete and try again */
 		if (unlink(set->path) < 0 && errno != ENOENT) {
-			i_error("service(%s): unlink(%s) failed: %m",
-				service->name, set->path);
+			service_error(service, "unlink(%s) failed: %m",
+				      set->path);
 			return -1;
 		}
 	}
@@ -88,15 +88,13 @@ static int service_fifo_listener_listen(
 	umask(old_umask);
 
 	if (ret < 0 && errno != EEXIST) {
-		i_error("service(%s): mkfifo(%s) failed: %m",
-			service->name, set->path);
+		service_error(service, "mkfifo(%s) failed: %m", set->path);
 		return -1;
 	}
 
 	fd = open(set->path, O_RDONLY);
 	if (fd == -1) {
-		i_error("service(%s): open(%s) failed: %m",
-			service->name, set->path);
+		service_error(service, "open(%s) failed: %m", set->path);
 		return -1;
 	}
 
@@ -127,8 +125,8 @@ static int service_inet_listener_listen(
 
 	fd = net_listen(&l->set.inetset.ip, &port, service->process_limit);
 	if (fd < 0) {
-		i_error("service(%s): listen(%s, %u) failed: %m",
-			service->name, set->address, set->port);
+		service_error(service, "listen(%s, %u) failed: %m",
+			      set->address, set->port);
 		return errno == EADDRINUSE ? 0 : -1;
 	}
 	net_set_nonblock(fd, TRUE);
diff -r 7b110aa9fac5 -r 7b3accdf44f8 src/master/service-log.c
--- a/src/master/service-log.c	Mon May 04 18:12:04 2009 -0400
+++ b/src/master/service-log.c	Mon May 04 18:28:17 2009 -0400
@@ -37,12 +37,12 @@ int services_log_init(struct service_lis
 		fd_close_on_exec(services[i]->log_fd[0], TRUE);
 		fd_close_on_exec(services[i]->log_fd[1], TRUE);
 
-		handshake.prefix_len = strlen(services[i]->name) + 2;
+		handshake.prefix_len = strlen(services[i]->set->name) + 2;
 
 		buffer_set_used_size(handshake_buf, 0);
 		buffer_append(handshake_buf, &handshake, sizeof(handshake));
-		buffer_append(handshake_buf, services[i]->name,
-			      strlen(services[i]->name));
+		buffer_append(handshake_buf, services[i]->set->name,
+			      strlen(services[i]->set->name));
 		buffer_append(handshake_buf, ": ", 2);
 
 		ret = write(services[i]->log_fd[1],


More information about the dovecot-cvs mailing list