}
#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];
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 */
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;
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;