child-process.c revision be0185d71b19869700ac936fa9d09fb4ce950ae3
/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "lib-signals.h"
#include "hash.h"
#include "str.h"
#include "env-util.h"
#include "syslog-util.h"
#include "child-process.h"
#include <unistd.h>
#include <syslog.h>
const char *process_names[PROCESS_TYPE_MAX] = {
"unknown",
"auth",
"auth-worker",
"login",
"imap",
"pop3",
"ssl-build-param",
"dict"
};
struct hash_table *processes;
{
}
{
}
{
}
void child_process_init_env(void)
{
int facility;
/* remove all environment, we don't need them */
env_clean();
/* we'll log through master process */
env_put("LOG_TO_MASTER=1");
if (settings_root == NULL ||
&facility))
#ifdef DEBUG
#endif
}
{
const char **argv;
/* very simple argument splitting. */
if (*title == '\0')
else
}
{
const char *p;
/* hide the path, it's ugly */
}
enum process_type process_type)
{
switch (status) {
case FATAL_LOGOPEN:
return "Can't open log file";
case FATAL_LOGWRITE:
return "Can't write to log file";
case FATAL_LOGERROR:
return "Internal logging error";
case FATAL_OUTOFMEM:
switch (process_type) {
case PROCESS_TYPE_AUTH:
case PROCESS_TYPE_AUTH_WORKER:
return "Out of memory - see auth_process_size setting";
case PROCESS_TYPE_LOGIN:
return "Out of memory - see login_process_size setting";
case PROCESS_TYPE_IMAP:
case PROCESS_TYPE_POP3:
return "Out of memory - see mail_process_size setting";
case PROCESS_TYPE_UNKNOWN:
case PROCESS_TYPE_SSL_PARAM:
case PROCESS_TYPE_DICT:
case PROCESS_TYPE_MAX:
break;
}
return "Out of memory";
case FATAL_EXEC:
return "exec() failed";
case FATAL_DEFAULT:
return "Fatal failure";
}
return NULL;
}
void *context ATTR_UNUSED)
{
struct child_process *process;
const char *process_type_name, *msg;
enum process_type process_type;
int status;
bool abnormal_exit;
/* get the type and remove from hash */
str_truncate(str, 0);
else {
}
/* write errors to syslog */
if (status == 0) {
if (process_type == PROCESS_TYPE_UNKNOWN) {
i_error("unknown child %s exited "
}
} else if (status == 1 &&
/* kludgy. hide this failure. */
} else if (status == FATAL_DEFAULT &&
process->seen_fatal) {
/* the error was already logged. */
} else {
"child %s (%s) returned error %d%s",
}
} else if (WIFSIGNALED(status)) {
}
if (!process->ip_changed)
else
}
}
}
}
i_warning("waitpid() failed: %m");
}
{
}
void child_processes_init(void)
{
}
void child_processes_deinit(void)
{
/* make sure we log if child processes died unexpectedly */
}