From: Josef 'Jeff' Sipek Date: Tue, 19 Sep 2017 12:54:35 +0000 (+0300) Subject: global: use i_close_fd{,_path}() instead of open-coding them X-Git-Tag: 2.3.0.rc1~943 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a943ed0f901e312445fd393249b91932797bba79;p=thirdparty%2Fdovecot%2Fcore.git global: use i_close_fd{,_path}() instead of open-coding them --- diff --git a/src/auth/auth-master-connection.c b/src/auth/auth-master-connection.c index 7f3d7f36f6..0f0c9eee9f 100644 --- a/src/auth/auth-master-connection.c +++ b/src/auth/auth-master-connection.c @@ -787,11 +787,7 @@ void auth_master_connection_destroy(struct auth_master_connection **_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_master_connection_unref(&conn); diff --git a/src/auth/auth-postfix-connection.c b/src/auth/auth-postfix-connection.c index 9ab0adeab7..0abe498b4a 100644 --- a/src/auth/auth-postfix-connection.c +++ b/src/auth/auth-postfix-connection.c @@ -201,11 +201,7 @@ auth_postfix_connection_destroy(struct auth_postfix_connection **_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); diff --git a/src/auth/db-checkpassword.c b/src/auth/db-checkpassword.c index 1f2ebb03ae..9d89a9d787 100644 --- a/src/auth/db-checkpassword.c +++ b/src/auth/db-checkpassword.c @@ -66,15 +66,8 @@ static void checkpassword_request_close(struct chkpw_auth_request *request) 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) diff --git a/src/auth/db-passwd-file.c b/src/auth/db-passwd-file.c index 8aa3abb2ea..ff6bebfc80 100644 --- a/src/auth/db-passwd-file.c +++ b/src/auth/db-passwd-file.c @@ -234,11 +234,7 @@ static int passwd_file_open(struct passwd_file *pw, bool startup, 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); diff --git a/src/doveadm/server-connection.c b/src/doveadm/server-connection.c index 2c80395728..c22d60c93e 100644 --- a/src/doveadm/server-connection.c +++ b/src/doveadm/server-connection.c @@ -559,10 +559,7 @@ void server_connection_destroy(struct server_connection **_conn) 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); } diff --git a/src/lib-auth/auth-master.c b/src/lib-auth/auth-master.c index 85b0790e34..b4f3a30e42 100644 --- a/src/lib-auth/auth-master.c +++ b/src/lib-auth/auth-master.c @@ -83,11 +83,7 @@ auth_master_init(const char *auth_socket_path, enum auth_master_flags flags) 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; diff --git a/src/lib-dict/dict-cdb.c b/src/lib-dict/dict-cdb.c index 1c23a784c7..cb66cb0f43 100644 --- a/src/lib-dict/dict-cdb.c +++ b/src/lib-dict/dict-cdb.c @@ -76,10 +76,7 @@ static void cdb_dict_deinit(struct dict *_dict) /* 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); diff --git a/src/lib-dict/dict-file.c b/src/lib-dict/dict-file.c index a35a9c480e..6c16f1d435 100644 --- a/src/lib-dict/dict-file.c +++ b/src/lib-dict/dict-file.c @@ -96,10 +96,7 @@ static void file_dict_deinit(struct dict *_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); @@ -149,10 +146,7 @@ static int file_dict_open_latest(struct file_dict *dict, const char **error_r) 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; diff --git a/src/lib-dns/dns-lookup.c b/src/lib-dns/dns-lookup.c index abe83a6cc8..ed6376ab28 100644 --- a/src/lib-dns/dns-lookup.c +++ b/src/lib-dns/dns-lookup.c @@ -62,11 +62,7 @@ static void dns_client_disconnect(struct dns_client *client, const char *error) 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; diff --git a/src/lib-imap-client/imapc-connection.c b/src/lib-imap-client/imapc-connection.c index dde95b66bc..c3a9fe6f9c 100644 --- a/src/lib-imap-client/imapc-connection.c +++ b/src/lib-imap-client/imapc-connection.c @@ -412,10 +412,7 @@ static void imapc_connection_lfiles_free(struct imapc_connection *conn) 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); diff --git a/src/lib-index/mailbox-log.c b/src/lib-index/mailbox-log.c index 3df958ccaf..90496757b8 100644 --- a/src/lib-index/mailbox-log.c +++ b/src/lib-index/mailbox-log.c @@ -72,11 +72,7 @@ void mailbox_log_free(struct mailbox_log **_log) 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, @@ -199,11 +195,7 @@ int mailbox_log_append(struct mailbox_log *log, 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) @@ -284,10 +276,7 @@ int mailbox_log_iter_deinit(struct mailbox_log_iter **_iter) *_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; } diff --git a/src/lib-master/master-login.c b/src/lib-master/master-login.c index 60e8bfcbd9..ac0181d126 100644 --- a/src/lib-master/master-login.c +++ b/src/lib-master/master-login.c @@ -416,10 +416,7 @@ static void master_login_conn_input(struct master_login_connection *conn) 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); diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 4c669074e2..d1e7707119 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -932,11 +932,7 @@ static void master_service_refresh_login_state(struct master_service *service) 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) diff --git a/src/lib-stats/stats-connection.c b/src/lib-stats/stats-connection.c index 459e7c7827..15ce2ff6f4 100644 --- a/src/lib-stats/stats-connection.c +++ b/src/lib-stats/stats-connection.c @@ -61,10 +61,7 @@ void stats_connection_unref(struct stats_connection **_conn) 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); } diff --git a/src/lib-storage/index/imapc/imapc-mail-fetch.c b/src/lib-storage/index/imapc/imapc-mail-fetch.c index a86660355e..7c1abe822a 100644 --- a/src/lib-storage/index/imapc/imapc-mail-fetch.c +++ b/src/lib-storage/index/imapc/imapc-mail-fetch.c @@ -625,11 +625,7 @@ imapc_fetch_stream(struct imapc_mail *mail, 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 diff --git a/src/lib-storage/index/imapc/imapc-mail.c b/src/lib-storage/index/imapc/imapc-mail.c index 7059f2e8d5..d422eda014 100644 --- a/src/lib-storage/index/imapc/imapc-mail.c +++ b/src/lib-storage/index/imapc/imapc-mail.c @@ -449,11 +449,7 @@ static void imapc_mail_close(struct mail *_mail) 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; diff --git a/src/lib-storage/index/imapc/imapc-save.c b/src/lib-storage/index/imapc/imapc-save.c index 7d98a3305c..4876d0c856 100644 --- a/src/lib-storage/index/imapc/imapc-save.c +++ b/src/lib-storage/index/imapc/imapc-save.c @@ -291,11 +291,7 @@ int imapc_save_finish(struct mail_save_context *_ctx) 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; diff --git a/src/lib-storage/index/imapc/imapc-storage.c b/src/lib-storage/index/imapc/imapc-storage.c index d7332f657a..98585f90dc 100644 --- a/src/lib-storage/index/imapc/imapc-storage.c +++ b/src/lib-storage/index/imapc/imapc-storage.c @@ -763,11 +763,7 @@ static int imapc_mailbox_open(struct mailbox *box) 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; } diff --git a/src/lib-storage/index/pop3c/pop3c-client.c b/src/lib-storage/index/pop3c/pop3c-client.c index b51c622e42..0197626478 100644 --- a/src/lib-storage/index/pop3c/pop3c-client.c +++ b/src/lib-storage/index/pop3c/pop3c-client.c @@ -205,11 +205,7 @@ static void pop3c_client_disconnect(struct pop3c_client *client) 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, diff --git a/src/lib/ioloop-notify-inotify.c b/src/lib/ioloop-notify-inotify.c index 7cc93fbed4..1cef6ceac5 100644 --- a/src/lib/ioloop-notify-inotify.c +++ b/src/lib/ioloop-notify-inotify.c @@ -206,11 +206,7 @@ void io_loop_notify_handler_deinit(struct ioloop *ioloop) 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); } diff --git a/src/lmtp/client.c b/src/lmtp/client.c index 5a47bb4d1f..0d14e708a7 100644 --- a/src/lmtp/client.c +++ b/src/lmtp/client.c @@ -381,10 +381,7 @@ void client_state_reset(struct client *client, const char *state_name) 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); diff --git a/src/login-common/login-proxy-state.c b/src/login-common/login-proxy-state.c index 05509ed356..9815e33d89 100644 --- a/src/login-common/login-proxy-state.c +++ b/src/login-common/login-proxy-state.c @@ -56,11 +56,7 @@ struct login_proxy_state *login_proxy_state_init(const char *notify_path) 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) diff --git a/src/plugins/fts-squat/squat-trie.c b/src/plugins/fts-squat/squat-trie.c index 8d5b5964c3..6188021d72 100644 --- a/src/plugins/fts-squat/squat-trie.c +++ b/src/plugins/fts-squat/squat-trie.c @@ -163,11 +163,7 @@ static void squat_trie_close_fd(struct squat_trie *trie) 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) diff --git a/src/plugins/fts-squat/squat-uidlist.c b/src/plugins/fts-squat/squat-uidlist.c index 34a0b83033..5027f705c7 100644 --- a/src/plugins/fts-squat/squat-uidlist.c +++ b/src/plugins/fts-squat/squat-uidlist.c @@ -557,11 +557,7 @@ static void squat_uidlist_close(struct squat_uidlist *uidlist) 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; } diff --git a/src/plugins/mail-filter/istream-ext-filter.c b/src/plugins/mail-filter/istream-ext-filter.c index 00a92ab826..682fbca5af 100644 --- a/src/plugins/mail-filter/istream-ext-filter.c +++ b/src/plugins/mail-filter/istream-ext-filter.c @@ -29,11 +29,7 @@ i_stream_mail_filter_close(struct iostream_private *stream, bool close_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) i_stream_close(mstream->istream.parent); } diff --git a/src/plugins/mail-filter/ostream-ext-filter.c b/src/plugins/mail-filter/ostream-ext-filter.c index 9eccca6bcd..9d3c91dc9c 100644 --- a/src/plugins/mail-filter/ostream-ext-filter.c +++ b/src/plugins/mail-filter/ostream-ext-filter.c @@ -28,11 +28,7 @@ o_stream_mail_filter_close(struct iostream_private *stream, bool close_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); } diff --git a/src/plugins/quota/quota-fs.c b/src/plugins/quota/quota-fs.c index b21884a3f2..ce9a46237d 100644 --- a/src/plugins/quota/quota-fs.c +++ b/src/plugins/quota/quota-fs.c @@ -138,10 +138,7 @@ static void fs_quota_mountpoint_free(struct fs_quota_mountpoint *mount) 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 diff --git a/src/plugins/quota/quota-maildir.c b/src/plugins/quota/quota-maildir.c index 37b404f748..a971be0566 100644 --- a/src/plugins/quota/quota-maildir.c +++ b/src/plugins/quota/quota-maildir.c @@ -526,10 +526,7 @@ static int maildirsize_parse(struct maildir_quota_root *root, 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) { diff --git a/src/plugins/replication/replication-plugin.c b/src/plugins/replication/replication-plugin.c index 2cde5408c5..aa61285e52 100644 --- a/src/plugins/replication/replication-plugin.c +++ b/src/plugins/replication/replication-plugin.c @@ -378,11 +378,7 @@ void replication_plugin_init(struct module *module) 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); diff --git a/src/util/tcpwrap.c b/src/util/tcpwrap.c index a0503179c5..5ee291822b 100644 --- a/src/util/tcpwrap.c +++ b/src/util/tcpwrap.c @@ -58,10 +58,7 @@ static void tcpwrap_client_input(struct tcpwrap_client *client) 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); }