main.c revision ba9169997959e4d355479d9e2bebf67844beb43e
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "lib-signals.h"
#include "network.h"
#include "auth-process.h"
#include "login-process.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <syslog.h>
const char *process_names[PROCESS_TYPE_MAX] = {
"unknown",
"auth",
"login",
"imap"
};
static Timeout to_children;
{
int i;
for (i = 0; i < max_len; i++) {
if (str[i] == '\0')
return TRUE;
}
return FALSE;
}
void clean_child_process(void)
{
extern char **environ;
/* remove all environment, we don't need them */
/* set the failure log */
if (set_log_path != NULL) {
set_log_path, NULL));
}
if (set_log_timestamp != NULL) {
}
closelog();
}
{
}
{
const char *process_type_name;
int status, process_type;
/* get the type and remove from hash */
if (process_type == PROCESS_TYPE_IMAP)
/* write errors to syslog */
if (status != 0) {
i_error("child %d (%s) returned error %d",
}
} else if (WIFSIGNALED(status)) {
i_error("child %d (%s) killed with signal %d",
}
}
i_warning("waitpid() failed: %m");
}
{
return NULL;
if (ret != 0)
if (ips_count < 1)
return ip;
}
static void open_fds(void)
{
if (null_fd == -1)
if (imap_fd == -1) {
}
if (imaps_fd == -1) {
}
}
static void main_init()
{
/* deny file access from everyone else except owner */
(void)umask(0077);
if (set_log_path == NULL) {
} else {
/* log failures into specified log file */
}
}
static void main_deinit(void)
{
if (lib_signal_kill != 0)
closelog();
}
static void daemonize(void)
{
if (pid < 0)
i_fatal("fork() failed: %m");
if (pid != 0)
_exit(0);
}
{
/* parse arguments */
int foreground = FALSE;
int i;
lib_init();
for (i = 1; i < argc; i++) {
/* foreground */
foreground = TRUE;
/* config file */
i++;
configfile = argv[i];
} else {
}
}
/* read and verify settings before forking */
open_fds();
if (!foreground)
daemonize();
ioloop = io_loop_create();
main_init();
main_deinit();
lib_deinit();
return 0;
}