]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
my_hostname was broken because of recent change.
authorTimo Sirainen <tss@iki.fi>
Mon, 18 Feb 2013 13:12:26 +0000 (15:12 +0200)
committerTimo Sirainen <tss@iki.fi>
Mon, 18 Feb 2013 13:12:26 +0000 (15:12 +0200)
src/lib/hostpid.c

index e538aa9ce3250cba74daf4a79afb7d556851a401..05b357a8a7e973b0b32066dbcc943bbcef4601f2 100644 (file)
 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_init(void)
 
 void hostpid_deinit(void)
 {
+       i_free(my_hostname_dup);
        i_free(my_domain);
 }