main.c revision 51b4c2c50a1eb94b9f9c6589afcf82586cf9a2f1
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainenunsigned int max_custom_flag_length, mailbox_check_interval;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic char log_prefix[128]; /* syslog() needs this to be permanent */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic void sig_quit(int signo __attr_unused__)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void open_logfile(void)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* quite a long user name, cut it */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen user = t_strndup(user, sizeof(log_prefix)-6-2);
659fe5d24825b160cae512538088020d97a60239Timo Sirainen i_snprintf(log_prefix, sizeof(log_prefix), "imap(%s)", user);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_set_failure_syslog(log_prefix, LOG_NDELAY, LOG_MAIL);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* log to file or stderr */
d8b77aef97e89f1ccc5cbdaef77be9052279e35fTimo Sirainen i_set_failure_file(getenv("LOGFILE"), log_prefix);
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainen i_set_failure_timestamp_format(getenv("LOGSTAMP"));
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenstatic void drop_privileges(void)
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen /* Log file or syslog opening probably requires roots */
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainenstatic void main_init(void)
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen /* support also maildir-specific environment */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen storage = mail_storage_create_with_data(mail, user);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_fatal("Failed to create storage with data: %s", mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void main_deinit(void)
8a3d609fdd84f5938c82e8e7eeb84a24ab41b317Timo Sirainen /* warn about being killed because of some signal, except SIGINT (^C)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen which is too common at least while testing :) */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (lib_signal_kill != 0 && lib_signal_kill != 2)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen i_warning("Killed with signal %d", lib_signal_kill);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint main(int argc __attr_unused__, char *argv[], char *envp[])
lib_init();
main_init();
main_deinit();
lib_deinit();