Based on patch by Apple.
--HG--
branch : HEAD
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
-#include <netdb.h>
#include <utime.h>
#define MBOX_DELIVERY_ID_RAND_BYTES (64/8)
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()");
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;
&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 */
#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];
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;
+}
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