changeset 14687:7c058aa05b0a

Replaced (void)close(fd) and close_keep_errno() with i_close_fd(). i_close_fd() preserves the errno and logs an error if the close() fails.
author Timo Sirainen <tss@iki.fi>
date Mon, 25 Jun 2012 02:52:33 +0300
parents 9ff19c1d5f69
children 128c598d2870
files src/auth/db-checkpassword.c src/auth/db-passwd-file.c src/auth/mech-winbind.c src/config/config-parser.c src/config/sysinfo-get.c src/director/director-test.c src/doveadm/doveadm-dump-log.c src/doveadm/doveadm-dump-mailboxlog.c src/doveadm/doveadm-instance.c src/doveadm/doveadm-master.c src/doveadm/doveadm-sis.c src/doveadm/doveadm-stats.c src/doveadm/dsync/doveadm-dsync.c src/doveadm/dsync/dsync-slave-io.c src/imap/main.c src/lda/main.c src/lib-dict/dict-file.c src/lib-dns/dns-lookup.c src/lib-imap-client/imapc-client.c src/lib-index/mail-cache-compress.c src/lib-index/mail-transaction-log.c src/lib-lda/smtp-client.c src/lib-master/master-login.c src/lib-master/master-service-settings.c src/lib-master/mountpoint-list.c src/lib-settings/settings-parser.c src/lib-storage/index/index-attachment.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-lock.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/pop3c/pop3c-client.c src/lib-storage/list/mailbox-list-maildir.c src/lib-storage/mailbox-uidvalidity.c src/lib/Makefile.am src/lib/askpass.c src/lib/close-keep-errno.c src/lib/close-keep-errno.h src/lib/failures.c src/lib/fdatasync-path.c src/lib/file-copy.c src/lib/file-dotlock.c src/lib/ioloop-notify-dn.c src/lib/ioloop-notify-kqueue.c src/lib/iostream-rawlog.c src/lib/istream-seekable.c src/lib/macros.h src/lib/network.c src/lib/nfs-workarounds.c src/lib/randgen.c src/lib/safe-mkstemp.c src/lib/test-ostream-file.c src/lib/unlink-directory.c src/lmtp/commands.c src/login-common/access-lookup.c src/login-common/ssl-proxy-gnutls.c src/master/main.c src/master/service-listen.c src/master/service-monitor.c src/master/service.c src/plugins/acl/acl-backend-vfile-acllist.c src/plugins/acl/acl-backend-vfile.c src/plugins/fts-lucene/fts-backend-lucene.c src/plugins/fts-squat/squat-trie.c src/plugins/fts/doveadm-dump-fts-expunge-log.c src/plugins/fts/fts-expunge-log.c src/plugins/fts/fts-indexer.c src/plugins/fts/fts-parser-script.c src/plugins/quota/quota-maildir.c src/plugins/trash/trash-plugin.c src/plugins/virtual/virtual-config.c src/plugins/zlib/doveadm-zlib.c src/plugins/zlib/zlib-plugin.c src/pop3/main.c src/ssl-params/ssl-params.c src/util/gdbhelper.c src/util/rawlog.c
diffstat 78 files changed, 161 insertions(+), 185 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/db-checkpassword.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/auth/db-checkpassword.c	Mon Jun 25 02:52:33 2012 +0300
@@ -473,8 +473,8 @@
 		auth_request_log_error(request, "checkpassword",
 				       "pipe() failed: %m");
 		if (fd_in[0] != -1) {
-			(void)close(fd_in[0]);
-			(void)close(fd_in[1]);
+			i_close_fd(fd_in[0]);
+			i_close_fd(fd_in[1]);
 		}
 		callback(request, DB_CHECKPASSWORD_STATUS_INTERNAL_FAILURE,
 			 NULL, request_callback);
@@ -485,10 +485,10 @@
 	if (pid == -1) {
 		auth_request_log_error(request, "checkpassword",
 				       "fork() failed: %m");
-		(void)close(fd_in[0]);
-		(void)close(fd_in[1]);
-		(void)close(fd_out[0]);
-		(void)close(fd_out[1]);
+		i_close_fd(fd_in[0]);
+		i_close_fd(fd_in[1]);
+		i_close_fd(fd_out[0]);
+		i_close_fd(fd_out[1]);
 		callback(request, DB_CHECKPASSWORD_STATUS_INTERNAL_FAILURE,
 			 NULL, request_callback);
 		return;
@@ -496,8 +496,8 @@
 
 	if (pid == 0) {
 		/* child */
-		(void)close(fd_in[0]);
-		(void)close(fd_out[1]);
+		i_close_fd(fd_in[0]);
+		i_close_fd(fd_out[1]);
 		checkpassword_exec(db, request, fd_in[1], fd_out[0],
 				   auth_password != NULL);
 		/* not reached */
--- a/src/auth/db-passwd-file.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/auth/db-passwd-file.c	Mon Jun 25 02:52:33 2012 +0300
@@ -184,7 +184,7 @@
 
 	if (fstat(fd, &st) != 0) {
 		i_error("passwd-file %s: fstat() failed: %m", pw->path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return FALSE;
 	}
 
--- a/src/auth/mech-winbind.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/auth/mech-winbind.c	Mon Jun 25 02:52:33 2012 +0300
@@ -111,15 +111,15 @@
 		return;
 	}
 	if (pipe(outfd) < 0) {
-		(void)close(infd[0]); (void)close(infd[1]);
+		i_close_fd(infd[0]); i_close_fd(infd[1]);
 		return;
 	}
 
 	pid = fork();
 	if (pid < 0) {
 		i_error("fork() failed: %m");
-		(void)close(infd[0]); (void)close(infd[1]);
-		(void)close(outfd[0]); (void)close(outfd[1]);
+		i_close_fd(infd[0]); i_close_fd(infd[1]);
+		i_close_fd(outfd[0]); i_close_fd(outfd[1]);
 		return;
 	}
 
@@ -127,8 +127,8 @@
 		/* child */
 		const char *args[3];
 
-		(void)close(infd[0]);
-		(void)close(outfd[1]);
+		i_close_fd(infd[0]);
+		i_close_fd(outfd[1]);
 
 		if (dup2(outfd[0], STDIN_FILENO) < 0 ||
 		    dup2(infd[1], STDOUT_FILENO) < 0)
@@ -141,8 +141,8 @@
 	}
 
 	/* parent */
-	(void)close(infd[1]);
-	(void)close(outfd[0]);
+	i_close_fd(infd[1]);
+	i_close_fd(outfd[0]);
 
 	winbind->pid = pid;
 	winbind->in_pipe =
--- a/src/config/config-parser.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/config/config-parser.c	Mon Jun 25 02:52:33 2012 +0300
@@ -439,7 +439,7 @@
 		*error_r = t_strdup_printf("%s: read(%s) failed: %m",
 					   key, path);
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return ret < 0 ? -1 : 0;
 }
 
--- a/src/config/sysinfo-get.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/config/sysinfo-get.c	Mon Jun 25 02:52:33 2012 +0300
@@ -21,7 +21,7 @@
 	if (fd == -1)
 		return FALSE;
 	ret = read(fd, buf, sizeof(buf));
-	(void)close(fd);
+	i_close_fd(fd);
 	if (ret <= 0)
 		return FALSE;
 
--- a/src/director/director-test.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/director/director-test.c	Mon Jun 25 02:52:33 2012 +0300
@@ -338,7 +338,7 @@
 
 	out_fd = net_connect_ip(local_ip, DIRECTOR_OUT_PORT, NULL);
 	if (out_fd == -1) {
-		(void)close(in_fd);
+		i_close_fd(in_fd);
 		return;
 	}
 
--- a/src/doveadm/doveadm-dump-log.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/doveadm-dump-log.c	Mon Jun 25 02:52:33 2012 +0300
@@ -509,7 +509,7 @@
 	    hdr.major_version == MAIL_TRANSACTION_LOG_MAJOR_VERSION &&
 	    hdr.hdr_size >= MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE)
 		ret = TRUE;
-	(void)close(fd);
+	i_close_fd(fd);
 	return ret;
 }
 
--- a/src/doveadm/doveadm-dump-mailboxlog.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/doveadm-dump-mailboxlog.c	Mon Jun 25 02:52:33 2012 +0300
@@ -100,7 +100,7 @@
 			break;
 		}
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return ret;
 }
 
--- a/src/doveadm/doveadm-instance.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/doveadm-instance.c	Mon Jun 25 02:52:33 2012 +0300
@@ -39,7 +39,7 @@
 				  (kill(pid, 0) < 0 && errno == ESRCH));
 		}
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return found;
 }
 
--- a/src/doveadm/doveadm-master.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/doveadm-master.c	Mon Jun 25 02:52:33 2012 +0300
@@ -41,7 +41,7 @@
 				  (kill(*pid_r, 0) < 0 && errno == ESRCH));
 		}
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return found;
 }
 
--- a/src/doveadm/doveadm-sis.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/doveadm-sis.c	Mon Jun 25 02:52:33 2012 +0300
@@ -48,7 +48,7 @@
 	if (fd1 == -1) {
 		if (errno != ENOENT)
 			i_error("open(%s) failed: %m", path2);
-		(void)close(fd1);
+		i_close_fd(fd1);
 		return -1;
 	}
 
--- a/src/doveadm/doveadm-stats.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/doveadm-stats.c	Mon Jun 25 02:52:33 2012 +0300
@@ -496,7 +496,7 @@
 	array_free(&ctx.lines);
 	pool_unref(&ctx.prev_pool);
 	pool_unref(&ctx.cur_pool);
-	(void)close(ctx.fd);
+	i_close_fd(ctx.fd);
 }
 
 static void cmd_stats_top(int argc, char *argv[])
--- a/src/doveadm/dsync/doveadm-dsync.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/dsync/doveadm-dsync.c	Mon Jun 25 02:52:33 2012 +0300
@@ -79,12 +79,12 @@
 		    dup2(fd_err[1], STDERR_FILENO) < 0)
 			i_fatal("dup2() failed: %m");
 
-		(void)close(fd_in[0]);
-		(void)close(fd_in[1]);
-		(void)close(fd_out[0]);
-		(void)close(fd_out[1]);
-		(void)close(fd_err[0]);
-		(void)close(fd_err[1]);
+		i_close_fd(fd_in[0]);
+		i_close_fd(fd_in[1]);
+		i_close_fd(fd_out[0]);
+		i_close_fd(fd_out[1]);
+		i_close_fd(fd_err[0]);
+		i_close_fd(fd_err[1]);
 
 		execvp_const(args[0], args);
 	default:
@@ -92,9 +92,9 @@
 		break;
 	}
 
-	(void)close(fd_in[0]);
-	(void)close(fd_out[1]);
-	(void)close(fd_err[1]);
+	i_close_fd(fd_in[0]);
+	i_close_fd(fd_out[1]);
+	i_close_fd(fd_err[1]);
 	ctx->fd_in = fd_out[0];
 	ctx->fd_out = fd_in[1];
 	ctx->fd_err = fd_err[0];
@@ -363,7 +363,7 @@
 	if (ctx->io_err != NULL)
 		io_remove(&ctx->io_err);
 	if (ctx->fd_err != -1) {
-		(void)close(ctx->fd_err);
+		i_close_fd(ctx->fd_err);
 		ctx->fd_err = -1;
 	}
 	return ret;
--- a/src/doveadm/dsync/dsync-slave-io.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/doveadm/dsync/dsync-slave-io.c	Mon Jun 25 02:52:33 2012 +0300
@@ -2,7 +2,6 @@
 
 #include "lib.h"
 #include "array.h"
-#include "close-keep-errno.h"
 #include "fd-set-nonblock.h"
 #include "safe-mkstemp.h"
 #include "ioloop.h"
@@ -1366,7 +1365,7 @@
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		close_keep_errno(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 
--- a/src/imap/main.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/imap/main.c	Mon Jun 25 02:52:33 2012 +0300
@@ -277,7 +277,7 @@
 				i_error("write(client) failed: %m");
 		}
 		i_error("%s", error);
-		(void)close(client->fd);
+		i_close_fd(client->fd);
 		master_service_client_connection_destroyed(master_service);
 	}
 }
--- a/src/lda/main.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lda/main.c	Mon Jun 25 02:52:33 2012 +0300
@@ -4,7 +4,6 @@
 #include "lib-signals.h"
 #include "env-util.h"
 #include "fd-set-nonblock.h"
-#include "close-keep-errno.h"
 #include "istream.h"
 #include "istream-seekable.h"
 #include "abspath.h"
@@ -102,7 +101,7 @@
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		close_keep_errno(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 
--- a/src/lib-dict/dict-file.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-dict/dict-file.c	Mon Jun 25 02:52:33 2012 +0300
@@ -494,7 +494,7 @@
 		if (dotlock != NULL)
 			(void)file_dotlock_delete(&dotlock);
 		else {
-			(void)close(fd);
+			i_close_fd(fd);
 			file_unlock(&lock);
 		}
 		return -1;
@@ -522,7 +522,7 @@
 	if (o_stream_nfinish(output) < 0) {
 		i_error("write(%s) failed: %m", temp_path);
 		o_stream_destroy(&output);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	o_stream_destroy(&output);
@@ -530,7 +530,7 @@
 	if (dotlock != NULL) {
 		if (file_dotlock_replace(&dotlock,
 				DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) < 0) {
-			(void)close(fd);
+			i_close_fd(fd);
 			return -1;
 		}
 	} else {
@@ -538,14 +538,14 @@
 			i_error("rename(%s, %s) failed: %m",
 				temp_path, dict->path);
 			file_unlock(&lock);
-			(void)close(fd);
+			i_close_fd(fd);
 			return -1;
 		}
 		file_lock_free(&lock);
 	}
 
 	if (dict->fd != -1)
-		(void)close(dict->fd);
+		i_close_fd(dict->fd);
 	dict->fd = fd;
 	return 0;
 }
--- a/src/lib-dns/dns-lookup.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-dns/dns-lookup.c	Mon Jun 25 02:52:33 2012 +0300
@@ -144,7 +144,7 @@
 	if (write_full(fd, cmd, strlen(cmd)) < 0) {
 		result.error = t_strdup_printf("write(%s) failed: %m",
 					       set->dns_client_socket_path);
-		(void)close(fd);
+		i_close_fd(fd);
 		callback(&result, context);
 		return -1;
 	}
--- a/src/lib-imap-client/imapc-client.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-imap-client/imapc-client.c	Mon Jun 25 02:52:33 2012 +0300
@@ -405,7 +405,7 @@
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	*path_r = str_c(path);
--- a/src/lib-index/mail-cache-compress.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-index/mail-cache-compress.c	Mon Jun 25 02:52:33 2012 +0300
@@ -5,7 +5,6 @@
 #include "ostream.h"
 #include "nfs-workarounds.h"
 #include "read-full.h"
-#include "close-keep-errno.h"
 #include "file-dotlock.h"
 #include "file-cache.h"
 #include "file-set-size.h"
@@ -325,7 +324,7 @@
 		}
 
 		ret = read_full(fd, &hdr, sizeof(hdr));
-		close_keep_errno(fd);
+		i_close_fd(fd);
 
 		if (ret >= 0) {
 			if (ret == 0)
@@ -408,7 +407,7 @@
 				 DOTLOCK_REPLACE_FLAG_DONT_CLOSE_FD) < 0) {
 		mail_cache_set_syscall_error(cache,
 					     "file_dotlock_replace()");
-		(void)close(fd);
+		i_close_fd(fd);
 		array_free(&ext_offsets);
 		return -1;
 	}
--- a/src/lib-index/mail-transaction-log.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-index/mail-transaction-log.c	Mon Jun 25 02:52:33 2012 +0300
@@ -5,7 +5,6 @@
 #include "buffer.h"
 #include "file-dotlock.h"
 #include "nfs-workarounds.h"
-#include "close-keep-errno.h"
 #include "mmap-util.h"
 #include "mail-index-private.h"
 #include "mail-transaction-log-private.h"
--- a/src/lib-lda/smtp-client.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-lda/smtp-client.c	Mon Jun 25 02:52:33 2012 +0300
@@ -4,7 +4,6 @@
 #include "ioloop.h"
 #include "buffer.h"
 #include "str.h"
-#include "close-keep-errno.h"
 #include "safe-mkstemp.h"
 #include "execv-const.h"
 #include "istream.h"
@@ -95,15 +94,15 @@
 
 	if ((pid = fork()) == (pid_t)-1) {
 		i_error("fork() failed: %m");
-		(void)close(fd[0]); (void)close(fd[1]);
+		i_close_fd(fd[0]); i_close_fd(fd[1]);
 		return smtp_client_devnull(output_r);
 	}
 	if (pid == 0) {
 		/* child */
-		(void)close(fd[1]);
+		i_close_fd(fd[1]);
 		smtp_client_run_sendmail(set, destination, return_path, fd[0]);
 	}
-	(void)close(fd[0]);
+	i_close_fd(fd[0]);
 
 	client = i_new(struct smtp_client, 1);
 	client->output = o_stream_create_fd(fd[1], IO_BLOCK_SIZE, TRUE);
@@ -133,7 +132,7 @@
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		close_keep_errno(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 
--- a/src/lib-master/master-login.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-master/master-login.c	Mon Jun 25 02:52:33 2012 +0300
@@ -330,7 +330,7 @@
 			i_error("write(%s) failed: partial write",
 				login->postlogin_socket_path);
 		}
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	net_set_nonblock(fd, TRUE);
--- a/src/lib-master/master-service-settings.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-master/master-service-settings.c	Mon Jun 25 02:52:33 2012 +0300
@@ -347,7 +347,7 @@
 			return -1;
 
 		if (config_send_request(input, fd, path, error_r) < 0) {
-			(void)close(fd);
+			i_close_fd(fd);
 			config_exec_fallback(service, input);
 			return -1;
 		}
@@ -405,7 +405,7 @@
 				*error_r = t_strdup_printf(
 					"Timeout reading config from %s", path);
 			}
-			(void)close(fd);
+			i_close_fd(fd);
 			config_exec_fallback(service, input);
 			return -1;
 		}
@@ -414,7 +414,7 @@
 		    service->config_fd == -1 && input->config_path == NULL)
 			service->config_fd = fd;
 		else
-			(void)close(fd);
+			i_close_fd(fd);
 	}
 
 	if (fd == -1 || service->keep_environment) {
--- a/src/lib-master/mountpoint-list.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-master/mountpoint-list.c	Mon Jun 25 02:52:33 2012 +0300
@@ -203,10 +203,10 @@
 	}
 	if (write_full(fd, str_data(data), str_len(data)) < 0) {
 		i_error("write(%s) failed: %m", str_c(temp_path));
-		(void)close(fd);
+		i_close_fd(fd);
 	} else if (fdatasync(fd) < 0) {
 		i_error("fdatasync(%s) failed: %m", str_c(temp_path));
-		(void)close(fd);
+		i_close_fd(fd);
 	} else if (close(fd) < 0) {
 		i_error("close(%s) failed: %m", str_c(temp_path));
 	} else if (rename(str_c(temp_path), path) < 0) {
--- a/src/lib-settings/settings-parser.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-settings/settings-parser.c	Mon Jun 25 02:52:33 2012 +0300
@@ -1046,8 +1046,8 @@
 	pid = fork();
 	if (pid == (pid_t)-1) {
 		i_error("fork() failed: %m");
-		(void)close(fd[0]);
-		(void)close(fd[1]);
+		i_close_fd(fd[0]);
+		i_close_fd(fd[1]);
 		return -1;
 	}
 	if (pid == 0) {
@@ -1061,13 +1061,13 @@
 		argv[0] = bin_path;
 		argv[2] = config_path;
 		argv[4] = service;
-		(void)close(fd[0]);
+		i_close_fd(fd[0]);
 		if (dup2(fd[1], STDOUT_FILENO) < 0)
 			i_fatal("dup2() failed: %m");
 
 		execv_const(argv[0], argv);
 	}
-	(void)close(fd[1]);
+	i_close_fd(fd[1]);
 
 	input = i_stream_create_fd(fd[0], (size_t)-1, TRUE);
 	ret = settings_parse_stream_read(ctx, input);
--- a/src/lib-storage/index/index-attachment.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/index-attachment.c	Mon Jun 25 02:52:33 2012 +0300
@@ -180,7 +180,7 @@
 	if (unlink(str_c(temp_path)) < 0) {
 		mail_storage_set_critical(storage,
 			"unlink(%s) failed: %m", str_c(temp_path));
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	return fd;
--- a/src/lib-storage/index/maildir/maildir-storage.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Mon Jun 25 02:52:33 2012 +0300
@@ -401,7 +401,7 @@
 				"fchown(%s) failed: %m", path);
 		}
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return 0;
 }
 
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Mon Jun 25 02:52:33 2012 +0300
@@ -31,7 +31,6 @@
 #include "ostream.h"
 #include "str.h"
 #include "file-dotlock.h"
-#include "close-keep-errno.h"
 #include "nfs-workarounds.h"
 #include "eacces-error.h"
 #include "maildir-storage.h"
@@ -741,7 +740,7 @@
 	}
 
 	if (fstat(fd, &st) < 0) {
-                close_keep_errno(fd);
+                i_close_fd(fd);
                 if (errno == ESTALE && try_retry) {
                         *retry_r = TRUE;
                         return -1;
@@ -1469,7 +1468,7 @@
 		maildir_uidlist_update_hdr(uidlist, &st);
 	}
 	if (ret < 0)
-		(void)close(fd);
+		i_close_fd(fd);
 	return ret;
 }
 
--- a/src/lib-storage/index/mbox/mbox-file.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-file.c	Mon Jun 25 02:52:33 2012 +0300
@@ -39,7 +39,7 @@
 
 	if (fstat(fd, &st) < 0) {
 		mbox_set_syscall_error(mbox, "fstat()");
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 
--- a/src/lib-storage/index/mbox/mbox-lock.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-lock.c	Mon Jun 25 02:52:33 2012 +0300
@@ -279,7 +279,7 @@
 		if (chdir(dir) < 0) {
 			mail_storage_set_critical(&mbox->storage->storage,
 				"chdir(%s) failed: %m", dir);
-			(void)close(orig_dir_fd);
+			i_close_fd(orig_dir_fd);
 			return -1;
 		}
 		fname++;
@@ -293,7 +293,7 @@
 	}
 
 	if (restrict_access_use_priv_gid() < 0) {
-		(void)close(orig_dir_fd);
+		i_close_fd(orig_dir_fd);
 		return -1;
 	}
 
@@ -334,7 +334,7 @@
 		mail_storage_set_critical(&mbox->storage->storage,
 			"fchdir() failed: %m");
 	}
-	(void)close(orig_dir_fd);
+	i_close_fd(orig_dir_fd);
 	errno = orig_errno;
 	return ret;
 }
--- a/src/lib-storage/index/mbox/mbox-storage.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Mon Jun 25 02:52:33 2012 +0300
@@ -512,7 +512,7 @@
 		restrict_access_drop_priv_gid();
 	}
 	if (fd != -1) {
-		(void)close(fd);
+		i_close_fd(fd);
 		return 0;
 	} else if (errno == EACCES) {
 		mail_storage_set_critical(box->storage, "%s",
@@ -553,7 +553,7 @@
 					       "Mailbox already exists");
 			return -1;
 		}
-		(void)close(fd);
+		i_close_fd(fd);
 	}
 	return update == NULL ? 0 : mbox_mailbox_update(box, update);
 }
--- a/src/lib-storage/index/pop3c/pop3c-client.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/index/pop3c/pop3c-client.c	Mon Jun 25 02:52:33 2012 +0300
@@ -9,7 +9,6 @@
 #include "ostream.h"
 #include "iostream-rawlog.h"
 #include "iostream-ssl.h"
-#include "close-keep-errno.h"
 #include "safe-mkstemp.h"
 #include "base64.h"
 #include "str.h"
@@ -716,7 +715,7 @@
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		close_keep_errno(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 
--- a/src/lib-storage/list/mailbox-list-maildir.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Mon Jun 25 02:52:33 2012 +0300
@@ -304,7 +304,7 @@
 				"fchown(%s) failed: %m", path);
 		}
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return 0;
 }
 
--- a/src/lib-storage/mailbox-uidvalidity.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib-storage/mailbox-uidvalidity.c	Mon Jun 25 02:52:33 2012 +0300
@@ -168,7 +168,7 @@
 			i_error("creat(%s) failed: %m", tmp);
 			return cur_value;
 		}
-		(void)close(fd);
+		i_close_fd(fd);
 		mailbox_uidvalidity_write(list, path, cur_value);
 		return cur_value;
 	}
@@ -201,14 +201,14 @@
 	ret = read_full(fd, buf, sizeof(buf)-1);
 	if (ret < 0) {
 		i_error("read(%s) failed: %m", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return mailbox_uidvalidity_next_rescan(list, path);
 	}
 	buf[sizeof(buf)-1] = 0;
 	cur_value = strtoul(buf, &endp, 16);
 	if (ret == 0 || endp != buf+sizeof(buf)-1) {
 		/* broken value */
-		(void)close(fd);
+		i_close_fd(fd);
 		return mailbox_uidvalidity_next_rescan(list, path);
 	}
 
--- a/src/lib/Makefile.am	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/Makefile.am	Mon Jun 25 02:52:33 2012 +0300
@@ -20,7 +20,6 @@
 	bsearch-insert-pos.c \
 	buffer.c \
 	child-wait.c \
-	close-keep-errno.c \
 	compat.c \
 	crc32.c \
 	data-stack.c \
@@ -140,7 +139,6 @@
 	bsearch-insert-pos.h \
 	buffer.h \
 	child-wait.h \
-	close-keep-errno.h \
 	compat.h \
 	crc32.h \
 	data-stack.h \
--- a/src/lib/askpass.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/askpass.c	Mon Jun 25 02:52:33 2012 +0300
@@ -50,7 +50,7 @@
 			(void)tcsetattr(fd, TCSAFLUSH, &old_tio);
 
 		fputs("\n", stderr); fflush(stderr);
-		(void)close(fd);
+		i_close_fd(fd);
 	}
 }
 
--- a/src/lib/close-keep-errno.c	Mon Jun 25 02:38:29 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/* Copyright (c) 2006-2012 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "close-keep-errno.h"
-
-#include <unistd.h>
-
-void close_keep_errno(int fd)
-{
-	int old_errno = errno;
-	(void)close(fd);
-	errno = old_errno;
-}
--- a/src/lib/close-keep-errno.h	Mon Jun 25 02:38:29 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-#ifndef CLOSE_KEEP_ERRNO_H
-#define CLOSE_KEEP_ERRNO_H
-
-/* Close the file handle without changing errno. */
-void close_keep_errno(int fd);
-
-#endif
--- a/src/lib/failures.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/failures.c	Mon Jun 25 02:52:33 2012 +0300
@@ -714,17 +714,17 @@
 		log_info_fd = STDERR_FILENO;
 
 	if (log_fd != STDERR_FILENO) {
-		(void)close(log_fd);
+		i_close_fd(log_fd);
 		log_fd = STDERR_FILENO;
 	}
 
 	if (log_info_fd != STDERR_FILENO) {
-		(void)close(log_info_fd);
+		i_close_fd(log_info_fd);
 		log_info_fd = STDERR_FILENO;
 	}
 
 	if (log_debug_fd != STDERR_FILENO) {
-		(void)close(log_debug_fd);
+		i_close_fd(log_debug_fd);
 		log_debug_fd = STDERR_FILENO;
 	}
 
--- a/src/lib/fdatasync-path.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/fdatasync-path.c	Mon Jun 25 02:52:33 2012 +0300
@@ -26,6 +26,6 @@
 			ret = -1;
 		}
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return ret;
 }
--- a/src/lib/file-copy.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/file-copy.c	Mon Jun 25 02:52:33 2012 +0300
@@ -52,7 +52,7 @@
 
 	if (fstat(fd_in, &st) < 0) {
 		i_error("fstat(%s) failed: %m", srcpath);
-		(void)close(fd_in);
+		i_close_fd(fd_in);
 		return -1;
 	}
 
@@ -61,7 +61,7 @@
 	umask(old_umask);
 	if (fd_out == -1) {
 		i_error("open(%s, O_CREAT) failed: %m", tmppath);
-		(void)close(fd_in);
+		i_close_fd(fd_in);
 		return -1;
 	}
 
--- a/src/lib/file-dotlock.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/file-dotlock.c	Mon Jun 25 02:52:33 2012 +0300
@@ -105,7 +105,7 @@
 
 	/* read line */
 	ret = read(fd, buf, sizeof(buf)-1);
-	(void)close(fd);
+	i_close_fd(fd);
 	if (ret <= 0)
 		return -1;
 
@@ -364,7 +364,7 @@
 			if (file_write_pid(lock_info->fd,
 					   str_c(tmp_path),
 					   lock_info->set->nfs_flush) < 0) {
-				(void)close(lock_info->fd);
+				i_close_fd(lock_info->fd);
 				lock_info->fd = -1;
 				return -1;
 			}
@@ -418,7 +418,7 @@
 	if (write_pid) {
 		if (file_write_pid(fd, lock_info->lock_path,
 				   lock_info->set->nfs_flush) < 0) {
-			(void)close(fd);
+			i_close_fd(fd);
 			return -1;
 		}
 	}
--- a/src/lib/ioloop-notify-dn.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/ioloop-notify-dn.c	Mon Jun 25 02:52:33 2012 +0300
@@ -120,7 +120,7 @@
 		if (errno != EINVAL)
 			i_error("fcntl(F_SETSIG) failed: %m");
 		ioloop_dnotify_disable(ctx);
-		(void)close(fd);
+		i_close_fd(fd);
 		return IO_NOTIFY_NOSUPPORT;
 	}
 	if (fcntl(fd, F_NOTIFY, DN_CREATE | DN_DELETE | DN_RENAME |
@@ -135,7 +135,7 @@
 			ioloop_dnotify_disable(ctx);
 		}
 		(void)fcntl(fd, F_SETSIG, 0);
-		(void)close(fd);
+		i_close_fd(fd);
 		return IO_NOTIFY_NOSUPPORT;
 	}
 
--- a/src/lib/ioloop-notify-kqueue.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/ioloop-notify-kqueue.c	Mon Jun 25 02:52:33 2012 +0300
@@ -141,7 +141,7 @@
 		  NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_REVOKE, 0, io);
 	if (kevent(ctx->kq, &ev, 1, NULL, 0, NULL) < 0) {
 		i_error("kevent(%d, %s) for notify failed: %m", fd, path);
-		(void)close(fd);
+		i_close_fd(fd);
 		i_free(io);
 		return IO_NOTIFY_NOSUPPORT;
 	}
--- a/src/lib/iostream-rawlog.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/iostream-rawlog.c	Mon Jun 25 02:52:33 2012 +0300
@@ -101,7 +101,7 @@
 	out_fd = open(out_path, O_CREAT | O_APPEND | O_WRONLY, 0600);
 	if (out_fd == -1) {
 		i_error("creat(%s) failed: %m", out_path);
-		(void)close(in_fd);
+		i_close_fd(in_fd);
 		(void)unlink(in_path);
 		return -1;
 	}
--- a/src/lib/istream-seekable.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/istream-seekable.c	Mon Jun 25 02:52:33 2012 +0300
@@ -2,7 +2,6 @@
 
 #include "lib.h"
 #include "buffer.h"
-#include "close-keep-errno.h"
 #include "read-full.h"
 #include "write-full.h"
 #include "istream-private.h"
@@ -88,7 +87,7 @@
 	if (write_full(fd, sstream->buffer->data, sstream->buffer->used) < 0) {
 		if (!ENOSPACE(errno))
 			i_error("write_full(%s) failed: %m", path);
-		close_keep_errno(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	sstream->temp_path = i_strdup(path);
@@ -210,7 +209,7 @@
 		return -1;
 	}
 	i_stream_destroy(&sstream->fd_input);
-	(void)close(sstream->fd);
+	i_close_fd(sstream->fd);
 	sstream->fd = -1;
 
 	stream->max_buffer_size = (size_t)-1;
--- a/src/lib/macros.h	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/macros.h	Mon Jun 25 02:52:33 2012 +0300
@@ -203,6 +203,14 @@
 
 #endif
 
+#define i_close_fd(fd) STMT_START {  \
+	int old_errno = errno; \
+	if (unlikely(close(fd)) < 0) \
+		i_error("close(%d[%s:%d]) failed: %m", \
+			fd, __FILE__, __LINE__); \
+	errno = old_errno; \
+	} STMT_END
+
 #define i_unreached() \
 	i_panic("file %s: line %d: unreached", __FILE__, __LINE__)
 
--- a/src/lib/network.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/network.c	Mon Jun 25 02:52:33 2012 +0300
@@ -2,7 +2,6 @@
 
 #define _GNU_SOURCE /* For Linux's struct ucred */
 #include "lib.h"
-#include "close-keep-errno.h"
 #include "fd-set-nonblock.h"
 #include "time-util.h"
 #include "network.h"
@@ -210,7 +209,7 @@
 		sin_set_ip(&so, my_ip);
 		if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) {
 			i_error("bind(%s) failed: %m", net_ip2addr(my_ip));
-			close_keep_errno(fd);
+			i_close_fd(fd);
 			return -1;
 		}
 	}
@@ -226,7 +225,7 @@
 	if (ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK)
 #endif
 	{
-                close_keep_errno(fd);
+                i_close_fd(fd);
 		return -1;
 	}
 
@@ -264,10 +263,10 @@
 
 	sin_set_ip(&so, ip);
 	if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) {
-		close_keep_errno(fd);
+		i_close_fd(fd);
 		return -1;
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return 0;
 }
 
@@ -296,7 +295,7 @@
 	/* connect */
 	ret = connect(fd, &sa.sa, sizeof(sa));
 	if (ret < 0 && errno != EINPROGRESS) {
-                close_keep_errno(fd);
+                i_close_fd(fd);
 		return -1;
 	}
 
@@ -428,7 +427,7 @@
 	}
 
         /* error */
-	close_keep_errno(fd);
+	i_close_fd(fd);
 	return -1;
 }
 
@@ -468,7 +467,7 @@
 			i_error("listen() failed: %m");
 	}
 
-	close_keep_errno(fd);
+	i_close_fd(fd);
 	return -1;
 }
 
@@ -484,7 +483,7 @@
 		/* see if it really exists */
 		fd = net_connect_unix(path);
 		if (fd != -1 || errno != ECONNREFUSED) {
-			if (fd != -1) (void)close(fd);
+			if (fd != -1) i_close_fd(fd);
 			errno = EADDRINUSE;
 			return -1;
 		}
--- a/src/lib/nfs-workarounds.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/nfs-workarounds.c	Mon Jun 25 02:52:33 2012 +0300
@@ -259,7 +259,7 @@
 	/* Try to flush the attribute cache the nice way first. */
 	fd = open(path, O_RDONLY);
 	if (fd != -1)
-		(void)close(fd);
+		i_close_fd(fd);
 	else if (errno == ESTALE) {
 		/* this already flushed the cache */
 	} else {
@@ -326,7 +326,7 @@
 		if (t_get_current_dir(&cur_path) < 0) {
 			i_error("nfs_flush_file_handle_cache_dir: "
 				"getcwd() failed");
-			(void)close(cur_dir_fd);
+			i_close_fd(cur_dir_fd);
 			return TRUE;
 		}
 		p = strrchr(cur_path, '/');
@@ -341,7 +341,7 @@
 		ret = nfs_flush_file_handle_cache_dir(path, FALSE);
 		if (fchdir(cur_dir_fd) < 0)
 			i_error("fchdir() failed: %m");
-		(void)close(cur_dir_fd);
+		i_close_fd(cur_dir_fd);
 		return ret;
 	} else {
 		i_error("nfs_flush_file_handle_cache_dir: "
--- a/src/lib/randgen.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/randgen.c	Mon Jun 25 02:52:33 2012 +0300
@@ -63,7 +63,7 @@
 	if (--init_refcount > 0)
 		return;
 
-	(void)close(urandom_fd);
+	i_close_fd(urandom_fd);
 	urandom_fd = -1;
 }
 
--- a/src/lib/safe-mkstemp.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/safe-mkstemp.c	Mon Jun 25 02:52:33 2012 +0300
@@ -63,7 +63,7 @@
 				uid == (uid_t)-1 ? -1L : (long)uid,
 				gid == (gid_t)-1 ? -1L : (long)gid);
 		}
-		(void)close(fd);
+		i_close_fd(fd);
 		(void)unlink(str_c(prefix));
 		return -1;
 	}
--- a/src/lib/test-ostream-file.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/test-ostream-file.c	Mon Jun 25 02:52:33 2012 +0300
@@ -54,7 +54,7 @@
 		test_assert(memcmp(buf, buf2, ret) == 0);
 	}
 	o_stream_unref(&output);
-	(void)close(fd);
+	i_close_fd(fd);
 }
 
 void test_ostream_file(void)
--- a/src/lib/unlink-directory.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lib/unlink-directory.c	Mon Jun 25 02:52:33 2012 +0300
@@ -33,7 +33,6 @@
 #define _GNU_SOURCE /* for O_NOFOLLOW with Linux */
 
 #include "lib.h"
-#include "close-keep-errno.h"
 #include "unlink-directory.h"
 
 #include <fcntl.h>
@@ -73,26 +72,26 @@
 		return -1;
 
 	if (fstat(dir_fd, &st2) < 0) {
-		close_keep_errno(dir_fd);
+		i_close_fd(dir_fd);
 		return -1;
 	}
 
 	if (st.st_ino != st2.st_ino ||
 	    !CMP_DEV_T(st.st_dev, st2.st_dev)) {
 		/* directory was just replaced with something else. */
-		(void)close(dir_fd);
+		i_close_fd(dir_fd);
 		errno = ENOTDIR;
 		return -1;
 	}
 #endif
 	if (fchdir(dir_fd) < 0) {
-                close_keep_errno(dir_fd);
+                i_close_fd(dir_fd);
 		return -1;
 	}
 
 	dirp = opendir(".");
 	if (dirp == NULL) {
-		close_keep_errno(dir_fd);
+		i_close_fd(dir_fd);
 		return -1;
 	}
 
@@ -148,7 +147,7 @@
 	}
 	old_errno = errno;
 
-	(void)close(dir_fd);
+	i_close_fd(dir_fd);
 	if (closedir(dirp) < 0)
 		return -1;
 
@@ -177,7 +176,7 @@
 		i_fatal("unlink_directory(%s): "
 			"Can't fchdir() back to our original dir: %m", dir);
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 
 	if (ret < 0) {
 		errno = old_errno;
--- a/src/lmtp/commands.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/lmtp/commands.c	Mon Jun 25 02:52:33 2012 +0300
@@ -833,7 +833,7 @@
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 
--- a/src/login-common/access-lookup.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/login-common/access-lookup.c	Mon Jun 25 02:52:33 2012 +0300
@@ -82,7 +82,7 @@
 			i_error("fd_send(%s) failed: %m", path);
 		else
 			i_error("fd_send(%s) didn't write enough bytes", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return NULL;
 	}
 
--- a/src/login-common/ssl-proxy-gnutls.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/login-common/ssl-proxy-gnutls.c	Mon Jun 25 02:52:33 2012 +0300
@@ -463,7 +463,7 @@
 	read_dh_parameters(fd, fname);
 	read_rsa_parameters(fd, fname);
 
-	(void)close(fd);
+	i_close_fd(fd);
 }
 
 static void gcrypt_log_handler(void *context ATTR_UNUSED, int level,
--- a/src/master/main.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/master/main.c	Mon Jun 25 02:52:33 2012 +0300
@@ -156,7 +156,7 @@
 			VA_COPY(args2, args);
 			str = t_strdup_vprintf(format, args2);
 			(void)write_full(fd, str, strlen(str));
-			(void)close(fd);
+			i_close_fd(fd);
 		}
 	}
 
@@ -245,7 +245,7 @@
 		found = !(*pid_r == getpid() ||
 			  (kill(*pid_r, 0) < 0 && errno == ESRCH));
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return found;
 }
 
@@ -272,7 +272,7 @@
 		i_fatal("open(%s) failed: %m", path);
 	if (write_full(fd, pid, strlen(pid)) < 0)
 		i_fatal("write() failed in %s: %m", path);
-	(void)close(fd);
+	i_close_fd(fd);
 }
 
 static void create_config_symlink(const struct master_settings *set)
--- a/src/master/service-listen.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/master/service-listen.c	Mon Jun 25 02:52:33 2012 +0300
@@ -86,7 +86,7 @@
 		fd = net_connect_unix(set->path);
 		if (fd != -1 || errno != ECONNREFUSED || i >= 3) {
 			if (fd != -1)
-				(void)close(fd);
+				i_close_fd(fd);
 			service_error(service, "Socket already exists: %s",
 				      set->path);
 			return 0;
@@ -104,7 +104,7 @@
 	i_assert(fd != -1);
 
 	if (service_file_chown(l) < 0) {
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	net_set_nonblock(fd, TRUE);
--- a/src/master/service-monitor.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/master/service-monitor.c	Mon Jun 25 02:52:33 2012 +0300
@@ -398,7 +398,7 @@
 	} T_END;
 
 	if (fd != service->login_notify_fd)
-		(void)close(fd);
+		i_close_fd(fd);
 	return fd == -1 ? -1 : 0;
 }
 
--- a/src/master/service.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/master/service.c	Mon Jun 25 02:52:33 2012 +0300
@@ -690,7 +690,7 @@
 			}
 			while ((fd = net_accept((*listenerp)->fd,
 						NULL, NULL)) >= 0)
-				(void)close(fd);
+				i_close_fd(fd);
 			break;
 		case SERVICE_LISTENER_FIFO:
 			break;
--- a/src/plugins/acl/acl-backend-vfile-acllist.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/acl/acl-backend-vfile-acllist.c	Mon Jun 25 02:52:33 2012 +0300
@@ -109,7 +109,7 @@
 	}
 	if (fstat(fd, &st) < 0) {
 		i_error("fstat(%s) failed: %m", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	backend->acllist_mtime = st.st_mtime;
--- a/src/plugins/acl/acl-backend-vfile.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/acl/acl-backend-vfile.c	Mon Jun 25 02:52:33 2012 +0300
@@ -482,18 +482,18 @@
 
 	if (fstat(fd, &st) < 0) {
 		if (errno == ESTALE && try_retry) {
-			(void)close(fd);
+			i_close_fd(fd);
 			return 0;
 		}
 
 		i_error("fstat(%s) failed: %m", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	if (S_ISDIR(st.st_mode)) {
 		/* we opened a directory. */
 		*is_dir_r = TRUE;
-		(void)close(fd);
+		i_close_fd(fd);
 		return 0;
 	}
 
--- a/src/plugins/fts-lucene/fts-backend-lucene.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/fts-lucene/fts-backend-lucene.c	Mon Jun 25 02:52:33 2012 +0300
@@ -273,7 +273,7 @@
 				str_tabescape(ctx->first_box_vname));
 			fd = fts_indexer_cmd(user, cmd, &path);
 			if (fd != -1)
-				(void)close(fd);
+				i_close_fd(fd);
 		}
 	}
 
--- a/src/plugins/fts-squat/squat-trie.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/fts-squat/squat-trie.c	Mon Jun 25 02:52:33 2012 +0300
@@ -1635,7 +1635,7 @@
 					i_error("file_wait_lock(%s) failed: %m",
 						path);
 				}
-				(void)close(fd);
+				i_close_fd(fd);
 				return -1;
 			}
 		}
--- a/src/plugins/fts/doveadm-dump-fts-expunge-log.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/fts/doveadm-dump-fts-expunge-log.c	Mon Jun 25 02:52:33 2012 +0300
@@ -84,7 +84,7 @@
 		} T_END;
 	} while (ret > 0);
 	buffer_free(&buf);
-	(void)close(fd);
+	i_close_fd(fd);
 }
 
 static bool test_dump_fts_expunge_log(const char *path)
--- a/src/plugins/fts/fts-expunge-log.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/fts/fts-expunge-log.c	Mon Jun 25 02:52:33 2012 +0300
@@ -99,7 +99,7 @@
 	}
 	if (fstat(fd, &log->st) < 0) {
 		i_error("fstat(%s) failed: %m", log->path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	log->fd = fd;
--- a/src/plugins/fts/fts-indexer.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/fts/fts-indexer.c	Mon Jun 25 02:52:33 2012 +0300
@@ -51,7 +51,7 @@
 	cmd = t_strconcat(INDEXER_HANDSHAKE, cmd, NULL);
 	if (write_full(fd, cmd, strlen(cmd)) < 0) {
 		i_error("write(%s) failed: %m", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	*path_r = path;
--- a/src/plugins/fts/fts-parser-script.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/fts/fts-parser-script.c	Mon Jun 25 02:52:33 2012 +0300
@@ -79,7 +79,7 @@
 	cmd = t_strdup_printf(SCRIPT_HANDSHAKE"\n");
 	if (write_full(fd, cmd, strlen(cmd)) < 0) {
 		i_error("write(%s) failed: %m", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	input = i_stream_create_fd(fd, 1024, TRUE);
@@ -205,7 +205,7 @@
 	cmd = t_strdup_printf(SCRIPT_HANDSHAKE"%s\n\n", content_type);
 	if (write_full(fd, cmd, strlen(cmd)) < 0) {
 		i_error("write(%s) failed: %m", path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return NULL;
 	}
 
--- a/src/plugins/quota/quota-maildir.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/quota/quota-maildir.c	Mon Jun 25 02:52:33 2012 +0300
@@ -592,7 +592,7 @@
 
 	if (ret < 0 && size == 0) {
 		/* the read failed and there's no usable header, fail. */
-		(void)close(root->fd);
+		i_close_fd(root->fd);
 		root->fd = -1;
 		return -1;
 	}
@@ -609,7 +609,7 @@
 		ret = 1;
 	else {
 		/* broken file / need recalculation */
-		(void)close(root->fd);
+		i_close_fd(root->fd);
 		root->fd = -1;
 		ret = 0;
 	}
@@ -766,7 +766,7 @@
 	struct maildir_quota_root *root = (struct maildir_quota_root *)_root;
 
 	if (root->fd != -1)
-		(void)close(root->fd);
+		i_close_fd(root->fd);
 	i_free(root);
 }
 
@@ -885,12 +885,12 @@
 	} else if (root->fd == -1)
 		(void)maildirsize_recalculate(root);
 	else if (ctx->recalculate) {
-		(void)close(root->fd);
+		i_close_fd(root->fd);
 		root->fd = -1;
 		(void)maildirsize_recalculate(root);
 	} else if (maildirsize_update(root, ctx->count_used, ctx->bytes_used) < 0) {
 		if (root->fd != -1) {
-			(void)close(root->fd);
+			i_close_fd(root->fd);
 			root->fd = -1;
 		}
 		maildirsize_rebuild_later(root);
--- a/src/plugins/trash/trash-plugin.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/trash/trash-plugin.c	Mon Jun 25 02:52:33 2012 +0300
@@ -311,7 +311,7 @@
 		}
 	}
 	i_stream_destroy(&input);
-	(void)close(fd);
+	i_close_fd(fd);
 
 	array_sort(&tuser->trash_boxes, trash_mailbox_priority_cmp);
 	return ret;
--- a/src/plugins/virtual/virtual-config.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/virtual/virtual-config.c	Mon Jun 25 02:52:33 2012 +0300
@@ -427,7 +427,7 @@
 	if (ret == 0)
 		virtual_config_search_args_dup(mbox);
 	i_stream_unref(&ctx.input);
-	(void)close(fd);
+	i_close_fd(fd);
 	return ret;
 }
 
--- a/src/plugins/zlib/doveadm-zlib.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/zlib/doveadm-zlib.c	Mon Jun 25 02:52:33 2012 +0300
@@ -79,7 +79,7 @@
 		match = strstr(buf, " ok begin compression.") != NULL ||
 			strstr(buf, " compress deflate") != NULL;
 	}
-	(void)close(fd);
+	i_close_fd(fd);
 	return match;
 }
 
--- a/src/plugins/zlib/zlib-plugin.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/plugins/zlib/zlib-plugin.c	Mon Jun 25 02:52:33 2012 +0300
@@ -320,7 +320,7 @@
 			return 0;
 		}
 		if (fstat(fd, &st) == 0 && S_ISDIR(st.st_mode)) {
-			(void)close(fd);
+			i_close_fd(fd);
 			return 0;
 		}
 		input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
--- a/src/pop3/main.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/pop3/main.c	Mon Jun 25 02:52:33 2012 +0300
@@ -172,7 +172,7 @@
 	if (client_create_from_input(&input, client->fd, client->fd,
 				     &input_buf, &error) < 0) {
 		i_error("%s", error);
-		(void)close(client->fd);
+		i_close_fd(client->fd);
 		master_service_client_connection_destroyed(master_service);
 	}
 }
--- a/src/ssl-params/ssl-params.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/ssl-params/ssl-params.c	Mon Jun 25 02:52:33 2012 +0300
@@ -78,14 +78,14 @@
 	}
 	if (st.st_ino != st2.st_ino) {
 		/* nope. so someone else just generated the file. */
-		(void)close(fd);
+		i_close_fd(fd);
 		return;
 	}
 
 	/* check that the parameters file is still the same */
 	if (stat(path, &st) == 0) {
 		if (st.st_mtime != mtime) {
-			(void)close(fd);
+			i_close_fd(fd);
 			return;
 		}
 	} else if (errno != ENOENT)
@@ -165,7 +165,7 @@
 
 	if (fstat(fd, &st) < 0) {
 		i_error("fstat(%s) failed: %m", param->path);
-		(void)close(fd);
+		i_close_fd(fd);
 		return -1;
 	}
 	if (st.st_size == 0 || st.st_size > MAX_PARAM_FILE_SIZE) {
--- a/src/util/gdbhelper.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/util/gdbhelper.c	Mon Jun 25 02:52:33 2012 +0300
@@ -65,7 +65,7 @@
 			}
 			if (ret < 0)
 				i_fatal("read(pipe) failed: %m");
-			(void)close(fd_log);
+			i_close_fd(fd_log);
 		}
 	}
 	return 0;
--- a/src/util/rawlog.c	Mon Jun 25 02:38:29 2012 +0300
+++ b/src/util/rawlog.c	Mon Jun 25 02:52:33 2012 +0300
@@ -130,7 +130,7 @@
 			     data, size) < 0) {
 		/* failed, disable logging */
 		i_error("write(in) failed: %m");
-		(void)close(proxy->fd_in);
+		i_close_fd(proxy->fd_in);
 		proxy->fd_in = -1;
 	}
 }
@@ -142,7 +142,7 @@
 			     data, size) < 0) {
 		/* failed, disable logging */
 		i_error("write(out) failed: %m");
-		(void)close(proxy->fd_out);
+		i_close_fd(proxy->fd_out);
 		proxy->fd_out = -1;
 	}
 }
@@ -247,7 +247,7 @@
 		proxy->fd_out = open(fname, O_CREAT|O_EXCL|O_WRONLY, 0600);
 		if (proxy->fd_out == -1) {
 			i_error("rawlog_open: open() failed for %s: %m", fname);
-			(void)close(proxy->fd_in);
+			i_close_fd(proxy->fd_in);
 			proxy->fd_in = -1;
 			return;
 		}
@@ -336,11 +336,11 @@
 			i_fatal("dup2(sfd, 0)");
 		if (dup2(sfd[1], 1) < 0)
 			i_fatal("dup2(sfd, 1)");
-		(void)close(sfd[0]);
-		(void)close(sfd[1]);
+		i_close_fd(sfd[0]);
+		i_close_fd(sfd[1]);
 		return;
 	}
-	(void)close(sfd[1]);
+	i_close_fd(sfd[1]);
 
 	restrict_access_by_env(getenv("HOME"), TRUE);