dovecot-2.2: Master looks up system hostdomain now and sends it ...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Feb 18 07:20:19 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/a6b40687c0a4
changeset: 15829:a6b40687c0a4
user: Timo Sirainen <tss at iki.fi>
date: Mon Feb 18 07:20:03 2013 +0200
description:
Master looks up system hostdomain now and sends it to child processes via environment.
This avoids doing a gethostbyname() lookup at startup for each process that
needs it.
diffstat:
src/lib/hostpid.c | 28 ++++++++++++++++++----------
src/lib/hostpid.h | 5 +++++
src/master/service-process.c | 2 ++
3 files changed, 25 insertions(+), 10 deletions(-)
diffs (81 lines):
diff -r cc681437372a -r a6b40687c0a4 src/lib/hostpid.c
--- a/src/lib/hostpid.c Mon Feb 18 07:12:44 2013 +0200
+++ b/src/lib/hostpid.c Mon Feb 18 07:20:03 2013 +0200
@@ -3,6 +3,7 @@
#include "lib.h"
#include "hostpid.h"
+#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
@@ -17,13 +18,17 @@
{
static char hostname[256], pid[MAX_INT_STRLEN];
- if (gethostname(hostname, sizeof(hostname)-1) == -1)
- i_fatal("gethostname() failed: %m");
- hostname[sizeof(hostname)-1] = '\0';
- my_hostname = hostname;
+ my_hostname = getenv(MY_HOSTNAME_ENV);
+ if (my_hostname == NULL) {
+ if (gethostname(hostname, sizeof(hostname)-1) < 0)
+ i_fatal("gethostname() failed: %m");
+ hostname[sizeof(hostname)-1] = '\0';
+ my_hostname = hostname;
+ }
- if (strcspn(hostname, HOSTNAME_DISALLOWED_CHARS) != strlen(hostname))
- i_fatal("Invalid system hostname: %s", 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);
@@ -43,11 +48,14 @@
const char *name;
if (my_domain == NULL) {
- hent = gethostbyname(my_hostname);
- name = hent != NULL ? hent->h_name : NULL;
+ name = getenv(MY_HOSTDOMAIN_ENV);
if (name == NULL) {
- /* failed, use just the hostname */
- name = my_hostname;
+ 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);
}
diff -r cc681437372a -r a6b40687c0a4 src/lib/hostpid.h
--- a/src/lib/hostpid.h Mon Feb 18 07:12:44 2013 +0200
+++ b/src/lib/hostpid.h Mon Feb 18 07:20:03 2013 +0200
@@ -1,6 +1,11 @@
#ifndef HOSTPID_H
#define HOSTPID_H
+/* These environments override the hostname/hostdomain if they're set.
+ Master process normally sets these to child processes. */
+#define MY_HOSTNAME_ENV "DOVECOT_HOSTNAME"
+#define MY_HOSTDOMAIN_ENV "DOVECOT_HOSTDOMAIN"
+
extern const char *my_hostname;
extern const char *my_pid;
diff -r cc681437372a -r a6b40687c0a4 src/master/service-process.c
--- a/src/master/service-process.c Mon Feb 18 07:12:44 2013 +0200
+++ b/src/master/service-process.c Mon Feb 18 07:20:03 2013 +0200
@@ -235,6 +235,8 @@
service->set->service_count));
}
env_put(t_strdup_printf(MASTER_UID_ENV"=%u", uid));
+ env_put(t_strdup_printf(MY_HOSTNAME_ENV"=%s", my_hostname));
+ env_put(t_strdup_printf(MY_HOSTDOMAIN_ENV"=%s", my_hostdomain()));
if (!service->set->master_set->version_ignore)
env_put(MASTER_DOVECOT_VERSION_ENV"="PACKAGE_VERSION);
More information about the dovecot-cvs
mailing list