master-connection.c revision 1693511477f47c4a1da85a74fc2635ecb8e94709
/* Copyright (c) 2011-2015 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "istream.h"
#include "write-full.h"
#include "strescape.h"
#include "process-title.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "mail-namespace.h"
#include "mail-storage-private.h"
#include "mail-storage-service.h"
#include "mail-search-build.h"
#include "master-connection.h"
#include <unistd.h>
#define INDEXER_PROTOCOL_MAJOR_VERSION 1
#define INDEXER_PROTOCOL_MINOR_VERSION 0
#define INDEXER_WORKER_HANDSHAKE "VERSION\tindexer-worker-master\t1\t0\n%u\n"
#define INDEXER_MASTER_NAME "indexer-master-worker"
struct master_connection {
struct mail_storage_service_ctx *storage_service;
int fd;
unsigned int version_received:1;
};
{
return;
process_title_set("[idling]");
else if (seq1 == 0)
else {
}
}
static int
{
struct mailbox_status status;
struct mailbox_transaction_context *trans;
struct mail_search_args *search_args;
struct mail_search_context *ctx;
struct mailbox_metadata metadata;
int ret = 0;
&metadata) < 0) {
i_error("Mailbox %s: Precache-fields lookup failed: %s",
return -1;
}
&status) < 0) {
i_error("Mailbox %s: Status lookup failed: %s",
return -1;
}
if (++counter % 100 == 0) {
if (i_snprintf(percentage_str,
sizeof(percentage_str), "%u\n",
percentage) < 0)
i_unreached();
}
}
}
if (mailbox_search_deinit(&ctx) < 0) {
i_error("Mailbox %s: Mail search failed: %s",
ret = -1;
}
if (mailbox_transaction_commit(&trans) < 0) {
i_error("Mailbox %s: Transaction commit failed: %s",
ret = -1;
}
if (ret == 0) {
i_info("Indexed %u messages in %s",
}
return ret;
}
static int
const char *mailbox, unsigned int max_recent_msgs,
const char *what)
{
struct mail_namespace *ns;
struct mailbox_status status;
enum mail_error error;
int ret;
if (ret < 0) {
i_error("Getting path to mailbox %s failed: %s",
mailbox_free(&box);
return -1;
}
if (ret == 0) {
mailbox_free(&box);
return 0;
}
ret = 0;
if (max_recent_msgs != 0) {
/* index only if there aren't too many recent messages.
don't bother syncing the mailbox, that alone can take a
while with large maildirs. */
if (mailbox_open(box) < 0) {
ret = -1;
} else {
}
mailbox_free(&box);
return ret;
}
}
if (error != MAIL_ERROR_NOTFOUND) {
i_error("Syncing mailbox %s failed: %s",
} else if (user->mail_debug) {
i_debug("Syncing mailbox %s failed: %s",
}
ret = -1;
ret = -1;
}
mailbox_free(&box);
return ret;
}
static int
{
struct mail_storage_service_input input;
struct mail_storage_service_user *service_user;
unsigned int max_recent_msgs;
int ret;
/* <username> <mailbox> <session ID> <max_recent_msgs> [i][o] */
return -1;
}
/* if session-id is given, add -idx suffix to it so that stats process
doesn't complain about duplicates. also it's nicer to keep the stats
separate for the indexer and the caller. */
ret = -1;
} else {
}
}
{
const char *line;
int ret;
return;
}
if (!conn->version_received) {
return;
i_error("Indexer master not compatible with this master "
"(mixed old and new binaries?)");
return;
}
}
T_BEGIN {
} T_END;
if (ret < 0) {
break;
}
}
}
struct master_connection *
{
struct master_connection *conn;
const char *handshake;
return conn;
}
{
i_error("close(master conn) failed: %m");
}