main.c revision faec0abfd648c647030027e86de2ce8911df683b
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2005-2011 Dovecot authors, see the included COPYING file */
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen#define DOVECOT_CONFIG_BIN_PATH BINDIR"/doveconf"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen#define SERVICE_TIME_MOVED_BACKWARDS_MAX_THROTTLE_SECS (60*3)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic failure_callback_t *orig_fatal_callback;
5801ce4da7d807ab85d02051ece5969e7175eebaTimo Sirainenstatic failure_callback_t *orig_error_callback;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic const struct setting_parser_info *set_roots[] = {
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainenvoid process_exec(const char *cmd, const char *extra_args[])
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen /* @UNSAFE */
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen new_argv = t_new(const char *, count1 + count2 + 1);
861f53be0cc2fa5665f3c107a7576e2a53bb2eb0Timo Sirainen memcpy(new_argv, argv, sizeof(const char *) * count1);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen sizeof(const char *) * count2);
faec0abfd648c647030027e86de2ce8911df683bTimo Sirainen /* hide the path, it's ugly */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen /* prefix with dovecot/ */
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen argv[0] = t_strconcat(PACKAGE"/", argv[0], NULL);
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainenint get_uidgid(const char *user, uid_t *uid_r, gid_t *gid_r,
b4ddb5b3c3722620a8fef387dd8c47bb411a5643Timo Sirainen const char **error_r)
fa87f0ef3636fa52ce42513533ee500c0bf29910Timo Sirainen *error_r = t_strdup_printf("getpwnam(%s) failed: %m", user);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *error_r = t_strdup_printf("User doesn't exist: %s", user);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint get_gid(const char *group, gid_t *gid_r, const char **error_r)
242abe3ad2423776e9cf05e1304eb8fda4831b23Timo Sirainen *error_r = t_strdup_printf("getgrnam(%s) failed: %m", group);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *error_r = t_strdup_printf("Group doesn't exist: %s", group);
2efe19d9045768d985a3bd549cff12f65ba40cc8Timo Sirainenmaster_fatal_callback(const struct failure_context *ctx,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* if we already forked a child process, this isn't fatal for the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen main process and there's no need to write the fatal file. */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* write the error message to a file (we're chdired to
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen abort(); /* just to silence the noreturn attribute warnings */
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainenstartup_fatal_handler(const struct failure_context *ctx,
69b22a0c0c84087e5bdeec71faae7ea77295240fTimo Sirainen fprintf(stderr, "%s%s\n", failure_log_type_prefixes[ctx->type],
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstartup_error_handler(const struct failure_context *ctx,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen fprintf(stderr, "%s%s\n", failure_log_type_prefixes[ctx->type],
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic void fatal_log_check(const struct master_settings *set)
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen path = t_strconcat(set->base_dir, "/"FATAL_FILENAME, NULL);
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen fprintf(stderr, "Last died with error (see error log for more "
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenstatic bool pid_file_read(const char *path, pid_t *pid_r)
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen i_error("Empty PID file in %s, overriding", path);
return found;
const char *pid;
int fd;
const char *base_config_path;
void **sets;
const char *error;
hostpid_init();
const char *error;
&error) < 0)
static void main_log_startup(void)
core_limit == 0;
if (core_dumps_disabled)
static void master_set_process_limit(void)
unsigned int process_limit = 0;
static void global_dead_pipe_close(void)
static void main_deinit(void)
const char *path;
return path;
unsigned long secs;
static void daemonize(void)
if (pid < 0)
if (pid != 0)
_exit(0);
if (setsid() < 0)
hostpid_init();
static void print_help(void)
static void print_build_options(void)
#ifdef IOLOOP_EPOLL
#ifdef IOLOOP_KQUEUE
#ifdef IOLOOP_POLL
#ifdef IOLOOP_SELECT
#ifdef IOLOOP_NOTIFY_DNOTIFY
#ifdef IOLOOP_NOTIFY_INOTIFY
#ifdef IOLOOP_NOTIFY_KQUEUE
#ifdef HAVE_IPV6
#ifdef HAVE_GNUTLS
#ifdef HAVE_OPENSSL
#ifdef SQL_DRIVER_PLUGINS
#ifdef BUILD_MYSQL
#ifdef BUILD_PGSQL
#ifdef BUILD_SQLITE
#ifdef PASSDB_BSDAUTH
#ifdef PASSDB_CHECKPASSWORD
#ifdef PASSDB_LDAP
#ifdef PASSDB_PAM
#ifdef PASSDB_PASSWD
#ifdef PASSDB_PASSWD_FILE
#ifdef PASSDB_SHADOW
#ifdef PASSDB_SQL
#ifdef PASSDB_VPOPMAIL
#ifdef USERDB_CHECKPASSWORD
#ifdef USERDB_LDAP
#ifndef BUILTIN_LDAP
#ifdef USERDB_NSS
#ifdef USERDB_PASSWD
#ifdef USERDB_PREFETCH
#ifdef USERDB_PASSWD_FILE
#ifdef USERDB_SQL
#ifdef USERDB_STATIC
#ifdef USERDB_VPOPMAIL
#ifdef DEBUG
c, optarg)) {
print_help();
const char **args;
print_help();
print_help();
if (ask_key_pass) {
T_BEGIN {
} T_END;
if (!foreground)
daemonize();
main_deinit();