dovecot-2.2: i_set_failure_prefix() now takes printf-like parame...

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 12 01:06:23 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/d00cf8e0dae7
changeset: 15201:d00cf8e0dae7
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 12 01:06:13 2012 +0300
description:
i_set_failure_prefix() now takes printf-like parameters.
This avoids using t_strdup_printf() with it, which was done very commonly.

diffstat:

 src/doveadm/doveadm-mail.c             |   2 +-
 src/doveadm/dsync/doveadm-dsync.c      |   8 +++-----
 src/imap-urlauth/imap-urlauth-client.c |   3 +--
 src/imap-urlauth/imap-urlauth-worker.c |  17 ++++++++---------
 src/lib-master/master-login.c          |   7 +++----
 src/lib-master/master-service.c        |  16 +++++++---------
 src/lib-storage/mail-storage-service.c |   4 ++--
 src/lib/failures.c                     |  19 +++++++++++++++----
 src/lib/failures.h                     |   4 +++-
 src/lmtp/commands.c                    |   5 ++---
 src/log/log-connection.c               |   2 +-
 src/master/main.c                      |   2 +-
 12 files changed, 47 insertions(+), 42 deletions(-)

diffs (294 lines):

diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/doveadm/doveadm-mail.c	Fri Oct 12 01:06:13 2012 +0300
@@ -276,7 +276,7 @@
 	const char *error;
 	int ret;
 
-	i_set_failure_prefix(t_strdup_printf("doveadm(%s): ", input->username));
+	i_set_failure_prefix("doveadm(%s): ", input->username);
 
 	/* see if we want to execute this command via (another)
 	   doveadm server */
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/doveadm/dsync/doveadm-dsync.c	Fri Oct 12 01:06:13 2012 +0300
@@ -238,7 +238,7 @@
 
 	i_assert(ctx->local_location != NULL);
 
-	i_set_failure_prefix(t_strdup_printf("dsync(%s): ", user->username));
+	i_set_failure_prefix("dsync(%s): ", user->username);
 
 	/* update mail_location and create another user for the
 	   second location. */
@@ -288,8 +288,7 @@
 static void
 cmd_dsync_run_remote(struct mail_user *user)
 {
-	i_set_failure_prefix(t_strdup_printf("dsync-local(%s): ",
-					     user->username));
+	i_set_failure_prefix("dsync-local(%s): ", user->username);
 	io_loop_run(current_ioloop);
 }
 
@@ -515,8 +514,7 @@
 	user->admin = TRUE;
 	user->dsyncing = TRUE;
 
-	i_set_failure_prefix(t_strdup_printf("dsync-remote(%s): ",
-					     user->username));
+	i_set_failure_prefix("dsync-remote(%s): ", user->username);
 
 	temp_prefix = t_str_new(64);
 	mail_user_set_get_temp_prefix(temp_prefix, user->set);
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/imap-urlauth/imap-urlauth-client.c
--- a/src/imap-urlauth/imap-urlauth-client.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-client.c	Fri Oct 12 01:06:13 2012 +0300
@@ -324,8 +324,7 @@
 
 void client_destroy(struct client *client, const char *reason)
 {
-	i_set_failure_prefix(t_strdup_printf("%s: ",
-		master_service_get_name(master_service)));
+	i_set_failure_prefix("%s: ", master_service_get_name(master_service));
 
 	if (!client->disconnected) {
 		if (reason == NULL)
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/imap-urlauth/imap-urlauth-worker.c
--- a/src/imap-urlauth/imap-urlauth-worker.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-worker.c	Fri Oct 12 01:06:13 2012 +0300
@@ -203,9 +203,8 @@
 	imap_urlauth_worker_client_count++;
 	DLLIST_PREPEND(&imap_urlauth_worker_clients, client);
 
-	i_set_failure_prefix(t_strdup_printf("imap-urlauth[%s](%s): ", my_pid,
-					     client->access_user));
-
+	i_set_failure_prefix("imap-urlauth[%s](%s): ",
+			     my_pid, client->access_user);
 	return client;
 }
 
@@ -219,8 +218,8 @@
 {
 	char **app;
 
-	i_set_failure_prefix(t_strdup_printf("imap-urlauth[%s](%s): ",
-					     my_pid, client->access_user));
+	i_set_failure_prefix("imap-urlauth[%s](%s): ",
+			     my_pid, client->access_user);
 
 	if (client->url != NULL) {
 		/* deinitialize url */
@@ -664,8 +663,8 @@
 			mail_user->username, client->access_user);
 	}
 
-	i_set_failure_prefix(t_strdup_printf("imap-urlauth[%s](%s->%s): ",
-		my_pid, client->access_user, mail_user->username));
+	i_set_failure_prefix("imap-urlauth[%s](%s->%s): ",
+			     my_pid, client->access_user, mail_user->username);
 
 	client_send_line(client, "OK");
 	return 1;
@@ -889,8 +888,8 @@
 		client->access_user = i_strdup("anonymous");
 		client->access_anonymous = TRUE;
 	}
-	i_set_failure_prefix(t_strdup_printf("imap-urlauth[%s](%s): ", my_pid,
-					     client->access_user));
+	i_set_failure_prefix("imap-urlauth[%s](%s): ",
+			     my_pid, client->access_user);
 
 	args++;
 	while (*args != NULL) {
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/lib-master/master-login.c
--- a/src/lib-master/master-login.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/lib-master/master-login.c	Fri Oct 12 01:06:13 2012 +0300
@@ -182,8 +182,7 @@
 			i_error("close(fd_read client) failed: %m");
 		/* this client failed (login callback wasn't called).
 		   reset prefix to default. */
-		i_set_failure_prefix(t_strdup_printf("%s: ",
-			client->conn->login->service->name));
+		i_set_failure_prefix("%s: ", client->conn->login->service->name);
 	}
 
 	/* FIXME: currently we create a separate connection for each request,
@@ -371,8 +370,8 @@
 		master_login_client_free(&client);
 		return;
 	}
-	i_set_failure_prefix(t_strdup_printf("%s(%s): ",
-		client->conn->login->service->name, auth_args[0]));
+	i_set_failure_prefix("%s(%s): ", client->conn->login->service->name,
+			     auth_args[0]);
 
 	if (conn->login->postlogin_socket_path == NULL)
 		master_login_auth_finish(client, auth_args);
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/lib-master/master-service.c
--- a/src/lib-master/master-service.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/lib-master/master-service.c	Fri Oct 12 01:06:13 2012 +0300
@@ -133,7 +133,7 @@
 	lib_init();
 	/* Set a logging prefix temporarily. This will be ignored once the log
 	   is properly initialized */
-	i_set_failure_prefix(t_strdup_printf("%s(init): ", name));
+	i_set_failure_prefix("%s(init): ", name);
 
 	/* ignore these signals as early as possible */
         lib_signals_ignore(SIGPIPE, TRUE);
@@ -189,12 +189,10 @@
 	   we want to log */
 	if (getenv("LOG_SERVICE") != NULL)
 		i_set_failure_internal();
-	if (getenv("USER") != NULL) {
-		i_set_failure_prefix(t_strdup_printf("%s(%s): ",
-						     name, getenv("USER")));
-	} else {
-		i_set_failure_prefix(t_strdup_printf("%s: ", name));
-	}
+	if (getenv("USER") != NULL)
+		i_set_failure_prefix("%s(%s): ", name, getenv("USER"));
+	else
+		i_set_failure_prefix("%s: ", name);
 
 	if ((flags & MASTER_SERVICE_FLAG_STANDALONE) == 0) {
 		/* initialize master_status structure */
@@ -262,7 +260,7 @@
 	if (getenv("LOG_SERVICE") != NULL && !service->log_directly) {
 		/* logging via log service */
 		i_set_failure_internal();
-		i_set_failure_prefix(prefix);
+		i_set_failure_prefix("%s", prefix);
 		return;
 	}
 
@@ -287,7 +285,7 @@
 					  &facility))
 			facility = LOG_MAIL;
 		i_set_failure_syslog("dovecot", LOG_NDELAY, facility);
-		i_set_failure_prefix(prefix);
+		i_set_failure_prefix("%s", prefix);
 
 		if (strcmp(service->set->log_path, "syslog") != 0) {
 			/* set error handlers back to file */
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/lib-storage/mail-storage-service.c	Fri Oct 12 01:06:13 2012 +0300
@@ -659,14 +659,14 @@
 {
 	struct mail_storage_service_user *user = context;
 
-	i_set_failure_prefix(user->log_prefix);
+	i_set_failure_prefix("%s", user->log_prefix);
 }
 
 static void mail_storage_service_io_deactivate(void *context)
 {
 	struct mail_storage_service_user *user = context;
 
-	i_set_failure_prefix(user->service_ctx->default_log_prefix);
+	i_set_failure_prefix("%s", user->service_ctx->default_log_prefix);
 }
 
 static void
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/lib/failures.c
--- a/src/lib/failures.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/lib/failures.c	Fri Oct 12 01:06:13 2012 +0300
@@ -477,7 +477,7 @@
 
 void i_set_failure_file(const char *path, const char *prefix)
 {
-	i_set_failure_prefix(prefix);
+	i_set_failure_prefix("%s", prefix);
 
 	if (log_info_fd != STDERR_FILENO && log_info_fd != log_fd) {
 		if (close(log_info_fd) < 0)
@@ -514,11 +514,22 @@
 	(void)write_full(2, str, strlen(str));
 }
 
-void i_set_failure_prefix(const char *prefix)
+void i_set_failure_prefix(const char *prefix_fmt, ...)
+{
+	va_list args;
+
+	va_start(args, prefix_fmt);
+	i_free(log_prefix);
+	log_prefix = i_strdup_vprintf(prefix_fmt, args);
+	va_end(args);
+
+	log_prefix_sent = FALSE;
+}
+
+void i_unset_failure_prefix(void)
 {
 	i_free(log_prefix);
-	log_prefix = i_strdup(prefix);
-
+	log_prefix = i_strdup("");
 	log_prefix_sent = FALSE;
 }
 
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/lib/failures.h
--- a/src/lib/failures.h	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/lib/failures.h	Fri Oct 12 01:06:13 2012 +0300
@@ -111,7 +111,9 @@
 void i_set_debug_file(const char *path);
 
 /* Set the failure prefix. */
-void i_set_failure_prefix(const char *prefix);
+void i_set_failure_prefix(const char *prefix_fmt, ...) ATTR_FORMAT(1, 2);
+/* Set prefix to "". */
+void i_unset_failure_prefix(void);
 /* Prefix failures with a timestamp. fmt is in strftime() format. */
 void i_set_failure_timestamp_format(const char *fmt);
 /* When logging with internal error protocol, update the process's current
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/lmtp/commands.c
--- a/src/lmtp/commands.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/lmtp/commands.c	Fri Oct 12 01:06:13 2012 +0300
@@ -642,8 +642,7 @@
 			i_unreached();
 	}
 
-	i_set_failure_prefix(t_strdup_printf("lmtp(%s, %s): ",
-					     my_pid, username));
+	i_set_failure_prefix("lmtp(%s, %s): ", my_pid, username);
 	if (mail_storage_service_next(storage_service, rcpt->service_user,
 				      &client->state.dest_user) < 0) {
 		client_send_line(client, ERRSTR_TEMP_MAILBOX_FAIL,
@@ -720,7 +719,7 @@
 	while (client->state.rcpt_idx < count) {
 		ret = client_deliver(client, &rcpts[client->state.rcpt_idx],
 				     src_mail, session);
-		i_set_failure_prefix(t_strdup_printf("lmtp(%s): ", my_pid));
+		i_set_failure_prefix("lmtp(%s): ", my_pid);
 
 		client->state.rcpt_idx++;
 		if (ret == 0)
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/log/log-connection.c
--- a/src/log/log-connection.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/log/log-connection.c	Fri Oct 12 01:06:13 2012 +0300
@@ -104,7 +104,7 @@
 		log_error_buffer_add(log->errorbuf, &err);
 		break;
 	}
-	i_set_failure_prefix(prefix);
+	i_set_failure_prefix("%s", prefix);
 	i_log_type(ctx, "%s", text);
 	i_set_failure_prefix("log: ");
 }
diff -r 70ebdddbdf9c -r d00cf8e0dae7 src/master/main.c
--- a/src/master/main.c	Fri Oct 12 01:03:49 2012 +0300
+++ b/src/master/main.c	Fri Oct 12 01:06:13 2012 +0300
@@ -770,7 +770,7 @@
 				MASTER_SERVICE_FLAG_STANDALONE |
 				MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR,
 				&argc, &argv, "+Fanp");
-	i_set_failure_prefix("");
+	i_unset_failure_prefix();
 
 	io_loop_set_time_moved_callback(current_ioloop, master_time_moved);
 


More information about the dovecot-cvs mailing list