Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8596:2609eca99495 HEAD
Added my_hostdomain() function which mbox code now uses instead of doing that internally.
Based on patch by Apple.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 07 Jan 2009 13:45:37 -0500 |
parents | 829b6555392b |
children | 9f885dbd8157 |
files | src/lib-storage/index/mbox/mbox-save.c src/lib/hostpid.c src/lib/hostpid.h |
diffstat | 3 files changed, 29 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-save.c Wed Jan 07 13:44:41 2009 -0500 +++ b/src/lib-storage/index/mbox/mbox-save.c Wed Jan 07 13:45:37 2009 -0500 @@ -27,7 +27,6 @@ #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> -#include <netdb.h> #include <utime.h> #define MBOX_DELIVERY_ID_RAND_BYTES (64/8) @@ -58,8 +57,6 @@ unsigned int finished:1; }; -static char my_hostdomain[256] = ""; - static int write_error(struct mbox_save_context *ctx) { mbox_set_syscall_error(ctx->mbox, "write()"); @@ -114,23 +111,8 @@ static int write_from_line(struct mbox_save_context *ctx, time_t received_date, const char *from_envelope) { - const char *name; int ret; - if (*my_hostdomain == '\0') { - struct hostent *hent; - - hent = gethostbyname(my_hostname); - - name = hent != NULL ? hent->h_name : NULL; - if (name == NULL) { - /* failed, use just the hostname */ - name = my_hostname; - } - - i_strocpy(my_hostdomain, name, sizeof(my_hostdomain)); - } - T_BEGIN { const char *line; @@ -139,7 +121,7 @@ &ctx->mbox->storage->storage; from_envelope = t_strconcat(storage->ns->user->username, - "@", my_hostdomain, NULL); + "@", my_hostdomain(), NULL); } /* save in local timezone, no matter what it was given with */
--- a/src/lib/hostpid.c Wed Jan 07 13:44:41 2009 -0500 +++ b/src/lib/hostpid.c Wed Jan 07 13:45:37 2009 -0500 @@ -4,10 +4,13 @@ #include "hostpid.h" #include <unistd.h> +#include <netdb.h> const char *my_hostname = NULL; const char *my_pid = NULL; +static char *my_domain = NULL; + void hostpid_init(void) { static char hostname[256], pid[MAX_INT_STRLEN]; @@ -17,6 +20,26 @@ hostname[sizeof(hostname)-1] = '\0'; my_hostname = hostname; + /* allow calling hostpid_init() multiple times to reset hostname */ + i_free_and_null(my_domain); + i_strocpy(pid, dec2str(getpid()), sizeof(pid)); my_pid = pid; } + +const char *my_hostdomain(void) +{ + struct hostent *hent; + const char *name; + + if (my_domain == NULL) { + hent = gethostbyname(my_hostname); + name = hent != NULL ? hent->h_name : NULL; + if (name == NULL) { + /* failed, use just the hostname */ + name = my_hostname; + } + my_domain = i_strdup(name); + } + return my_domain; +}
--- a/src/lib/hostpid.h Wed Jan 07 13:44:41 2009 -0500 +++ b/src/lib/hostpid.h Wed Jan 07 13:45:37 2009 -0500 @@ -4,9 +4,12 @@ extern const char *my_hostname; extern const char *my_pid; -/* Initializes my_hostname and my_pid. Done only once, so it's safe and - fast to call this function multiple times. */ +/* Initializes my_hostname and my_pid. */ void hostpid_init(void); +/* Returns the current host+domain, or if it fails fallback to returning + hostname. */ +const char *my_hostdomain(void); + #endif