master-service.c revision 5ff22d69989a3ccc2d947164e47996f720d493d8
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen#define DEFAULT_CONFIG_FILE_PATH SYSCONFDIR"/dovecot.conf"
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen/* getenv(MASTER_CONFIG_FILE_ENV) provides path to configuration file/socket */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen/* getenv(MASTER_DOVECOT_VERSION_ENV) provides master's version number */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen#define MASTER_DOVECOT_VERSION_ENV "DOVECOT_VERSION"
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen/* when we're full of connections, how often to check if login state has
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen changed. we normally notice it immediately because of a signal, so this is
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen just a fallback against race conditions. */
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen/* If die callback hasn't managed to stop the service for this many seconds,
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen#define MASTER_SERVICE_DIE_TIMEOUT_MSECS (30*1000)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenstatic void master_service_io_listeners_close(struct master_service *service);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenstatic void master_service_refresh_login_state(struct master_service *service);
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen return "c:i:ko:OL";
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainenstatic void sig_die(const siginfo_t *si, void *context)
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen /* SIGINT comes either from master process or from keyboard. we don't
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen want to log it in either case.*/
d96f86fb881c5b106649e8994ead1052acf24030Timo Sirainen i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)",
043c8a96a035379bcba04f487d58457beefdfcaaTimo Sirainen lib_signal_code_to_str(si->si_signo, si->si_code));
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen } else if ((service->flags & MASTER_SERVICE_FLAG_NO_IDLE_DIE) != 0) {
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen /* never die when idling */
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen } else if ((service->flags & MASTER_SERVICE_FLAG_STANDALONE) == 0) {
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen /* SIGINT came from master. die only if we're not handling
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen any clients currently. */
struct master_service *
const char *value;
unsigned int count;
#ifdef DEBUG
int count;
non-setuid/gid binaries..) */
lib_init();
count == 0)
count > 0)
count > 0)
return service;
const char *prefix)
const char *path;
int facility;
&facility))
bool set)
void (*callback)(void))
bool (*callback)(void))
const char *path;
const char *path;
switch (opt) {
return FALSE;
return TRUE;
service);
void master_service_env_clean(void)
env_clean();
else T_BEGIN {
} T_END;
unsigned int client_limit)
unsigned int used;
unsigned int count)
unsigned int used;
void (*callback)(void))
unsigned int current_count;
if (current_count == 0)
if (ret < 0) {
} else if (ret == 0)
switch (state) {
service);
case MASTER_LOGIN_STATE_FULL:
int ret;
if (ret < 0)
lib_deinit();
return TRUE;
return TRUE;
return FALSE;
bool important_update;
used_count));
} T_END;
!important_update) {
service);
} else if (ret >= 0) {
} else if (important_update) {
unsigned major_version)
bool ret;
return FALSE;
return FALSE;
T_BEGIN {
} T_END;
return ret;