From: Timo Sirainen Date: Sat, 27 Dec 2008 07:19:04 +0000 (+0200) Subject: Added a bit more generic get_process_capability() function. X-Git-Tag: 1.2.beta1~158 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1a879886193463fd224d2ed732c115c638f24c55;p=thirdparty%2Fdovecot%2Fcore.git Added a bit more generic get_process_capability() function. To make life easier for managesieve patch. Patch by Stephan Bosch. --HG-- branch : HEAD --- diff --git a/src/master/master-settings.c b/src/master/master-settings.c index 93bbdf5016..4b258e6505 100644 --- a/src/master/master-settings.c +++ b/src/master/master-settings.c @@ -655,17 +655,18 @@ static void unlink_auth_sockets(const char *path, const char *prefix) } #ifdef HAVE_MODULES -static bool get_imap_capability(struct settings *set) +static const char * +get_process_capability(enum process_type ptype, struct settings *set) { /* FIXME: pretty ugly code just for getting the capability automatically */ - static const char *generated_capability = NULL; static const char *args[] = { "uid=65534", "gid=65534", "home=/tmp", NULL }; + const char *pname = process_names[ptype]; enum master_login_status login_status; struct mail_login_request request; char buf[4096]; @@ -675,16 +676,6 @@ static bool get_imap_capability(struct settings *set) uid_t uid; pid_t pid; - if (generated_capability != NULL) { - /* Reloading configuration. Don't try to execute the imap - process again. Too risky and the wait() call below will - break it anyway. Just use the previous capability list we - already had generated. */ - set->imap_generated_capability = - p_strdup(settings_pool, generated_capability); - return TRUE; - } - uid = geteuid(); if (uid != 0) { /* use the current user */ @@ -694,39 +685,42 @@ static bool get_imap_capability(struct settings *set) if (pipe(fd) < 0) { i_error("pipe() failed: %m"); - return FALSE; + return NULL; } fd_close_on_exec(fd[0], TRUE); fd_close_on_exec(fd[1], TRUE); memset(&request, 0, sizeof(request)); request.fd = fd[1]; - login_status = create_mail_process(PROCESS_TYPE_IMAP, set, &request, + login_status = create_mail_process(ptype, set, &request, "dump-capability", args, NULL, TRUE, &pid); if (login_status != MASTER_LOGIN_STATUS_OK) { (void)close(fd[0]); (void)close(fd[1]); - return FALSE; + return NULL; } (void)close(fd[1]); alarm(5); - if (wait(&status) == -1) - i_fatal("imap dump-capability process %d got stuck", (int)pid); + if (wait(&status) == -1) { + i_fatal("%s dump-capability process %d got stuck", + pname, (int)pid); + } alarm(0); if (status != 0) { (void)close(fd[0]); if (WIFSIGNALED(status)) { - i_error("imap dump-capability process " - "killed with signal %d", WTERMSIG(status)); + i_error("%s dump-capability process " + "killed with signal %d", + pname, WTERMSIG(status)); } else { - i_error("imap dump-capability process returned %d", - WIFEXITED(status) ? WEXITSTATUS(status) : + i_error("%s dump-capability process returned %d", + pname, WIFEXITED(status) ? WEXITSTATUS(status) : status); } - return FALSE; + return NULL; } pos = 0; @@ -734,20 +728,40 @@ static bool get_imap_capability(struct settings *set) pos += ret; if (ret < 0) { - i_error("read(imap dump-capability process) failed: %m"); + i_error("read(%s dump-capability process) failed: %m", pname); (void)close(fd[0]); - return FALSE; + return NULL; } (void)close(fd[0]); if (pos == 0 || buf[pos-1] != '\n') { - i_error("imap dump-capability: Couldn't read capability " - "(got %u bytes)", pos); - return FALSE; + i_error("%s dump-capability: Couldn't read capability " + "(got %u bytes)", pname, pos); + return NULL; } buf[pos-1] = '\0'; - generated_capability = i_strdup(buf); + return i_strdup(buf); +} + +static bool get_imap_capability(struct settings *set) +{ + static const char *generated_capability = NULL; + + if (generated_capability != NULL) { + /* Reloading configuration. Don't try to execute the imap + process again. Too risky and the wait() call below will + break it anyway. Just use the previous capability list we + already had generated. */ + set->imap_generated_capability = + p_strdup(settings_pool, generated_capability); + return TRUE; + } + + generated_capability = get_process_capability(PROCESS_TYPE_IMAP, set); + if (generated_capability == NULL) + return FALSE; + set->imap_generated_capability = p_strdup(settings_pool, generated_capability); return TRUE;