service-process.c revision a8aec60b5359e5ea7fc7a9464217ae3626df8785
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber/* Copyright (c) 2005-2013 Dovecot authors, see the included COPYING file */
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano unsigned int i, count, socket_listener_count, ssl_socket_count;
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano /* stdin/stdout is already redirected to /dev/null. Other master fds
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano should have been opened with fd_close_on_exec() so we don't have to
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano worry about them.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano because the destination fd might be another one's source fd we have
b4578c5b380130a41a69b5b49c970157acaf1dbbDwight Engen to be careful not to overwrite anything. dup() the fd when needed */
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano listeners = array_get(&service->listeners, &count);
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano dup2_append(&dups, service_anvil_global->log_fdpass_fd[0],
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano /* nonblocking anvil fd must be the first one. anvil treats it
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano as the master's fd */
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano dup2_append(&dups, service_anvil_global->nonblocking_fd[0], fd++);
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano dup2_append(&dups, service_anvil_global->blocking_fd[0], fd++);
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano /* anvil/log fds have no names */
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano for (i = MASTER_LISTEN_FD_FIRST; i < (unsigned int)fd; i++)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano /* first add non-ssl listeners */
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber for (i = 0; i < count; i++) {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano str_append_tabescaped(listener_names, listeners[i]->name);
f79d43bbe70a01454049b77d6f15f6369744959eStéphane Graber /* then ssl-listeners */
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano for (i = 0; i < count; i++) {
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano str_append_tabescaped(listener_names, listeners[i]->name);
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano dup2_append(&dups, service_anvil_global->blocking_fd[1],
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano dup2_append(&dups, service->status_fd[1], MASTER_STATUS_FD);
closelog();
bool disallow_root;
unsigned int len;
case SERVICE_TYPE_CONFIG:
case SERVICE_TYPE_LOG:
static unsigned int uid_counter = 0;
bool process_forked;
return NULL;
return NULL;
if (pid < 0) {
return NULL;
if (pid == 0) {
if (process_forked) {
return process;
switch (status) {
case FATAL_LOGOPEN:
case FATAL_LOGWRITE:
case FATAL_LOGERROR:
case FATAL_OUTOFMEM:
case FATAL_EXEC:
case FATAL_DEFAULT:
return NULL;
#ifdef WCOREDUMP
if (core_dumps_disabled) {
#ifndef HAVE_PR_SET_DUMPABLE
const char *msg;
if (status == 0) {
const char *data;
int status)
T_BEGIN {
bool default_fatal;
} T_END;