dovecot-2.2: my_hostname was broken because of recent change.

dovecot at dovecot.org dovecot at dovecot.org
Mon Feb 18 15:14:12 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/19e4448dee4f
changeset: 15832:19e4448dee4f
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Feb 18 15:12:26 2013 +0200
description:
my_hostname was broken because of recent change.

diffstat:

 src/lib/hostpid.c |  27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diffs (54 lines):

diff -r 62a930eb22b5 -r 19e4448dee4f src/lib/hostpid.c
--- a/src/lib/hostpid.c	Mon Feb 18 08:46:06 2013 +0200
+++ b/src/lib/hostpid.c	Mon Feb 18 15:12:26 2013 +0200
@@ -12,26 +12,32 @@
 const char *my_hostname = NULL;
 const char *my_pid = NULL;
 
+static char *my_hostname_dup = NULL;
 static char *my_domain = NULL;
 
 void hostpid_init(void)
 {
-	static char hostname[256], pid[MAX_INT_STRLEN];
+	static char pid[MAX_INT_STRLEN];
+	char hostname[256];
+	const char *value;
 
-	my_hostname = getenv(MY_HOSTNAME_ENV);
-	if (my_hostname == NULL) {
+	/* allow calling hostpid_init() multiple times to reset hostname */
+	i_free_and_null(my_hostname_dup);
+	i_free_and_null(my_domain);
+
+	value = getenv(MY_HOSTNAME_ENV);
+	if (value == NULL) {
 		if (gethostname(hostname, sizeof(hostname)-1) < 0)
 			i_fatal("gethostname() failed: %m");
 		hostname[sizeof(hostname)-1] = '\0';
-		my_hostname = hostname;
+		value = hostname;
 	}
 
-	if (my_hostname[0] == '\0' ||
-	    strcspn(my_hostname, HOSTNAME_DISALLOWED_CHARS) != strlen(my_hostname))
-		i_error("Invalid system hostname: '%s'", my_hostname);
-
-	/* allow calling hostpid_init() multiple times to reset hostname */
-	i_free_and_null(my_domain);
+	if (value[0] == '\0' ||
+	    strcspn(value, HOSTNAME_DISALLOWED_CHARS) != strlen(value))
+		i_error("Invalid system hostname: '%s'", value);
+	my_hostname_dup = i_strdup(value);
+	my_hostname = my_hostname_dup;
 
 	i_snprintf(pid, sizeof(pid), "%lld", (long long)getpid());
 	my_pid = pid;
@@ -39,6 +45,7 @@
 
 void hostpid_deinit(void)
 {
+	i_free(my_hostname_dup);
 	i_free(my_domain);
 }
 


More information about the dovecot-cvs mailing list