Skip to content

Commit

Permalink
global: Use [io]_stream_get_error() insted of %m
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed May 18, 2016
1 parent 43cc944 commit 0f3d4fb
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 96 deletions.
3 changes: 2 additions & 1 deletion src/auth/mech-winbind.c
Expand Up @@ -180,7 +180,8 @@ do_auth_continue(struct auth_request *auth_request,
str_data(str), str_len(str)) < 0 ||
o_stream_flush(request->winbind->out_pipe) < 0) {
auth_request_log_error(auth_request, AUTH_SUBSYS_MECH,
"write(out_pipe) failed: %m");
"write(out_pipe) failed: %s",
o_stream_get_error(request->winbind->out_pipe));
return HR_RESTART;
}
request->continued = FALSE;
Expand Down
3 changes: 2 additions & 1 deletion src/auth/userdb-passwd-file.c
Expand Up @@ -139,7 +139,8 @@ static void passwd_file_iterate_next(struct userdb_iterate_context *_ctx)
break;
}
if (line == NULL && ctx->input->stream_errno != 0) {
i_error("read(%s) failed: %m", ctx->path);
i_error("read(%s) failed: %s", ctx->path,
i_stream_get_error(ctx->input));
_ctx->failed = TRUE;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/director/director-connection.c
Expand Up @@ -2051,9 +2051,10 @@ void director_connection_send(struct director_connection *conn,
} T_END;
ret = o_stream_send(conn->output, data, len);
if (ret != (off_t)len) {
if (ret < 0)
i_error("director(%s): write() failed: %m", conn->name);
else {
if (ret < 0) {
i_error("director(%s): write() failed: %s", conn->name,
o_stream_get_error(conn->output));
} else {
i_error("director(%s): Output buffer full, "
"disconnecting", conn->name);
}
Expand Down
15 changes: 9 additions & 6 deletions src/doveadm/doveadm-director.c
Expand Up @@ -60,11 +60,12 @@ static void director_connect(struct director_context *ctx)
line = i_stream_read_next_line(ctx->input);
alarm(0);
if (line == NULL) {
if (ctx->input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->socket_path);
else if (ctx->input->eof)
if (ctx->input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->socket_path,
i_stream_get_error(ctx->input));
} else if (ctx->input->eof) {
i_fatal("%s disconnected", ctx->socket_path);
else {
} else {
i_fatal("read(%s) timed out (is director configured?)",
ctx->socket_path);
}
Expand All @@ -79,8 +80,10 @@ static void director_connect(struct director_context *ctx)
static void director_disconnect(struct director_context *ctx)
{
if (ctx->input != NULL) {
if (ctx->input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->socket_path);
if (ctx->input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->socket_path,
i_stream_get_error(ctx->input));
}
i_stream_destroy(&ctx->input);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/doveadm/doveadm-penalty.c
Expand Up @@ -80,8 +80,10 @@ static void penalty_lookup(struct penalty_context *ctx)
penalty_print_line(ctx, &penalty_line);
} T_END;
}
if (input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->anvil_path);
if (input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->anvil_path,
i_stream_get_error(input));
}

i_stream_destroy(&input);
}
Expand Down
13 changes: 8 additions & 5 deletions src/doveadm/doveadm-replicator.c
Expand Up @@ -48,9 +48,10 @@ static void replicator_connect(struct replicator_context *ctx)
line = i_stream_read_next_line(ctx->input);
alarm(0);
if (line == NULL) {
if (ctx->input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->socket_path);
else if (ctx->input->eof)
if (ctx->input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->socket_path,
i_stream_get_error(ctx->input));
} else if (ctx->input->eof)
i_fatal("%s disconnected", ctx->socket_path);
else
i_fatal("read(%s) timed out", ctx->socket_path);
Expand All @@ -64,8 +65,10 @@ static void replicator_connect(struct replicator_context *ctx)

static void replicator_disconnect(struct replicator_context *ctx)
{
if (ctx->input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->socket_path);
if (ctx->input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->socket_path,
i_stream_get_error(ctx->input));
}
i_stream_destroy(&ctx->input);
}

Expand Down
8 changes: 5 additions & 3 deletions src/doveadm/doveadm-stats.c
Expand Up @@ -111,7 +111,7 @@ static void stats_dump(const char *path, const char *cmd)
} while (args != NULL);
}
if (input->stream_errno != 0)
i_fatal("read(%s) failed: %m", path);
i_fatal("read(%s) failed: %s", path, i_stream_get_error(input));
i_stream_destroy(&input);
}

Expand Down Expand Up @@ -194,8 +194,10 @@ static void stats_read(struct top_context *ctx)
hash_table_insert(ctx->sessions, line->id, line);
}

if (ctx->input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->path);
if (ctx->input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->path,
i_stream_get_error(ctx->input));
}
i_fatal("read(%s): unexpected EOF", ctx->path);
}

Expand Down
6 changes: 4 additions & 2 deletions src/doveadm/doveadm-who.c
Expand Up @@ -169,8 +169,10 @@ void who_lookup(struct who_context *ctx, who_callback_t *callback)
callback(ctx, &who_line);
} T_END;
}
if (input->stream_errno != 0)
i_fatal("read(%s) failed: %m", ctx->anvil_path);
if (input->stream_errno != 0) {
i_fatal("read(%s) failed: %s", ctx->anvil_path,
i_stream_get_error(input));
}

i_stream_destroy(&input);
}
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-zlib.c
Expand Up @@ -122,8 +122,8 @@ static void server_input(struct client *client)

if (i_stream_read(client->input) == -1) {
if (client->input->stream_errno != 0) {
errno = client->input->stream_errno;
i_fatal("read(server) failed: %m");
i_fatal("read(server) failed: %s",
i_stream_get_error(client->input));
}

i_info("Server disconnected");
Expand Down
3 changes: 2 additions & 1 deletion src/lib-auth/auth-master.c
Expand Up @@ -413,7 +413,8 @@ static int auth_master_run_cmd_pre(struct auth_master_connection *conn,
o_stream_uncork(conn->output);

if (o_stream_nfinish(conn->output) < 0) {
i_error("write(auth socket) failed: %m");
i_error("write(auth socket) failed: %s",
o_stream_get_error(conn->output));
auth_master_unset_io(conn);
auth_connection_close(conn);
return -1;
Expand Down
5 changes: 3 additions & 2 deletions src/lib-auth/auth-server-connection.c
Expand Up @@ -453,9 +453,10 @@ int auth_server_connection_connect(struct auth_server_connection *conn)
AUTH_CLIENT_PROTOCOL_MINOR_VERSION,
conn->client->client_pid);
if (o_stream_send_str(conn->output, handshake) < 0) {
i_warning("Error sending handshake to auth server: %m");
i_warning("Error sending handshake to auth server: %s",
o_stream_get_error(conn->output));
auth_server_connection_disconnect(conn,
strerror(conn->output->last_failed_errno));
o_stream_get_error(conn->output));
return -1;
}

Expand Down
25 changes: 13 additions & 12 deletions src/lib-http/http-server-response.c
Expand Up @@ -142,8 +142,8 @@ void http_server_response_set_payload(struct http_server_response *resp,
resp->payload_input = input;
if ((ret = i_stream_get_size(input, TRUE, &resp->payload_size)) <= 0) {
if (ret < 0) {
i_error("i_stream_get_size(%s) failed: %m",
i_stream_get_name(input));
i_error("i_stream_get_size(%s) failed: %s",
i_stream_get_name(input), i_stream_get_error(input));
}
resp->payload_size = 0;
resp->payload_chunked = TRUE;
Expand Down Expand Up @@ -500,16 +500,16 @@ int http_server_response_send_more(struct http_server_response *resp,
if (resp->payload_input->stream_errno != 0) {
/* we're in the middle of sending a response, so the connection
will also have to be aborted */
errno = resp->payload_input->stream_errno;
*error_r = t_strdup_printf("read(%s) failed: %m",
i_stream_get_name(resp->payload_input));
*error_r = t_strdup_printf("read(%s) failed: %s",
i_stream_get_name(resp->payload_input),
i_stream_get_error(resp->payload_input));
ret = -1;
} else if (output->stream_errno != 0) {
/* failed to send response */
errno = output->stream_errno;
if (errno != EPIPE && errno != ECONNRESET) {
*error_r = t_strdup_printf("write(%s) failed: %m",
o_stream_get_name(output));
if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
*error_r = t_strdup_printf("write(%s) failed: %s",
o_stream_get_name(output), o_stream_get_error(output));
}
ret = -1;
} else {
Expand Down Expand Up @@ -646,9 +646,10 @@ static int http_server_response_send_real(struct http_server_response *resp,
o_stream_ref(output);
o_stream_cork(output);
if (o_stream_sendv(output, iov, N_ELEMENTS(iov)) < 0) {
if (errno != EPIPE && errno != ECONNRESET) {
*error_r = t_strdup_printf("write(%s) failed: %m",
o_stream_get_name(output));
if (output->stream_errno != EPIPE &&
output->stream_errno != ECONNRESET) {
*error_r = t_strdup_printf("write(%s) failed: %s",
o_stream_get_name(output), o_stream_get_error(output));
}
ret = -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib-index/mail-index-strmap.c
Expand Up @@ -1017,8 +1017,8 @@ static int mail_index_strmap_recreate(struct mail_index_strmap_view *view)
o_stream_cork(output);
mail_index_strmap_recreate_write(view, output);
if (o_stream_nfinish(output) < 0) {
mail_index_set_error(strmap->index,
"write(%s) failed: %m", temp_path);
mail_index_set_error(strmap->index, "write(%s) failed: %s",
temp_path, o_stream_get_error(output));
ret = -1;
}
o_stream_destroy(&output);
Expand Down
3 changes: 2 additions & 1 deletion src/lib-lda/duplicate.c
Expand Up @@ -317,7 +317,8 @@ void duplicate_flush(struct duplicate_context *ctx)
hash_table_iterate_deinit(&iter);

if (o_stream_nfinish(output) < 0) {
i_error("write(%s) failed: %m", file->path);
i_error("write(%s) failed: %s", file->path,
o_stream_get_error(output));
o_stream_unref(&output);
duplicate_file_free(&ctx->file);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/lib-lda/lmtp-client.c
Expand Up @@ -603,8 +603,8 @@ static void lmtp_client_input(struct lmtp_client *client)
lmtp_client_fail(client,
"501 5.5.4 Command reply line too long");
} else if (client->input->stream_errno != 0) {
errno = client->input->stream_errno;
i_error("lmtp client: read() failed: %m");
i_error("lmtp client: read() failed: %s",
i_stream_get_error(client->input));
lmtp_client_fail(client, ERRSTR_TEMP_REMOTE_FAILURE
" (read failure)");
} else if (client->input->eof) {
Expand Down
8 changes: 4 additions & 4 deletions src/lib-lda/smtp-client.c
Expand Up @@ -265,14 +265,14 @@ smtp_client_send_flush(struct smtp_client *smtp_client,
}

if (o_stream_nfinish(smtp_client->output) < 0) {
*error_r = t_strdup_printf("write(%s) failed: %m",
smtp_client->temp_path);
*error_r = t_strdup_printf("write(%s) failed: %s",
smtp_client->temp_path, o_stream_get_error(smtp_client->output));
return -1;
}

if (o_stream_seek(smtp_client->output, 0) < 0) {
*error_r = t_strdup_printf("lseek(%s) failed: %m",
smtp_client->temp_path);
*error_r = t_strdup_printf("lseek(%s) failed: %s",
smtp_client->temp_path, o_stream_get_error(smtp_client->output));
return -1;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib-master/anvil-client.c
Expand Up @@ -113,7 +113,8 @@ static void anvil_input(struct anvil_client *client)
aqueue_delete_tail(client->queries);
}
if (client->input->stream_errno != 0) {
i_error("read(%s) failed: %m", client->path);
i_error("read(%s) failed: %s", client->path,
i_stream_get_error(client->input));
anvil_reconnect(client);
} else if (client->input->eof) {
i_error("read(%s) failed: EOF", client->path);
Expand Down
4 changes: 2 additions & 2 deletions src/lib-master/master-instance.c
Expand Up @@ -116,7 +116,7 @@ static int master_instance_list_refresh(struct master_instance_list *list)
i_error("Invalid line in %s: %s", list->path, line);
} T_END;
if (input->stream_errno != 0) {
i_error("read(%s) failed: %m", line);
i_error("read(%s) failed: %s", line, i_stream_get_error(input));
ret = -1;
}
i_stream_destroy(&input);
Expand Down Expand Up @@ -147,7 +147,7 @@ master_instance_list_write(struct master_instance_list *list,
o_stream_nsend(output, str_data(str), str_len(str));
}
if (o_stream_nfinish(output) < 0) {
i_error("write(%s) failed: %m", path);
i_error("write(%s) failed: %s", path, o_stream_get_error(output));
ret = -1;
}
o_stream_destroy(&output);
Expand Down
3 changes: 2 additions & 1 deletion src/lib-master/master-service-settings.c
Expand Up @@ -327,7 +327,8 @@ config_read_reply_header(struct istream *istream, const char *path, pool_t pool,
if (ret == 0)
return 1;
*error_r = istream->stream_errno != 0 ?
t_strdup_printf("read(%s) failed: %m", path) :
t_strdup_printf("read(%s) failed: %s", path,
i_stream_get_error(istream)) :
t_strdup_printf("read(%s) failed: EOF", path);
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib-storage/index/cydir/cydir-save.c
Expand Up @@ -151,7 +151,8 @@ static int cydir_save_flush(struct cydir_save_context *ctx, const char *path)
int ret = 0;

if (o_stream_nfinish(ctx->ctx.data.output) < 0) {
mail_storage_set_critical(storage, "write(%s) failed: %m", path);
mail_storage_set_critical(storage, "write(%s) failed: %s", path,
o_stream_get_error(ctx->ctx.data.output));
ret = -1;
}

Expand Down
20 changes: 10 additions & 10 deletions src/lib-storage/index/dbox-multi/mdbox-purge.c
Expand Up @@ -78,7 +78,8 @@ mdbox_file_read_metadata_hdr(struct dbox_file *file,
return 0;
}
mail_storage_set_critical(&file->storage->storage,
"read(%s) failed: %m", file->cur_path);
"read(%s) failed: %s", file->cur_path,
i_stream_get_error(file->input));
return -1;
}

Expand Down Expand Up @@ -191,7 +192,6 @@ mdbox_purge_save_msg(struct mdbox_purge_context *ctx, struct dbox_file *file,
enum mdbox_map_append_flags append_flags;
uoff_t msg_size;
off_t ret;
int read_errno;

if (ctx->append_ctx == NULL)
ctx->append_ctx = mdbox_map_append_begin(ctx->atomic);
Expand All @@ -207,19 +207,19 @@ mdbox_purge_save_msg(struct mdbox_purge_context *ctx, struct dbox_file *file,

input = i_stream_create_limit(file->input, msg_size);
ret = o_stream_send_istream(output, input);
read_errno = input->stream_errno;
i_stream_unref(&input);

if (read_errno != 0) {
errno = read_errno;
if (input->stream_errno != 0) {
mail_storage_set_critical(&file->storage->storage,
"read(%s) failed: %m", file->cur_path);
"read(%s) failed: %s", file->cur_path,
i_stream_get_error(input));
i_stream_unref(&input);
return -1;
}
i_stream_unref(&input);
if (o_stream_nfinish(output) < 0) {
mail_storage_set_critical(&file->storage->storage,
"write(%s) failed: %m",
out_file_append->file->cur_path);
"write(%s) failed: %s",
out_file_append->file->cur_path,
o_stream_get_error(output));
return -1;
}
if (ret != (off_t)msg_size) {
Expand Down
15 changes: 5 additions & 10 deletions src/lib-storage/index/dbox-single/sdbox-file.c
Expand Up @@ -323,20 +323,15 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)

output = o_stream_create_fd_file(out_fd, 0, FALSE);
i_stream_seek(file->input, 0);
while ((ret = o_stream_send_istream(output, file->input)) > 0) ;
ret = o_stream_send_istream(output, file->input) > 0 ? 0 : -1;
if (o_stream_nfinish(output) < 0) {
mail_storage_set_critical(storage, "write(%s) failed: %m",
temp_path);
mail_storage_set_critical(storage, "write(%s) failed: %s",
temp_path, o_stream_get_error(output));
ret = -1;
} else if (file->input->stream_errno != 0) {
errno = file->input->stream_errno;
dbox_file_set_syscall_error(file, "ftruncate()");
mail_storage_set_critical(storage, "read(%s) failed: %s",
temp_path, i_stream_get_error(file->input));
ret = -1;
} else if (ret < 0) {
mail_storage_set_critical(storage,
"o_stream_send_istream(%s, %s) "
"failed with unknown error",
temp_path, file->cur_path);
}
o_stream_unref(&output);

Expand Down

0 comments on commit 0f3d4fb

Please sign in to comment.