if ((cctx->cmd->flags & CMD_FLAG_NO_PRINT) == 0)
doveadm_print_deinit();
if (o_stream_finish(doveadm_print_ostream) < 0) {
- i_info("Error writing output in command %s: %s",
- req->cmd->name,
- o_stream_get_error(req->output));
+ e_info(cctx->event, "Error writing output in command %s: %s",
+ req->cmd->name, o_stream_get_error(req->output));
doveadm_exit_code = EX_TEMPFAIL;
}
o_stream_nsend_str(req->output,",");
if (cctx->referral != NULL) {
- i_error("Command requested referral: %s", cctx->referral);
+ e_error(cctx->event,
+ "Command requested referral: %s", cctx->referral);
doveadm_http_server_json_error(req, "internalError");
} else if (doveadm_exit_code != 0) {
- if (doveadm_exit_code == 0 || doveadm_exit_code == EX_TEMPFAIL)
- i_error("Command %s failed", req->cmd->name);
+ if (doveadm_exit_code == 0 || doveadm_exit_code == EX_TEMPFAIL) {
+ e_error(cctx->event,
+ "Command %s failed", req->cmd->name);
+ }
doveadm_http_server_json_error(req, "exitCode");
} else {
doveadm_http_server_json_success(req, is);
}
if (v_input->stream_errno != 0) {
- i_error("read(%s) failed: %s",
+ e_error(req->conn->conn.event,
+ "read(%s) failed: %s",
i_stream_get_name(v_input),
i_stream_get_error(v_input));
req->method_err = 400;
if (req->input->stream_errno != 0) {
http_server_request_fail_close(http_sreq,
400, "Client disconnected");
- i_info("read(%s) failed: %s",
+ e_info(req->conn->conn.event,
+ "read(%s) failed: %s",
i_stream_get_name(req->input),
i_stream_get_error(req->input));
return;
if (req->output != NULL) {
if (o_stream_finish(req->output) == -1) {
- i_info("error writing output: %s",
+ e_info(req->conn->conn.event,
+ "error writing output: %s",
o_stream_get_error(req->output));
o_stream_destroy(&req->output);
http_server_request_fail(http_sreq,
if (agent == NULL) agent = "";
url = http_url_create(http_req->target.url);
- i_info("doveadm: %s %s %s \"%s %s "
+ e_info(conn->conn.event, "doveadm: %s %s %s \"%s %s "
"HTTP/%d.%d\" %d %"PRIuUOFF_T" \"%s\" \"%s\"",
net_ip2addr(&conn->conn.remote_ip), "-", "-",
http_req->method, http_req->target.url->path,
char *value;
if (*set->doveadm_password == '\0') {
- i_error("Invalid authentication attempt to HTTP API: "
+ e_error(conn->conn.event,
+ "Invalid authentication attempt to HTTP API: "
"Basic authentication scheme not enabled");
return FALSE;
}
if (creds->data != NULL && strcmp(creds->data, str_c(b64_value)) == 0)
return TRUE;
- i_error("Invalid authentication attempt to HTTP API "
+ e_error(conn->conn.event,
+ "Invalid authentication attempt to HTTP API "
"(using Basic authentication scheme)");
return FALSE;
}
string_t *b64_value;
if (*set->doveadm_api_key == '\0') {
- i_error("Invalid authentication attempt to HTTP API: "
+ e_error(conn->conn.event,
+ "Invalid authentication attempt to HTTP API: "
"X-Dovecot-API authentication scheme not enabled");
return FALSE;
}
if (creds->data != NULL && strcmp(creds->data, str_c(b64_value)) == 0)
return TRUE;
- i_error("Invalid authentication attempt to HTTP API "
+ e_error(conn->conn.event,
+ "Invalid authentication attempt to HTTP API "
"(using X-Dovecot-API authentication scheme)");
return FALSE;
}
if (strcasecmp(creds->scheme, "X-Dovecot-API") == 0)
return doveadm_http_server_auth_api_key(req, creds);
- i_error("Unsupported authentication scheme to HTTP API: %s",
+ e_error(req->conn->conn.event,
+ "Unsupported authentication scheme to HTTP API: %s",
str_sanitize(creds->scheme, 128));
return FALSE;
}
*conn->conn.set->doveadm_password == '\0') {
http_server_request_fail(http_sreq,
500, "Internal Server Error");
- i_error("No authentication defined in configuration. "
+ e_error(conn->conn.event,
+ "No authentication defined in configuration. "
"Add API key or password");
return FALSE;
}
t_strdup_printf("\n-%s\n", str));
} else {
o_stream_nsend_str(conn->output, "\n-\n");
- i_error("BUG: Command '%s' returned unknown error code %d",
- cctx->cmd->name, doveadm_exit_code);
+ e_error(cctx->event,
+ "BUG: Command returned unknown error code %d",
+ doveadm_exit_code);
}
}
const struct doveadm_cmd_ver2 *cmd_ver2;
if ((cmd_ver2 = doveadm_cmdline_find_with_args(cmd_name, &argc, &argv)) == NULL) {
- i_error("doveadm: Client sent unknown command: %s", cmd_name);
+ e_error(cctx->event,
+ "doveadm: Client sent unknown command: %s", cmd_name);
return -1;
}
cctx->cmd = cmd_ver2;
unsigned int argc = str_array_length(args);
if (argc < 3) {
- i_error("doveadm client: No command given");
+ e_error(cctx->event, "doveadm client: No command given");
return FALSE;
}
doveadm_exit_code = 0;
args++; argc--;
break;
default:
- i_error("doveadm client: Unknown flag: %c", *flags);
+ e_error(cctx->event,
+ "doveadm client: Unknown flag: %c", *flags);
return FALSE;
}
}
}
if (!doveadm_client_is_allowed_command(conn->conn.set, cmd_name)) {
- i_error("doveadm client isn't allowed to use command: %s",
+ e_error(cctx->event,
+ "doveadm client isn't allowed to use command: %s",
cmd_name);
return FALSE;
}
}
if (*set->doveadm_password == '\0') {
- i_error("doveadm_password not set, "
- "remote authentication disabled");
+ e_error(conn->conn.event,
+ "doveadm_password not set, remote authentication disabled");
return -1;
}
/* FIXME: some day we should probably let auth process do this and
support all kinds of authentication */
if (!str_begins(line, "PLAIN\t", &args)) {
- i_error("doveadm client attempted non-PLAIN authentication: %s", line);
+ e_error(conn->conn.event,
+ "doveadm client attempted non-PLAIN authentication: %s",
+ line);
return -1;
}
plain = t_buffer_create(128);
if (base64_decode(args, strlen(args), plain) < 0) {
- i_error("doveadm client sent invalid base64 auth PLAIN data");
+ e_error(conn->conn.event,
+ "doveadm client sent invalid base64 auth PLAIN data");
return -1;
}
data = plain->data;
if (size < 10 || data[0] != '\0' ||
memcmp(data+1, "doveadm", 7) != 0 || data[8] != '\0') {
- i_error("doveadm client didn't authenticate as 'doveadm'");
+ e_error(conn->conn.event
+ , "doveadm client didn't authenticate as 'doveadm'");
return -1;
}
pass = t_strndup(data + 9, size - 9);
if (strlen(pass) != strlen(set->doveadm_password) ||
!mem_equals_timing_safe(pass, set->doveadm_password,
strlen(pass))) {
- i_error("doveadm client authenticated with wrong password");
+ e_error(conn->conn.event,
+ "doveadm client authenticated with wrong password");
return -1;
}
return 1;
error = conn->input->stream_errno == 0 ? "EOF" :
strerror(conn->input->stream_errno);
}
- i_error("doveadm client disconnected before handshake: %s", error);
+ e_error(conn->conn.event,
+ "doveadm client disconnected before handshake: %s", error);
}
static void
if (!version_string_verify_full(line, "doveadm-server",
DOVEADM_SERVER_PROTOCOL_VERSION_MAJOR,
&conn->minor_version)) {
- i_error("doveadm client not compatible with this server "
+ e_error(conn->conn.event,
+ "doveadm client not compatible with this server "
"(mixed old and new binaries?)");
client_connection_tcp_destroy(&conn);
return;
if (master_service_ssl_init(master_service,
&conn->input, &conn->output,
&conn->ssl_iostream, &error) < 0) {
- i_error("SSL init failed: %s", error);
+ e_error(conn->conn.event, "SSL init failed: %s", error);
return -1;
}
if (ssl_iostream_handshake(conn->ssl_iostream) < 0) {
- i_error("SSL handshake failed: %s",
+ e_error(conn->conn.event, "SSL handshake failed: %s",
ssl_iostream_get_last_error(conn->ssl_iostream));
return -1;
}
if (master_service_settings_read(master_service, &input,
&output, &error) < 0) {
- i_error("Error reading configuration: %s", error);
+ e_error(conn->event, "Error reading configuration: %s", error);
return -1;
}
set = master_service_settings_get_others(master_service)[0];
}
static void
-cmd_user_list(struct auth_master_connection *conn,
+cmd_user_list(struct doveadm_cmd_context *cctx,
+ struct auth_master_connection *conn,
const struct authtest_input *input,
char *const *users)
{
}
}
if (auth_master_user_list_deinit(&ctx) < 0) {
- i_error("user listing failed");
+ e_error(cctx->event, "user listing failed");
doveadm_exit_code = EX_DATAERR;
}
conn = doveadm_get_auth_master_conn(master_socket_path);
if (auth_master_cache_flush(conn, users, &count) < 0) {
- i_error("Cache flush failed");
+ e_error(cctx->event, "Cache flush failed");
doveadm_exit_code = EX_TEMPFAIL;
} else {
doveadm_print_init("formatted");
if (!doveadm_cmd_param_array(cctx, "user-mask", &optval)) {
doveadm_exit_code = EX_USAGE;
- i_error("No user(s) specified");
+ e_error(cctx->event, "No user(s) specified");
return;
}
if (expand_field != NULL && userdb_only) {
- i_error("-e can't be used with -u");
+ e_error(cctx->event, "-e can't be used with -u");
doveadm_exit_code = EX_USAGE;
return;
}
if (expand_field != NULL && show_field != NULL) {
- i_error("-e can't be used with -f");
+ e_error(cctx->event, "-e can't be used with -f");
doveadm_exit_code = EX_USAGE;
return;
}
}
if (have_wildcards) {
- cmd_user_list(conn, &input, (char*const*)optval);
+ cmd_user_list(cctx, conn, &input, (char*const*)optval);
auth_master_deinit(&conn);
return;
}
static int
cmd_user_input(struct auth_master_connection *conn,
const struct authtest_input *input,
- const char *show_field, bool userdb)
+ const char *show_field, bool userdb,
+ struct event *event)
{
const char *lookup_name = userdb ? "userdb lookup" : "passdb lookup";
pool_t pool;
}
if (ret < 0) {
if (fields[0] == NULL)
- i_error("%s failed for %s", lookup_name, input->username);
+ e_error(event,
+ "%s failed for %s", lookup_name, input->username);
else {
- i_error("%s failed for %s: %s", lookup_name,
+ e_error(event,
+ "%s failed for %s: %s", lookup_name,
input->username, fields[0]);
}
ret = -1;
conn = doveadm_get_auth_master_conn(master_socket_path);
if (auth_master_cache_flush(conn, users, &count) < 0) {
- i_error("Cache flush failed");
+ e_error(cctx->event, "Cache flush failed");
doveadm_exit_code = EX_TEMPFAIL;
} else {
printf("%u cache entries flushed\n", count);
else
putchar('\n');
- ret = cmd_user_input(conn, &input, show_field, FALSE);
+ ret = cmd_user_input(conn, &input, show_field, FALSE, cctx->event);
switch (ret) {
case -1:
doveadm_exit_code = EX_TEMPFAIL;
static int
cmd_user_mail_input(struct mail_storage_service_ctx *storage_service,
const struct authtest_input *input,
- const char *show_field, const char *expand_field)
+ const char *show_field, const char *expand_field,
+ struct event *event)
{
struct mail_storage_service_input service_input;
struct mail_storage_service_user *service_user;
mail_user_var_expand_table(user),
mail_user_var_expand_func_table, user,
&error) <= 0) {
- i_error("Failed to expand %s: %s", expand_field, error);
+ e_error(event, "Failed to expand %s: %s", expand_field, error);
} else {
printf("%s\n", str_c(str));
}
auth_cmd_help(cctx);
if (expand_field != NULL && userdb_only) {
- i_error("-e can't be used with -u");
+ e_error(cctx->event, "-e can't be used with -u");
doveadm_exit_code = EX_USAGE;
return;
}
if (expand_field != NULL && show_field != NULL) {
- i_error("-e can't be used with -f");
+ e_error(cctx->event, "-e can't be used with -f");
doveadm_exit_code = EX_USAGE;
return;
}
putchar('\n');
ret = !userdb_only ?
- cmd_user_mail_input(storage_service, &input, show_field, expand_field) :
- cmd_user_input(conn, &input, show_field, TRUE);
+ cmd_user_mail_input(storage_service, &input, show_field,
+ expand_field, cctx->event) :
+ cmd_user_input(conn, &input, show_field, TRUE, cctx->event);
switch (ret) {
case -1:
doveadm_exit_code = EX_TEMPFAIL;
if ((fd = net_connect_ip(&ips[0], port, NULL)) == -1)
i_fatal("connect(%s, %u) failed: %m", host, port);
- i_info("Connected to %s port %u.", net_ip2addr(&ips[0]), port);
+ e_info(cctx->event, "Connected to %s port %u.", net_ip2addr(&ips[0]), port);
i_zero(&client);
client.event = event_create(cctx->event);
dopset_r->username = username;
if (!doveadm_cmd_param_str(cctx, "dict-uri", &dict_uri)) {
- i_error("dictionary URI must be specified");
+ e_error(cctx->event, "dictionary URI must be specified");
doveadm_exit_code = EX_USAGE;
return -1;
}
if (!str_begins_with(key, DICT_PATH_PRIVATE) &&
!str_begins_with(key, DICT_PATH_SHARED)) {
- i_error("Key must begin with '"DICT_PATH_PRIVATE
- "' or '"DICT_PATH_SHARED"': %s", key);
+ e_error(cctx->event, "Key must begin with "
+ "'"DICT_PATH_PRIVATE"' or '"DICT_PATH_SHARED"': %s",
+ key);
doveadm_exit_code = EX_USAGE;
return -1;
}
if (username[0] == '\0' &&
str_begins_with(key, DICT_PATH_PRIVATE)) {
- i_error("-u must be specified for "DICT_PATH_PRIVATE" keys");
+ e_error(cctx->event,
+ "-u must be specified for "DICT_PATH_PRIVATE" keys");
doveadm_exit_code = EX_USAGE;
return -1;
}
i_zero(&dict_set);
dict_set.base_dir = doveadm_settings->base_dir;
if (dict_init(dict_uri, &dict_set, &dict, &error) < 0) {
- i_error("dict_init(%s) failed: %s", dict_uri, error);
+ e_error(cctx->event,
+ "dict_init(%s) failed: %s", dict_uri, error);
doveadm_exit_code = EX_TEMPFAIL;
return -1;
}
struct dict_op_settings set;
if (!doveadm_cmd_param_str(cctx, "key", &key)) {
- i_error("dict-get: Missing key");
+ e_error(cctx->event, "dict-get: Missing key");
doveadm_exit_code = EX_USAGE;
return;
}
while (ctx.ret == -2)
dict_wait(dict);
if (ctx.ret < 0) {
- i_error("dict_lookup(%s) failed: %s", key, ctx.error);
+ e_error(cctx->event,
+ "dict_lookup(%s) failed: %s", key, ctx.error);
doveadm_exit_code = EX_TEMPFAIL;
} else if (ctx.ret == 0) {
- i_error("%s doesn't exist", key);
+ e_error(cctx->event, "%s doesn't exist", key);
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
} else {
unsigned int i, values_count = str_array_length(ctx.values);
if (!doveadm_cmd_param_str(cctx, "key", &key) ||
!doveadm_cmd_param_str(cctx, "value", &value)) {
- i_error("dict set: Missing parameters");
+ e_error(cctx->event, "dict set: Missing parameters");
doveadm_exit_code = EX_USAGE;
return;
}
dict_set(trans, key, value);
if (dict_transaction_commit(&trans, &error) <= 0) {
- i_error("dict_transaction_commit() failed: %s", error);
+ e_error(cctx->event,
+ "dict_transaction_commit() failed: %s", error);
doveadm_exit_code = EX_TEMPFAIL;
}
dict_deinit(&dict);
const char *key;
if (!doveadm_cmd_param_str(cctx, "key", &key)) {
- i_error("dict unset: Missing key");
+ e_error(cctx->event, "dict unset: Missing key");
doveadm_exit_code = EX_USAGE;
return;
}
dict_unset(trans, key);
if (dict_transaction_commit(&trans, &error) <= 0) {
- i_error("dict_transaction_commit() failed: %s", error);
+ e_error(cctx->event,
+ "dict_transaction_commit() failed: %s", error);
doveadm_exit_code = EX_TEMPFAIL;
}
dict_deinit(&dict);
if (!doveadm_cmd_param_str(cctx, "key", &key) ||
!doveadm_cmd_param_int64(cctx, "difference", &diff)) {
- i_error("dict-inc: Missing parameters");
+ e_error(cctx->event, "dict-inc: Missing parameters");
doveadm_exit_code = EX_USAGE;
return;
}
dict_atomic_inc(trans, key, diff);
ret = dict_transaction_commit(&trans, &error);
if (ret < 0) {
- i_error("dict_transaction_commit() failed: %s", error);
+ e_error(cctx->event,
+ "dict_transaction_commit() failed: %s", error);
doveadm_exit_code = EX_TEMPFAIL;
} else if (ret == 0) {
- i_error("%s doesn't exist", key);
+ e_error(cctx->event, "%s doesn't exist", key);
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
}
dict_deinit(&dict);
struct dict_op_settings set;
if (!doveadm_cmd_param_str(cctx, "prefix", &prefix)) {
- i_error("dict-iter: Missing prefix");
+ e_error(cctx->event, "dict-iter: Missing prefix");
doveadm_exit_code = EX_USAGE;
return;
}
}
}
if (dict_iterate_deinit(&iter, &error) < 0) {
- i_error("dict_iterate_deinit(%s) failed: %s", prefix, error);
+ e_error(cctx->event,
+ "dict_iterate_deinit(%s) failed: %s", prefix, error);
doveadm_exit_code = EX_TEMPFAIL;
}
dict_deinit(&dict);
array_idx_elem(&ctx->namespace_prefixes, 0);
ns = mail_namespace_find(user->namespaces, prefix);
if (ns == NULL) {
- i_error("Namespace not found: '%s'", prefix);
+ e_error(ctx->ctx.cctx->event,
+ "Namespace not found: '%s'", prefix);
ctx->ctx.exit_code = DOVEADM_EX_NOTFOUND;
return -1;
}
ctx->ctx.cur_service_user,
&user2, &error);
if (ret < 0) {
- i_error("Failed to initialize user: %s", error);
+ e_error(ctx->ctx.cctx->event,
+ "Failed to initialize user: %s", error);
ctx->ctx.exit_code = ret == -1 ? EX_TEMPFAIL : EX_CONFIG;
return -1;
}
get_dsync_verify_namespace(ctx, user2, &ns2) < 0)
return -1;
if (mail_namespace_get_sep(ns) != mail_namespace_get_sep(ns2)) {
- i_error("Mail locations must use the same hierarchy separator "
+ e_error(ctx->ctx.cctx->event,
+ "Mail locations must use the same hierarchy separator "
"(specify namespace prefix=\"%s\" "
"{ separator } explicitly)", ns->prefix);
ctx->ctx.exit_code = EX_CONFIG;
}
if (paths_are_equal(ns, ns2, MAILBOX_LIST_PATH_TYPE_MAILBOX) &&
paths_are_equal(ns, ns2, MAILBOX_LIST_PATH_TYPE_INDEX)) {
- i_error("Both source and destination mail_location "
+ e_error(ctx->ctx.cctx->event,
+ "Both source and destination mail_location "
"points to same directory: %s (namespace "
"prefix=\"%s\" { location } is set explicitly?)",
mailbox_list_get_root_forced(user->namespaces->list,
mail_storage_service_io_activate_user(ctx->ctx.cur_service_user);
if (!ctx->exited) {
- i_error("Remote command process isn't dying, killing it");
+ e_error(ctx->ctx.cctx->event,
+ "Remote command process isn't dying, killing it");
if (kill(ctx->remote_pid, SIGKILL) < 0 && errno != ESRCH) {
- i_error("kill(%ld, SIGKILL) failed: %m",
+ e_error(ctx->ctx.cctx->event,
+ "kill(%ld, SIGKILL) failed: %m",
(long)ctx->remote_pid);
}
}
/* replicator not running on this server. ignore. */
return;
}
- i_error("net_connect_unix(%s) failed: %m", path);
+ e_error(ctx->ctx.cctx->event,
+ "net_connect_unix(%s) failed: %m", path);
return;
}
fd_set_nonblock(fd, FALSE);
str_append_c(str, '\t');
str_append_tabescaped(str, state_str);
str_append_c(str, '\n');
- if (write_full(fd, str_data(str), str_len(str)) < 0)
- i_error("write(%s) failed: %m", path);
+ if (write_full(fd, str_data(str), str_len(str)) < 0) {
+ e_error(ctx->ctx.cctx->event,
+ "write(%s) failed: %m", path);
+ }
/* we only wanted to notify replicator. we don't care enough about the
answer to wait for it. */
- if (close(fd) < 0)
- i_error("close(%s) failed: %m", path);
+ if (close(fd) < 0) {
+ e_error(ctx->ctx.cctx->event,
+ "close(%s) failed: %m", path);
+ }
}
static void dsync_errors_finish(struct dsync_cmd_context *ctx)
set.state = ctx->state_input;
set.mailbox_alt_char = doveadm_settings->dsync_alt_char[0];
if (*doveadm_settings->dsync_hashed_headers == '\0') {
- i_error("dsync_hashed_headers must not be empty");
+ e_error(cctx->event, "dsync_hashed_headers must not be empty");
ctx->ctx.exit_code = EX_USAGE;
return -1;
}
array_foreach(&ctx->namespace_prefixes, strp) {
ns = mail_namespace_find(user->namespaces, *strp);
if (ns == NULL) {
- i_error("Namespace not found: '%s'", *strp);
+ e_error(cctx->event, "Namespace not found: '%s'", *strp);
ctx->ctx.exit_code = EX_USAGE;
return -1;
}
/* don't log a warning when running via doveadm server
(e.g. called by replicator) */
if (cctx->conn_type == DOVEADM_CONNECTION_TYPE_CLI) {
- i_warning("Mailbox changes caused a desync. "
+ e_warning(cctx->event,
+ "Mailbox changes caused a desync. "
"You may want to run dsync again: %s",
changes_during_sync == NULL ||
(remote_only_changes && changes_during_sync2 != NULL) ?
container_of(_ctx, struct dsync_cmd_context, ctx);
if (ctx->default_replica_location) {
- if (*ctx->destination != NULL)
- i_error("Don't give mail location with -d parameter");
+ if (*ctx->destination != NULL) {
+ e_error(ctx->ctx.cctx->event,
+ "Don't give mail location with -d parameter");
+ }
} else {
if (*ctx->destination == NULL)
doveadm_mail_help_name(_ctx->cmd->name);
doveadm_print_stream("", 0);
i_assert(ret == -1);
if (input->stream_errno == ENOENT) {
- i_error("%s doesn't exist: %s", fs_file_path(file),
+ e_error(cctx->event, "%s doesn't exist: %s", fs_file_path(file),
i_stream_get_error(input));
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
} else if (input->stream_errno != 0) {
- i_error("read(%s) failed: %s", fs_file_path(file),
+ e_error(cctx->event, "read(%s) failed: %s", fs_file_path(file),
i_stream_get_error(input));
doveadm_exit_code = EX_TEMPFAIL;
}
o_stream_nsend_istream(output, input);
i_stream_destroy(&input);
if (fs_write_stream_finish(file, &output) < 0) {
- i_error("fs_write_stream_finish() failed: %s",
+ e_error(cctx->event, "fs_write_stream_finish() failed: %s",
fs_file_last_error(file));
doveadm_exit_code = EX_TEMPFAIL;
}
dest_file = fs_file_init(fs, dest_path, FS_OPEN_MODE_REPLACE);
if (fs_copy(src_file, dest_file) == 0) ;
else if (errno == ENOENT) {
- i_error("%s doesn't exist: %s", src_path,
+ e_error(cctx->event, "%s doesn't exist: %s", src_path,
fs_file_last_error(dest_file));
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
} else {
- i_error("fs_copy(%s, %s) failed: %s",
+ e_error(cctx->event, "fs_copy(%s, %s) failed: %s",
src_path, dest_path, fs_file_last_error(dest_file));
doveadm_exit_code = EX_TEMPFAIL;
}
doveadm_print(fs_file_path(file));
doveadm_print(dec2str(st.st_size));
} else if (errno == ENOENT) {
- i_error("%s doesn't exist: %s", fs_file_path(file),
+ e_error(cctx->event,
+ "%s doesn't exist: %s", fs_file_path(file),
fs_file_last_error(file));
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
} else {
- i_error("fs_stat(%s) failed: %s",
+ e_error(cctx->event, "fs_stat(%s) failed: %s",
fs_file_path(file), fs_file_last_error(file));
doveadm_exit_code = EX_TEMPFAIL;
}
doveadm_print(m->value);
}
} else if (errno == ENOENT) {
- i_error("%s doesn't exist: %s", fs_file_path(file),
+ e_error(cctx->event,
+ "%s doesn't exist: %s", fs_file_path(file),
fs_file_last_error(file));
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
} else {
- i_error("fs_stat(%s) failed: %s",
+ e_error(cctx->event, "fs_stat(%s) failed: %s",
fs_file_path(file), fs_file_last_error(file));
doveadm_exit_code = EX_TEMPFAIL;
}
doveadm_print(fname);
}
if (fs_iter_deinit(&iter, &error) < 0) {
- i_error("fs_iter_deinit(%s) failed: %s", path, error);
+ e_error(cctx->event,
+ "fs_iter_deinit(%s) failed: %s", path, error);
doveadm_exit_code = EX_TEMPFAIL;
}
fs_deinit(&fs);
static void instance_cmd_help(const struct doveadm_cmd_ver2 *cmd) ATTR_NORETURN;
-static bool pid_file_read(const char *path)
+static bool pid_file_read(const char *path, struct event *event)
{
char buf[32];
int fd;
fd = open(path, O_RDONLY);
if (fd == -1) {
if (errno != ENOENT)
- i_error("open(%s) failed: %m", path);
+ e_error(event, "open(%s) failed: %m", path);
return FALSE;
}
ret = read(fd, buf, sizeof(buf));
if (ret < 0)
- i_error("read(%s) failed: %m", path);
+ e_error(event, "read(%s) failed: %m", path);
else if (ret > 0 && buf[ret-1] == '\n') {
buf[ret-1] = '\0';
if (str_to_pid(buf, &pid) == 0) {
doveadm_print(inst->name);
doveadm_print(unixdate2str(inst->last_used));
pidfile_path = t_strconcat(inst->base_dir, "/master.pid", NULL);
- if (pid_file_read(pidfile_path))
+ if (pid_file_read(pidfile_path, cctx->event))
doveadm_print("yes");
else
doveadm_print("no");
inst = master_instance_list_find_by_name(list, name);
base_dir = inst != NULL ? inst->base_dir : name;
if ((ret = master_instance_list_remove(list, base_dir)) < 0) {
- i_error("Failed to remove instance");
+ e_error(cctx->event, "Failed to remove instance");
doveadm_exit_code = EX_TEMPFAIL;
} else if (ret == 0) {
- i_error("Instance already didn't exist");
+ e_error(cctx->event, "Instance already didn't exist");
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
}
master_instance_list_deinit(&list);
}
}
-static void cmd_log_reopen(struct doveadm_cmd_context *cctx ATTR_UNUSED)
+static void cmd_log_reopen(struct doveadm_cmd_context *cctx)
{
- doveadm_master_send_signal(SIGUSR1);
+ doveadm_master_send_signal(SIGUSR1, cctx->event);
}
struct log_find_file {
if (iter->iter == NULL)
ret = 0;
else if ((ret = mailbox_list_iter_deinit(&iter->iter)) < 0) {
- i_error("Listing mailboxes failed: %s",
- mailbox_list_get_last_internal_error(iter->user->namespaces->list, &error));
+ const char *errtxt = mailbox_list_get_last_internal_error(
+ iter->user->namespaces->list, &error);
+ e_error(iter->ctx->cctx->event,
+ "Listing mailboxes failed: %s", errtxt);
doveadm_mail_failed_error(iter->ctx, error);
}
array_free(&iter->patterns);
#define MASTER_PID_FILE_NAME "master.pid"
-static bool pid_file_read(const char *path, pid_t *pid_r)
+static bool pid_file_read(const char *path, pid_t *pid_r, struct event *event)
{
char buf[32];
int fd;
ret = read(fd, buf, sizeof(buf)-1);
if (ret <= 0) {
if (ret == 0)
- i_error("Empty PID file in %s", path);
+ e_error(event, "Empty PID file in %s", path);
else
i_fatal("read(%s) failed: %m", path);
found = FALSE;
return found;
}
-void doveadm_master_send_signal(int signo)
+void doveadm_master_send_signal(int signo, struct event *event)
{
const char *pidfile_path;
unsigned int i;
pidfile_path = t_strconcat(doveadm_settings->base_dir,
"/"MASTER_PID_FILE_NAME, NULL);
- if (!pid_file_read(pidfile_path, &pid))
+ if (!pid_file_read(pidfile_path, &pid, event))
i_fatal("Dovecot is not running (read from %s)", pidfile_path);
if (kill(pid, signo) < 0)
for (i = 0; i < 30; i++) {
if (kill(pid, 0) < 0) {
if (errno != ESRCH)
- i_error("kill() failed: %m");
+ e_error(event, "kill() failed: %m");
break;
}
i_sleep_msecs(100);
}
}
-static void cmd_stop(struct doveadm_cmd_context *cctx ATTR_UNUSED)
+static void cmd_stop(struct doveadm_cmd_context *cctx)
{
- doveadm_master_send_signal(SIGTERM);
+ doveadm_master_send_signal(SIGTERM, cctx->event);
}
-static void cmd_reload(struct doveadm_cmd_context *cctx ATTR_UNUSED)
+static void cmd_reload(struct doveadm_cmd_context *cctx)
{
- doveadm_master_send_signal(SIGHUP);
+ doveadm_master_send_signal(SIGHUP, cctx->event);
}
static struct istream *master_service_send_cmd(const char *cmd)
alarm(5);
if ((line = i_stream_read_next_line(input)) == NULL) {
- i_error("read(%s) failed: %s", i_stream_get_name(input),
+ e_error(cctx->event, "read(%s) failed: %s", i_stream_get_name(input),
i_stream_get_error(input));
doveadm_exit_code = EX_TEMPFAIL;
} else if (line[0] == '-') {
doveadm_exit_code = DOVEADM_EX_NOTFOUND;
- i_error("%s", line+1);
+ e_error(cctx->event, "%s", line+1);
} else if (line[0] != '+') {
- i_error("Unexpected input from %s: %s",
+ e_error(cctx->event, "Unexpected input from %s: %s",
i_stream_get_name(input), line);
doveadm_exit_code = EX_TEMPFAIL;
}
} T_END;
}
if (line == NULL) {
- i_error("read(%s) failed: %s", i_stream_get_name(input),
+ e_error(cctx->event, "read(%s) failed: %s", i_stream_get_name(input),
i_stream_get_error(input));
doveadm_exit_code = EX_TEMPFAIL;
}
} T_END;
}
if (line == NULL) {
- i_error("read(%s) failed: %s", i_stream_get_name(input),
+ e_error(cctx->event, "read(%s) failed: %s", i_stream_get_name(input),
i_stream_get_error(input));
doveadm_exit_code = EX_TEMPFAIL;
}
str_truncate(str, 0);
if (from_utf8) {
if (imap_utf8_to_utf7(names[i], str) < 0) {
- i_error("Mailbox name not valid UTF-8: %s",
+ e_error(cctx->event,
+ "Mailbox name not valid UTF-8: %s",
names[i]);
doveadm_exit_code = EX_DATAERR;
}
} else {
if (imap_utf7_to_utf8(names[i], str) < 0) {
- i_error("Mailbox name not valid mUTF-7: %s",
+ e_error(cctx->event,
+ "Mailbox name not valid mUTF-7: %s",
names[i]);
doveadm_exit_code = EX_DATAERR;
}
if (doveadm_cmd_param_str(cctx, "netmask", &netmask)) {
if (net_parse_range(netmask, &ctx.net_ip, &ctx.net_bits) != 0) {
doveadm_exit_code = EX_USAGE;
- i_error("Invalid netmask '%s' given", netmask);
+ e_error(cctx->event, "Invalid netmask '%s' given", netmask);
return;
}
}
plaintext = t_askpass("Enter new password: ");
check = t_askpass("Retype new password: ");
if (strcmp(plaintext, check) != 0) {
- i_error("Passwords don't match!");
+ e_error(cctx->event, "Passwords don't match!");
if (--lives == 0)
lib_exit(1);
plaintext = NULL;
} T_END;
}
if (line == NULL) {
- i_error("Replicator disconnected unexpectedly");
+ e_error(cctx->event, "Replicator disconnected unexpectedly");
doveadm_exit_code = EX_TEMPFAIL;
}
replicator_disconnect(ctx);
line = i_stream_read_next_line(ctx->input);
if (line == NULL) {
- i_error("Replicator disconnected unexpectedly");
+ e_error(cctx->event, "Replicator disconnected unexpectedly");
doveadm_exit_code = EX_TEMPFAIL;
} else if (line[0] != '+') {
- i_error("Replicator failed: %s", line+1);
+ e_error(cctx->event, "Replicator failed: %s", line+1);
doveadm_exit_code = EX_USAGE;
} else {
doveadm_print(t_strdup_printf("%s users updated", line+1));
line = i_stream_read_next_line(ctx->input);
if (line == NULL) {
- i_error("Replicator disconnected unexpectedly");
+ e_error(cctx->event, "Replicator disconnected unexpectedly");
doveadm_exit_code = EX_TEMPFAIL;
} else if (line[0] != '+') {
- i_error("Replicator failed: %s", line+1);
+ e_error(cctx->event, "Replicator failed: %s", line+1);
doveadm_exit_code = EX_USAGE;
}
replicator_disconnect(ctx);
line = i_stream_read_next_line(ctx->input);
if (line == NULL) {
- i_error("Replicator disconnected unexpectedly");
+ e_error(cctx->event, "Replicator disconnected unexpectedly");
doveadm_exit_code = EX_TEMPFAIL;
} else if (line[0] != '+') {
- i_error("Replicator failed: %s", line+1);
+ e_error(cctx->event, "Replicator failed: %s", line+1);
doveadm_exit_code = EX_USAGE;
}
replicator_disconnect(ctx);
}
}
if (closedir(dir) < 0)
- i_error("closedir(%s) failed: %m", path);
+ e_error(cctx->event, "closedir(%s) failed: %m", path);
}
struct doveadm_cmd_ver2 doveadm_cmd_sis_deduplicate = {
const char *build_cmd_error;
ctx.cctx = cctx;
if (vfuncs->build_cmd(&ctx, &build_cmd_error) < 0) {
- i_error("%s", build_cmd_error);
+ e_error(cctx->event, "%s", build_cmd_error);
return;
}
stats_send_cmd(&ctx);
static void handle_disconnection(struct stats_cmd_context *ctx)
{
- i_error("read(%s) failed: %s", ctx->path,
+ e_error(ctx->cctx->event, "read(%s) failed: %s", ctx->path,
i_stream_get_disconnect_reason(ctx->input));
}
return;
}
if (line[0] == '-')
- i_error("%s", ++line);
+ e_error(ctx->cctx->event, "%s", ++line);
else if (line[0] != '+')
- i_error("Invalid response: %s", line);
+ e_error(ctx->cctx->event, "Invalid response: %s", line);
}
static int build_stats_remove_cmd(struct stats_cmd_context *ctx,
void usage(void) ATTR_NORETURN;
void help_ver2(const struct doveadm_cmd_ver2 *cmd) ATTR_NORETURN;
-void doveadm_master_send_signal(int signo);
+void doveadm_master_send_signal(int signo, struct event *event);
#endif