if (conn->output != NULL)
o_stream_close(conn->output);
io_remove(&conn->io);
- if (conn->fd != -1) {
- if (close(conn->fd) < 0)
- i_error("close(%s): %m", conn->path);
- conn->fd = -1;
- }
+ i_close_fd_path(&conn->fd, conn->path);
master_service_client_connection_destroyed(master_service);
auth_master_connection_unref(&conn);
if (conn->output != NULL)
o_stream_close(conn->output);
io_remove(&conn->io);
- if (conn->fd != -1) {
- if (close(conn->fd) < 0)
- i_error("close(%s): %m", conn->path);
- conn->fd = -1;
- }
+ i_close_fd_path(&conn->fd, conn->path);
master_service_client_connection_destroyed(master_service);
auth_postfix_connection_unref(&conn);
io_remove(&request->io_in);
io_remove(&request->io_out);
- if (request->fd_in != -1) {
- if (close(request->fd_in) < 0)
- i_error("checkpassword: close() failed: %m");
- request->fd_in = -1;
- }
- if (request->fd_out != -1) {
- if (close(request->fd_out) < 0)
- i_error("checkpassword: close() failed: %m");
- }
+ i_close_fd(&request->fd_in);
+ i_close_fd(&request->fd_out);
}
static void checkpassword_request_free(struct chkpw_auth_request **_request)
static void passwd_file_close(struct passwd_file *pw)
{
- if (pw->fd != -1) {
- if (close(pw->fd) < 0)
- i_error("passwd-file %s: close() failed: %m", pw->path);
- pw->fd = -1;
- }
+ i_close_fd_path(&pw->fd, pw->path);
if (hash_table_is_created(pw->users))
hash_table_destroy(&pw->users);
if (conn->ssl_iostream != NULL)
ssl_iostream_unref(&conn->ssl_iostream);
io_remove(&conn->io);
- if (conn->fd != -1) {
- if (close(conn->fd) < 0)
- i_error("close(server) failed: %m");
- }
+ i_close_fd(&conn->fd);
pool_unref(&conn->pool);
}
static void auth_connection_close(struct auth_master_connection *conn)
{
timeout_remove(&conn->to);
- if (conn->fd != -1) {
- if (close(conn->fd) < 0)
- i_error("close(%s) failed: %m", conn->auth_socket_path);
- conn->fd = -1;
- }
+ i_close_fd_path(&conn->fd, conn->auth_socket_path);
conn->sent_handshake = FALSE;
conn->handshaked = FALSE;
/* we can safely deinit unallocated cdb */
cdb_free(&dict->cdb);
- if (dict->fd != -1) {
- if (close(dict->fd) < 0)
- i_error("close(%s) failed: %m", dict->path);
- }
+ i_close_fd_path(&dict->fd, dict->path);
i_free(dict->path);
i_free(dict);
{
struct file_dict *dict = (struct file_dict *)_dict;
- if (dict->fd != -1) {
- if (close(dict->fd) < 0)
- i_error("close(%s) failed: %m", dict->path);
- }
+ i_close_fd_path(&dict->fd, dict->path);
hash_table_destroy(&dict->hash);
pool_unref(&dict->hash_pool);
i_free(dict->path);
if (!file_dict_need_refresh(dict))
return 0;
- if (dict->fd != -1) {
- if (close(dict->fd) < 0)
- i_error("close(%s) failed: %m", dict->path);
- }
+ i_close_fd_path(&dict->fd, dict->path);
open_type = dict->lock_method == FILE_LOCK_METHOD_DOTLOCK ?
O_RDONLY : O_RDWR;
timeout_remove(&client->to_idle);
io_remove(&client->io);
i_stream_destroy(&client->input);
- if (client->fd != -1) {
- if (close(client->fd) < 0)
- i_error("close(%s) failed: %m", client->path);
- client->fd = -1;
- }
+ i_close_fd_path(&client->fd, client->path);
i_zero(&result);
result.ret = EAI_FAIL;
static void
imapc_connection_literal_reset(struct imapc_connection_literal *literal)
{
- if (literal->fd != -1) {
- if (close(literal->fd) < 0)
- i_error("close(%s) failed: %m", literal->temp_path);
- }
+ i_close_fd_path(&literal->fd, literal->temp_path);
i_free_and_null(literal->temp_path);
i_zero(literal);
static void mailbox_log_close(struct mailbox_log *log)
{
- if (log->fd != -1) {
- if (close(log->fd) < 0)
- i_error("close(%s) failed: %m", log->filepath);
- log->fd = -1;
- }
+ i_close_fd_path(&log->fd, log->filepath);
}
void mailbox_log_set_permissions(struct mailbox_log *log, mode_t mode,
static bool mailbox_log_iter_open_next(struct mailbox_log_iter *iter)
{
- if (iter->fd != -1) {
- if (close(iter->fd) < 0)
- i_error("close(%s) failed: %m", iter->filepath);
- iter->fd = -1;
- }
+ i_close_fd_path(&iter->fd, iter->filepath);
if (iter->filepath == NULL)
iter->filepath = iter->log->filepath2;
else if (iter->filepath == iter->log->filepath2)
*_iter = NULL;
- if (iter->fd != -1) {
- if (close(iter->fd) < 0)
- i_error("close(%s) failed: %m", iter->filepath);
- }
+ i_close_fd_path(&iter->fd, iter->filepath);
i_free(iter);
return ret;
}
master_login_conn_close(conn);
master_login_conn_unref(&conn);
}
- if (client_fd != -1) {
- if (close(client_fd) < 0)
- i_error("close(fd_read client) failed: %m");
- }
+ i_close_fd(&client_fd);
return;
}
fd_close_on_exec(client_fd, TRUE);
void master_service_close_config_fd(struct master_service *service)
{
- if (service->config_fd != -1) {
- if (close(service->config_fd) < 0)
- i_error("close(master config fd) failed: %m");
- service->config_fd = -1;
- }
+ i_close_fd(&service->config_fd);
}
void master_service_deinit(struct master_service **_service)
return;
*_conn = NULL;
- if (conn->fd != -1) {
- if (close(conn->fd) < 0)
- i_error("close(%s) failed: %m", conn->path);
- }
+ i_close_fd_path(&conn->fd, conn->path);
i_free(conn->path);
i_free(conn);
}
hdr_stream = i_stream_create_fd_autoclose(&mail->fd, 0);
}
index_mail_close_streams(imail);
- if (mail->fd != -1) {
- if (close(mail->fd) < 0)
- i_error("close(imapc mail) failed: %m");
- mail->fd = -1;
- }
+ i_close_fd(&mail->fd);
} else {
if (!have_header) {
/* BODY.PEEK[TEXT] received - we can't currently handle
mail->body = NULL;
}
}
- if (mail->fd != -1) {
- if (close(mail->fd) < 0)
- i_error("close(imapc mail) failed: %m");
- mail->fd = -1;
- }
+ i_close_fd(&mail->fd);
buffer_free(&mail->body);
mail->header_fetched = FALSE;
mail->body_fetched = FALSE;
o_stream_unref(&_ctx->data.output);
i_stream_unref(&ctx->input);
- if (ctx->fd != -1) {
- if (close(ctx->fd) < 0)
- i_error("close(%s) failed: %m", ctx->temp_path);
- ctx->fd = -1;
- }
+ i_close_fd_path(&ctx->fd, ctx->temp_path);
i_free(ctx->temp_path);
index_save_context_free(_ctx);
return ctx->failed ? -1 : 0;
void imapc_mail_cache_free(struct imapc_mail_cache *cache)
{
- if (cache->fd != -1) {
- if (close(cache->fd) < 0)
- i_error("close(imapc cached mail) failed: %m");
- cache->fd = -1;
- }
+ i_close_fd(&cache->fd);
buffer_free(&cache->buf);
cache->uid = 0;
}
o_stream_destroy(&client->output);
if (client->ssl_iostream != NULL)
ssl_iostream_unref(&client->ssl_iostream);
- if (client->fd != -1) {
- if (close(client->fd) < 0)
- i_error("close(pop3c) failed: %m");
- client->fd = -1;
- }
+ i_close_fd(&client->fd);
while (array_count(&client->commands) > 0)
pop3c_client_async_callback_disconnected(client);
client_login_callback(client, POP3C_COMMAND_STATE_DISCONNECTED,
io_remove(&_io);
}
- if (ctx->inotify_fd != -1) {
- if (close(ctx->inotify_fd) < 0)
- i_error("close(inotify) failed: %m");
- ctx->inotify_fd = -1;
- }
+ i_close_fd(&ctx->inotify_fd);
i_free(ctx);
}
buffer_free(&client->state.mail_data);
o_stream_unref(&client->state.mail_data_output);
- if (client->state.mail_data_fd != -1) {
- if (close(client->state.mail_data_fd) < 0)
- i_error("close(mail data fd) failed: %m");
- }
+ i_close_fd(&client->state.mail_data_fd);
i_zero(&client->state);
p_clear(client->state_pool);
static void login_proxy_state_close(struct login_proxy_state *state)
{
- if (state->notify_fd != -1) {
- if (close(state->notify_fd) < 0)
- i_error("close(%s) failed: %m", state->notify_path);
- state->notify_fd = -1;
- }
+ i_close_fd_path(&state->notify_fd, state->notify_path);
}
void login_proxy_state_deinit(struct login_proxy_state **_state)
trie->mmap_base = NULL;
trie->mmap_size = 0;
}
- if (trie->fd != -1) {
- if (close(trie->fd) < 0)
- i_error("close(%s) failed: %m", trie->path);
- trie->fd = -1;
- }
+ i_close_fd_path(&trie->fd, trie->path);
}
static void squat_trie_close(struct squat_trie *trie)
file_lock_free(&uidlist->file_lock);
if (uidlist->dotlock != NULL)
file_dotlock_delete(&uidlist->dotlock);
- if (uidlist->fd != -1) {
- if (close(uidlist->fd) < 0)
- i_error("close(%s) failed: %m", uidlist->path);
- uidlist->fd = -1;
- }
+ i_close_fd_path(&uidlist->fd, uidlist->path);
uidlist->corrupted = FALSE;
}
i_stream_destroy(&mstream->ext_in);
o_stream_destroy(&mstream->ext_out);
- if (mstream->fd != -1) {
- if (close(mstream->fd) < 0)
- i_error("ext-filter: close() failed: %m");
- mstream->fd = -1;
- }
+ i_close_fd(&mstream->fd);
if (close_parent)
i_stream_close(mstream->istream.parent);
}
i_stream_destroy(&mstream->ext_in);
o_stream_destroy(&mstream->ext_out);
- if (mstream->fd != -1) {
- if (close(mstream->fd) < 0)
- i_error("ext-filter: close() failed: %m");
- mstream->fd = -1;
- }
+ i_close_fd(&mstream->fd);
if (close_parent)
o_stream_close(mstream->ostream.parent);
}
return;
#ifdef FS_QUOTA_SOLARIS
- if (mount->fd != -1) {
- if (close(mount->fd) < 0)
- i_error("close(%s) failed: %m", mount->path);
- }
+ i_close_fd_path(&mount->fd, mount->path);
i_free(mount->path);
#endif
static int maildirsize_open(struct maildir_quota_root *root)
{
- if (root->fd != -1) {
- if (close(root->fd) < 0)
- i_error("close(%s) failed: %m", root->maildirsize_path);
- }
+ i_close_fd_path(&root->fd, root->maildirsize_path);
root->fd = nfs_safe_open(root->maildirsize_path, O_RDWR | O_APPEND);
if (root->fd == -1) {
void replication_plugin_deinit(void)
{
- if (fifo_fd != -1) {
- if (close(fifo_fd) < 0)
- i_error("close(%s) failed: %m", fifo_path);
- fifo_fd = -1;
- }
+ i_close_fd_path(&fifo_fd, fifo_path);
i_free_and_null(fifo_path);
mail_storage_hooks_remove(&replication_mail_storage_hooks);
i_error("Invalid input from client");
}
- if (check_fd != -1) {
- if (close(check_fd) < 0)
- i_error("close(fdread fd) failed: %m");
- }
+ i_close_fd(&check_fd);
tcpwrap_client_destroy(&client);
}