changeset 19136:fefaa6d09a81

Replaced unlink() calls with i_unlink*() wherever possible.
author Timo Sirainen <tss@iki.fi>
date Tue, 08 Sep 2015 19:07:02 +0300
parents 2ec2b0a51fec
children 27a629e444b2
files src/auth/auth-token.c src/doveadm/doveadm-sis.c src/doveadm/dsync/dsync-brain.c src/doveadm/dsync/dsync-ibc-stream.c src/lda/main.c src/lib-compression/test-compression.c src/lib-fs/fs-posix.c src/lib-imap-client/imapc-client.c src/lib-imap-urlauth/imap-urlauth-connection.c src/lib-index/mail-cache-compress.c src/lib-index/mail-cache.c src/lib-index/mail-index-strmap.c src/lib-index/mail-index-transaction.c src/lib-index/mail-index.c src/lib-index/mailbox-log.c src/lib-index/test-mail-transaction-log-append.c src/lib-lda/duplicate.c src/lib-lda/smtp-client.c src/lib-mail/test-istream-attachment.c src/lib-master/mountpoint-list.c src/lib-storage/index/dbox-common/dbox-file-fix.c src/lib-storage/index/dbox-common/dbox-storage.c src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c src/lib-storage/index/dbox-single/sdbox-file.c src/lib-storage/index/index-mail-binary.c src/lib-storage/index/maildir/maildir-keywords.c src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib-storage/index/pop3c/pop3c-client.c src/lib-storage/mailbox-uidvalidity.c src/lib/file-copy.c src/lib/file-create-locked.c src/lib/file-dotlock.c src/lib/iostream-rawlog.c src/lib/iostream-temp.c src/lib/istream-seekable.c src/lib/net.c src/lib/safe-mkstemp.c src/lib/test-istream-seekable.c src/lib/test-ostream-file.c src/lib/unlink-old-files.c src/lmtp/commands.c src/login-common/ssl-proxy-gnutls.c src/master/main.c src/master/master-settings.c src/master/service-listen.c src/plugins/acl/acl-backend-vfile-acllist.c src/plugins/fts-squat/squat-test.c src/plugins/fts-squat/squat-trie.c src/plugins/fts-squat/squat-uidlist.c src/plugins/fts/fts-expunge-log.c src/plugins/mail-filter/mail-filter-plugin.c src/plugins/quota/quota-maildir.c src/ssl-params/ssl-params.c
diffstat 54 files changed, 91 insertions(+), 166 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-token.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/auth/auth-token.c	Tue Sep 08 19:07:02 2015 +0300
@@ -57,8 +57,7 @@
 	if (st.st_size != AUTH_TOKEN_SECRET_LEN || !S_ISREG(st.st_mode)) {
 		i_error("Corrupted token secret file: %s", path);
 		i_close_fd(&fd);
-		if (unlink(path) < 0)
-			i_error("unlink(%s) failed: %m", path);
+		i_unlink(path);
 		return -1;
 	}
 
@@ -76,8 +75,7 @@
 	    !CMP_DEV_T(st.st_dev, lst.st_dev)) {
 		i_error("Compromised token secret file: %s", path);
 		i_close_fd(&fd);
-		if (unlink(path) < 0)
-			i_error("unlink(%s) failed: %m", path);
+		i_unlink(path);
 		return -1;
 	}
 
@@ -126,15 +124,13 @@
 	}
 
 	if (ret < 0) {
-		if (unlink(temp_path) < 0)
-			i_error("unlink(%s) failed: %m", temp_path);
+		i_unlink(temp_path);
 		return -1;
 	}
 
 	if (rename(temp_path, path) < 0) {
 		i_error("rename(%s, %s) failed: %m", temp_path, path);
-		if (unlink(temp_path) < 0)
-			i_error("unlink(%s) failed: %m", temp_path);
+		i_unlink(temp_path);
 		return -1;
 	}
 
--- a/src/doveadm/doveadm-sis.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/doveadm/doveadm-sis.c	Tue Sep 08 19:07:02 2015 +0300
@@ -118,14 +118,12 @@
 		return -1;
 	}
 	if (st.st_ino != src_inode) {
-		if (unlink(tmppath) < 0)
-			i_error("unlink(%s) failed: %m", tmppath);
+		i_unlink(tmppath);
 		return 0;
 	}
 	if (rename(tmppath, dest) < 0) {
 		i_error("rename(%s, %s) failed: %m", src, tmppath);
-		if (unlink(tmppath) < 0)
-			i_error("unlink(%s) failed: %m", tmppath);
+		i_unlink(tmppath);
 		return -1;
 	}
 	return 1;
@@ -258,10 +256,8 @@
 		T_BEGIN {
 			ret = sis_try_deduplicate(rootdir, d->d_name);
 		} T_END;
-		if (ret == 0) {
-			if (unlink(str_c(path)) < 0)
-				i_error("unlink(%s) failed: %m", str_c(path));
-		}
+		if (ret == 0)
+			i_unlink(str_c(path));
 	}
 	if (closedir(dir) < 0)
 		i_error("closedir(%s) failed: %m", queuedir);
--- a/src/doveadm/dsync/dsync-brain.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/doveadm/dsync/dsync-brain.c	Tue Sep 08 19:07:02 2015 +0300
@@ -332,8 +332,7 @@
 
 	if (brain->lock_fd != -1) {
 		/* unlink the lock file before it gets unlocked */
-		if (unlink(brain->lock_path) < 0)
-			i_error("unlink(%s) failed: %m", brain->lock_path);
+		i_unlink(brain->lock_path);
 		file_lock_free(&brain->lock);
 		i_close_fd(&brain->lock_fd);
 	}
--- a/src/doveadm/dsync/dsync-ibc-stream.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/doveadm/dsync/dsync-ibc-stream.c	Tue Sep 08 19:07:02 2015 +0300
@@ -467,9 +467,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lda/main.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lda/main.c	Tue Sep 08 19:07:02 2015 +0300
@@ -98,9 +98,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib-compression/test-compression.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-compression/test-compression.c	Tue Sep 08 19:07:02 2015 +0300
@@ -80,8 +80,7 @@
 	sha1_result(&sha1, input_sha1);
 
 	test_assert(memcmp(input_sha1, output_sha1, sizeof(input_sha1)) == 0);
-	if (unlink(path) < 0)
-		i_error("unlink(%s) failed: %m", path);
+	i_unlink(path);
 
 	test_end();
 }
--- a/src/lib-fs/fs-posix.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-fs/fs-posix.c	Tue Sep 08 19:07:02 2015 +0300
@@ -630,8 +630,7 @@
 	ret = link(src->full_path, dest->full_path);
 	if (errno == EEXIST && dest->open_mode == FS_OPEN_MODE_REPLACE) {
 		/* destination file already exists - replace it */
-		if (unlink(dest->full_path) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", dest->full_path);
+		i_unlink_if_exists(dest->full_path);
 		ret = link(src->full_path, dest->full_path);
 	}
 	while (ret < 0 && errno == ENOENT &&
--- a/src/lib-imap-client/imapc-client.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-imap-client/imapc-client.c	Tue Sep 08 19:07:02 2015 +0300
@@ -460,9 +460,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib-imap-urlauth/imap-urlauth-connection.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-connection.c	Tue Sep 08 19:07:02 2015 +0300
@@ -493,9 +493,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib-index/mail-cache-compress.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/mail-cache-compress.c	Tue Sep 08 19:07:02 2015 +0300
@@ -458,8 +458,7 @@
 		return -1;
 	if (mail_cache_compress_write(cache, trans, fd, temp_path, unlock) < 0) {
 		i_close_fd(&fd);
-		if (unlink(temp_path) < 0)
-			i_error("unlink(%s) failed: %m", temp_path);
+		i_unlink(temp_path);
 		return -1;
 	}
 	if (cache->file_cache != NULL)
--- a/src/lib-index/mail-cache.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/mail-cache.c	Tue Sep 08 19:07:02 2015 +0300
@@ -25,7 +25,7 @@
 static void mail_cache_unlink(struct mail_cache *cache)
 {
 	if (!cache->index->readonly)
-		(void)unlink(cache->filepath);
+		i_unlink(cache->filepath);
 }
 
 void mail_cache_reset(struct mail_cache *cache)
--- a/src/lib-index/mail-index-strmap.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/mail-index-strmap.c	Tue Sep 08 19:07:02 2015 +0300
@@ -243,7 +243,7 @@
 	mail_index_set_error(view->strmap->index,
 			     "Corrupted strmap index file: %s",
 			     view->strmap->path);
-	(void)unlink(view->strmap->path);
+	i_unlink(view->strmap->path);
 	mail_index_strmap_close(view->strmap);
 	mail_index_strmap_view_reset(view);
 }
@@ -285,7 +285,7 @@
 	    hdr.uid_validity != idx_hdr->uid_validity) {
 		/* need to rebuild. if we already had something in the strmap,
 		   we can keep it. */
-		(void)unlink(strmap->path);
+		i_unlink(strmap->path);
 		mail_index_strmap_close(strmap);
 		return 0;
 	}
@@ -1034,7 +1034,7 @@
 		ret = -1;
 	}
 	if (ret < 0)
-		(void)unlink(temp_path);
+		i_unlink(temp_path);
 	return ret;
 }
 
--- a/src/lib-index/mail-index-transaction.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/mail-index-transaction.c	Tue Sep 08 19:07:02 2015 +0300
@@ -176,8 +176,7 @@
 	if (t->reset) {
 		/* get rid of the old index. it might just confuse readers,
 		   especially if it's broken. */
-		if (unlink(log->index->filepath) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", log->index->filepath);
+		i_unlink_if_exists(log->index->filepath);
 	}
 
 	*commit_size_r = log_offset2 - log_offset1;
--- a/src/lib-index/mail-index.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/mail-index.c	Tue Sep 08 19:07:02 2015 +0300
@@ -468,10 +468,8 @@
 	if (fd == -1 && errno == EEXIST) {
 		/* stale temp file. unlink and recreate rather than overwriting,
 		   just to make sure locking problems won't cause corruption */
-		if (unlink(path) < 0) {
-			i_error("unlink(%s) failed: %m", path);
+		if (i_unlink(path) < 0)
 			return -1;
-		}
 		old_mask = umask(0);
 		fd = open(path, O_RDWR|O_CREAT|O_EXCL, index->mode);
 		umask(old_mask);
--- a/src/lib-index/mailbox-log.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/mailbox-log.c	Tue Sep 08 19:07:02 2015 +0300
@@ -276,8 +276,7 @@
 			(iter->count - iter->idx) * sizeof(iter->buf[0]);
 		i_error("Corrupted mailbox log %s at offset %"PRIuUOFF_T": "
 			"type=%d", iter->filepath, offset, rec->type);
-		if (unlink(iter->filepath) < 0)
-			i_error("unlink(%s) failed: %m", iter->filepath);
+		i_unlink(iter->filepath);
 		return NULL;
 	}
 	return rec;
--- a/src/lib-index/test-mail-transaction-log-append.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-index/test-mail-transaction-log-append.c	Tue Sep 08 19:07:02 2015 +0300
@@ -162,7 +162,7 @@
 	i_free(log->head);
 	i_free(log->index);
 	i_free(log);
-	unlink(tmp_path);
+	i_unlink(tmp_path);
 }
 
 int main(void)
--- a/src/lib-lda/duplicate.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-lda/duplicate.c	Tue Sep 08 19:07:02 2015 +0300
@@ -184,10 +184,8 @@
 	}
 
 	if (record_size == 0 ||
-	    duplicate_read_records(file, input, record_size) < 0) {
-		if (unlink(file->path) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", file->path);
-	}
+	    duplicate_read_records(file, input, record_size) < 0)
+		i_unlink_if_exists(file->path);
 
 	i_stream_unref(&input);
 	if (close(fd) < 0)
--- a/src/lib-lda/smtp-client.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-lda/smtp-client.c	Tue Sep 08 19:07:02 2015 +0300
@@ -87,9 +87,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib-mail/test-istream-attachment.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-mail/test-istream-attachment.c	Tue Sep 08 19:07:02 2015 +0300
@@ -132,7 +132,7 @@
 	fd = safe_mkstemp(str, 0600, (uid_t)-1, (gid_t)-1);
 	if (fd == -1)
 		i_fatal("safe_mkstemp(%s) failed: %m", str_c(str));
-	(void)unlink(str_c(str));
+	i_unlink(str_c(str));
 	return fd;
 }
 
--- a/src/lib-master/mountpoint-list.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-master/mountpoint-list.c	Tue Sep 08 19:07:02 2015 +0300
@@ -223,7 +223,7 @@
 	} else {
 		return 0;
 	}
-	(void)unlink(str_c(temp_path));
+	i_unlink(str_c(temp_path));
 	return -1;
 }
 
--- a/src/lib-storage/index/dbox-common/dbox-file-fix.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-file-fix.c	Tue Sep 08 19:07:02 2015 +0300
@@ -498,10 +498,8 @@
 	if (!have_messages) {
 		/* the resulting file has no messages. just delete the file. */
 		dbox_file_close(file);
-		if (unlink(temp_path) < 0)
-			i_error("unlink(%s) failed: %m", temp_path);
-		if (unlink(file->cur_path) < 0)
-			i_error("unlink(%s) failed: %m", file->cur_path);
+		i_unlink(temp_path);
+		i_unlink(file->cur_path);
 		return 0;
 	}
 	if (rename(temp_path, file->cur_path) < 0) {
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Tue Sep 08 19:07:02 2015 +0300
@@ -77,8 +77,7 @@
 		return;
 
 	/* unlink/create the current alt path symlink */
-	if (unlink(alt_symlink_path) < 0 && errno != ENOENT)
-		i_error("unlink(%s) failed: %m", alt_symlink_path);
+	i_unlink_if_exists(alt_symlink_path);
 	if (alt_path != NULL) {
 		if (symlink(alt_path, alt_symlink_path) < 0 &&
 		    errno != EEXIST) {
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Tue Sep 08 19:07:02 2015 +0300
@@ -249,8 +249,7 @@
 		/* use link()+unlink() instead of rename() to make sure we
 		   don't overwrite any files. */
 		if (link(old_path, new_path) == 0) {
-			if (unlink(old_path) < 0)
-				i_error("unlink(%s) failed: %m", old_path);
+			i_unlink(old_path);
 			*fname_p = strrchr(new_path, '/') + 1;
 			*file_id_r = ctx->highest_file_id;
 			return 0;
--- a/src/lib-storage/index/dbox-single/sdbox-file.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/dbox-single/sdbox-file.c	Tue Sep 08 19:07:02 2015 +0300
@@ -352,7 +352,7 @@
 		ret = -1;
 	}
 	if (ret < 0) {
-		(void)unlink(temp_path);
+		i_unlink(temp_path);
 		return -1;
 	}
 	/* preserve the original atime/mtime. this isn't necessary for Dovecot,
@@ -370,14 +370,14 @@
 	if (rename(temp_path, dest_path) < 0) {
 		mail_storage_set_critical(storage,
 			"rename(%s, %s) failed: %m", temp_path, dest_path);
-		(void)unlink(temp_path);
+		i_unlink_if_exists(temp_path);
 		return -1;
 	}
 	if (storage->set->parsed_fsync_mode != FSYNC_MODE_NEVER) {
 		if (fdatasync_path(dest_dir) < 0) {
 			mail_storage_set_critical(storage,
 				"fdatasync(%s) failed: %m", dest_dir);
-			(void)unlink(dest_path);
+			i_unlink(dest_path);
 			return -1;
 		}
 	}
@@ -385,7 +385,7 @@
 		dbox_file_set_syscall_error(file, "unlink()");
 		if (errno == EACCES) {
 			/* configuration problem? revert the write */
-			(void)unlink(dest_path);
+			i_unlink(dest_path);
 		}
 		/* who knows what happened to the file. keep both just to be
 		   sure both won't get deleted. */
--- a/src/lib-storage/index/index-mail-binary.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/index-mail-binary.c	Tue Sep 08 19:07:02 2015 +0300
@@ -220,9 +220,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib-storage/index/maildir/maildir-keywords.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/maildir/maildir-keywords.c	Tue Sep 08 19:07:02 2015 +0300
@@ -365,7 +365,7 @@
 		return 0;
 
 	lock_path = t_strconcat(mk->path, ".lock", NULL);
-	(void)unlink(lock_path);
+	i_unlink_if_exists(lock_path);
 
 	perm = mailbox_get_permissions(&mk->mbox->box);
 	for (i = 0;; i++) {
--- a/src/lib-storage/index/maildir/maildir-save.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Tue Sep 08 19:07:02 2015 +0300
@@ -671,7 +671,7 @@
 	struct maildir_filename *mf;
 
 	for (mf = ctx->files; mf != NULL; mf = mf->next) T_BEGIN {
-		(void)unlink(maildir_mf_get_path(ctx, mf));
+		i_unlink(maildir_mf_get_path(ctx, mf));
 	} T_END;
 	ctx->files = NULL;
 }
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Tue Sep 08 19:07:02 2015 +0300
@@ -817,7 +817,7 @@
 
         if (ret == 0) {
                 /* file is broken */
-                (void)unlink(uidlist->path);
+                i_unlink(uidlist->path);
         } else if (ret > 0) {
                 /* success */
 		if (readonly)
--- a/src/lib-storage/index/pop3c/pop3c-client.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/index/pop3c/pop3c-client.c	Tue Sep 08 19:07:02 2015 +0300
@@ -753,9 +753,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib-storage/mailbox-uidvalidity.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib-storage/mailbox-uidvalidity.c	Tue Sep 08 19:07:02 2015 +0300
@@ -181,8 +181,7 @@
 	if (min_value != max_value) {
 		/* duplicate uidvalidity files, delete the oldest */
 		tmp = t_strdup_printf("%s.%08x", path, min_value);
-		if (unlink(tmp) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", tmp);
+		i_unlink_if_exists(tmp);
 	}
 
 	cur_value = max_value;
--- a/src/lib/file-copy.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/file-copy.c	Tue Sep 08 19:07:02 2015 +0300
@@ -25,10 +25,8 @@
 		if (link(srcpath, tmppath) == 0)
 			return 1;
 		if (errno == EEXIST) {
-			if (unlink(tmppath) < 0 && errno != ENOENT) {
-				i_error("unlink(%s) failed: %m", tmppath);
+			if (i_unlink_if_exists(tmppath) < 0)
 				return -1;
-			}
 			if (link(srcpath, tmppath) == 0)
 				return 1;
 		}
@@ -109,7 +107,7 @@
 			}
 		}
 		if (ret < 0)
-			(void)unlink(tmppath);
+			i_unlink(tmppath);
 	} T_END;
 	return ret;
 }
--- a/src/lib/file-create-locked.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/file-create-locked.c	Tue Sep 08 19:07:02 2015 +0300
@@ -77,15 +77,13 @@
 						   str_c(temp_path), path);
 		}
 	} else {
-		if (unlink(str_c(temp_path)) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", str_c(temp_path));
+		i_unlink_if_exists(str_c(temp_path));
 		*fd_r = fd;
 		return 1;
 	}
 	orig_errno = errno;
 	i_close_fd(&fd);
-	if (unlink(str_c(temp_path)) < 0 && errno != ENOENT)
-		i_error("unlink(%s) failed: %m", str_c(temp_path));
+	i_unlink_if_exists(str_c(temp_path));
 	errno = orig_errno;
 	return ret;
 }
--- a/src/lib/file-dotlock.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/file-dotlock.c	Tue Sep 08 19:07:02 2015 +0300
@@ -191,11 +191,8 @@
 
 static int dotlock_override(struct lock_info *lock_info)
 {
-	if (unlink(lock_info->lock_path) < 0 && errno != ENOENT) {
-		i_error("unlink(%s) failed: %m",
-			lock_info->lock_path);
+	if (i_unlink_if_exists(lock_info->lock_path) < 0)
 		return -1;
-	}
 
 	/* make sure we sleep for a while after overriding the lock file.
 	   otherwise another process might try to override it at the same time
@@ -391,8 +388,7 @@
 		return -1;
 	}
 
-	if (unlink(lock_info->temp_path) < 0) {
-		i_error("unlink(%s) failed: %m", lock_info->temp_path);
+	if (i_unlink(lock_info->temp_path) < 0) {
 		/* non-fatal, continue */
 	}
 	lock_info->temp_path = NULL;
@@ -596,10 +592,8 @@
 			i_error("close(%s) failed: %m", lock_path);
 		errno = old_errno;
 	}
-	if (lock_info.temp_path != NULL) {
-		if (unlink(lock_info.temp_path) < 0)
-			i_error("unlink(%s) failed: %m", lock_info.temp_path);
-	}
+	if (lock_info.temp_path != NULL)
+		i_unlink(lock_info.temp_path);
 
 	if (ret == 0)
 		errno = EAGAIN;
@@ -724,6 +718,7 @@
 	struct dotlock *dotlock;
 	const char *lock_path;
         struct stat st;
+	int ret;
 
 	dotlock = *dotlock_p;
 	*dotlock_p = NULL;
@@ -758,20 +753,10 @@
 			  (int)(time(NULL) - dotlock->lock_time));
 	}
 
-	if (unlink(lock_path) < 0) {
-		if (errno == ENOENT) {
-			dotlock_replaced_warning(dotlock, TRUE);
-			file_dotlock_free(&dotlock);
-			return 0;
-		}
-
-		i_error("unlink(%s) failed: %m", lock_path);
-		file_dotlock_free(&dotlock);
-		return -1;
-	}
-
+	if ((ret = i_unlink_if_exists(lock_path)) == 0)
+		dotlock_replaced_warning(dotlock, TRUE);
 	file_dotlock_free(&dotlock);
-	return 1;
+	return ret;
 }
 
 int file_dotlock_open(const struct dotlock_settings *set, const char *path,
--- a/src/lib/iostream-rawlog.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/iostream-rawlog.c	Tue Sep 08 19:07:02 2015 +0300
@@ -242,7 +242,7 @@
 	if (out_fd == -1) {
 		i_error("creat(%s) failed: %m", out_path);
 		i_close_fd(&in_fd);
-		(void)unlink(in_path);
+		i_unlink(in_path);
 		return -1;
 	}
 
--- a/src/lib/iostream-temp.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/iostream-temp.c	Tue Sep 08 19:07:02 2015 +0300
@@ -58,8 +58,7 @@
 		i_error("safe_mkstemp(%s) failed: %m", str_c(path));
 		return -1;
 	}
-	if (unlink(str_c(path)) < 0) {
-		i_error("unlink(%s) failed: %m", str_c(path));
+	if (i_unlink(str_c(path)) < 0) {
 		i_close_fd(&tstream->fd);
 		return -1;
 	}
--- a/src/lib/istream-seekable.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/istream-seekable.c	Tue Sep 08 19:07:02 2015 +0300
@@ -460,9 +460,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("istream-seekable: unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/lib/net.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/net.c	Tue Sep 08 19:07:02 2015 +0300
@@ -542,8 +542,7 @@
 		}
 
 		/* delete and try again */
-		if (unlink(path) < 0 && errno != ENOENT) {
-			i_error("unlink(%s) failed: %m", path);
+		if (i_unlink_if_exists(path) < 0) {
 			errno = EADDRINUSE;
 			return -1;
 		}
--- a/src/lib/safe-mkstemp.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/safe-mkstemp.c	Tue Sep 08 19:07:02 2015 +0300
@@ -64,7 +64,7 @@
 				gid == (gid_t)-1 ? -1L : (long)gid);
 		}
 		i_close_fd(&fd);
-		(void)unlink(str_c(prefix));
+		i_unlink(str_c(prefix));
 		return -1;
 	}
 	return fd;
--- a/src/lib/test-istream-seekable.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/test-istream-seekable.c	Tue Sep 08 19:07:02 2015 +0300
@@ -17,7 +17,7 @@
 	if (fd == -1)
 		i_error("creat(%s) failed: %m", *path_r);
 	else
-		unlink(*path_r);
+		i_unlink(*path_r);
 	return fd;
 }
 
--- a/src/lib/test-ostream-file.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/test-ostream-file.c	Tue Sep 08 19:07:02 2015 +0300
@@ -24,8 +24,7 @@
 	fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1);
 	if (fd == -1)
 		i_fatal("safe_mkstemp(%s) failed: %m", str_c(path));
-	if (unlink(str_c(path)) < 0)
-		i_fatal("unlink(%s) failed: %m", str_c(path));
+	i_unlink(str_c(path));
 	output = o_stream_create_fd(fd, MAX_BUFSIZE, FALSE);
 	o_stream_cork(output);
 
--- a/src/lib/unlink-old-files.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lib/unlink-old-files.c	Tue Sep 08 19:07:02 2015 +0300
@@ -54,8 +54,7 @@
 			if (errno != ENOENT)
 				i_error("stat(%s) failed: %m", str_c(path));
 		} else if (!S_ISDIR(st.st_mode) && st.st_ctime < min_time) {
-			if (unlink(str_c(path)) < 0 && errno != ENOENT)
-				i_error("unlink(%s) failed: %m", str_c(path));
+			i_unlink_if_exists(str_c(path));
 		}
 	}
 
--- a/src/lmtp/commands.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/lmtp/commands.c	Tue Sep 08 19:07:02 2015 +0300
@@ -1168,9 +1168,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/login-common/ssl-proxy-gnutls.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/login-common/ssl-proxy-gnutls.c	Tue Sep 08 19:07:02 2015 +0300
@@ -357,13 +357,13 @@
 		i_fatal("read() failed for %s: %m", fname);
 
 	if (ret != sizeof(datum->size)) {
-		(void)unlink(fname);
+		i_unlink(fname);
 		i_fatal("Corrupted SSL parameter file %s: File too small",
 			fname);
 	}
 
 	if (datum->size > 10240) {
-		(void)unlink(fname);
+		i_unlink(fname);
 		i_fatal("Corrupted SSL parameter file %s: "
 			"Field '%s' too large (%u)",
 			fname, field_name, datum->size);
@@ -376,7 +376,7 @@
 		i_fatal("read() failed for %s: %m", fname);
 
 	if ((size_t)ret != datum->size) {
-		(void)unlink(fname);
+		i_unlink(fname);
 		i_fatal("Corrupted SSL parameter file %s: "
 			"Field '%s' not fully in file (%u < %u)",
 			fname, field_name, datum->size - ret, datum->size);
@@ -398,7 +398,7 @@
 		read_next_field(fd, &dbits, fname, "DH bits");
 
 		if (dbits.size != sizeof(int)) {
-			(void)unlink(fname);
+			i_unlink(fname);
 			i_fatal("Corrupted SSL parameter file %s: "
 				"Field 'DH bits' has invalid size %u",
 				fname, dbits.size);
--- a/src/master/main.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/master/main.c	Tue Sep 08 19:07:02 2015 +0300
@@ -217,8 +217,7 @@
 	}
 
 	i_close_fd(&fd);
-	if (unlink(path) < 0)
-		i_error("unlink(%s) failed: %m", path);
+	i_unlink(path);
 }
 
 static bool pid_file_read(const char *path, pid_t *pid_r)
@@ -291,8 +290,7 @@
 	const char *base_config_path;
 
 	base_config_path = t_strconcat(set->base_dir, "/"PACKAGE".conf", NULL);
-	if (unlink(base_config_path) < 0 && errno != ENOENT)
-		i_error("unlink(%s) failed: %m", base_config_path);
+	i_unlink_if_exists(base_config_path);
 
 	if (symlink(services->config->config_file_path, base_config_path) < 0) {
 		i_error("symlink(%s, %s) failed: %m",
@@ -553,8 +551,7 @@
 	global_dead_pipe_close();
 	services_destroy(services, TRUE);
 
-	if (unlink(pidfile_path) < 0)
-		i_error("unlink(%s) failed: %m", pidfile_path);
+	i_unlink(pidfile_path);
 	i_free(pidfile_path);
 
 	service_anvil_global_deinit();
--- a/src/master/master-settings.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/master/master-settings.c	Tue Sep 08 19:07:02 2015 +0300
@@ -711,8 +711,7 @@
 			}
 		}
 
-		if (unlink(str_c(str)) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", str_c(str));
+		i_unlink_if_exists(str_c(str));
 	}
 	(void)closedir(dirp);
 }
--- a/src/master/service-listen.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/master/service-listen.c	Tue Sep 08 19:07:02 2015 +0300
@@ -446,10 +446,7 @@
 		switch (old_listeners[j]->type) {
 		case SERVICE_LISTENER_UNIX:
 		case SERVICE_LISTENER_FIFO: {
-			const char *path =
-				old_listeners[j]->set.fileset.set->path;
-			if (unlink(path) < 0)
-				i_error("unlink(%s) failed: %m", path);
+			i_unlink(old_listeners[j]->set.fileset.set->path);
 			break;
 		}
 		case SERVICE_LISTENER_INET:
--- a/src/plugins/acl/acl-backend-vfile-acllist.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/acl/acl-backend-vfile-acllist.c	Tue Sep 08 19:07:02 2015 +0300
@@ -137,8 +137,7 @@
 
 		if (p == line || *p != ' ' || p[1] == '\0') {
 			i_error("Broken acllist file: %s", path);
-			if (unlink(path) < 0 && errno != ENOENT)
-				i_error("unlink(%s) failed: %m", path);
+			i_unlink_if_exists(path);
 			i_close_fd(&fd);
 			return -1;
 		}
@@ -316,8 +315,7 @@
 		(void)acl_lookup_dict_rebuild(auser->acl_lookup_dict);
 	} else {
 		acllist_clear(backend, 0);
-		if (unlink(str_c(path)) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", str_c(path));
+		i_unlink_if_exists(str_c(path));
 	}
 	backend->rebuilding_acllist = FALSE;
 	return ret;
@@ -333,8 +331,7 @@
 		/* delete it to make sure it gets rebuilt later */
 		if (!acl_list_get_path(backend, &acllist_path))
 			i_unreached();
-		if (unlink(acllist_path) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", acllist_path);
+		i_unlink_if_exists(acllist_path);
 		return -1;
 	}
 }
--- a/src/plugins/fts-squat/squat-test.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/fts-squat/squat-test.c	Tue Sep 08 19:07:02 2015 +0300
@@ -53,8 +53,8 @@
 	double cputime;
 
 	lib_init();
-	(void)unlink(trie_path);
-	(void)unlink(uidlist_path);
+	i_unlink_if_exists(trie_path);
+	i_unlink_if_exists(uidlist_path);
 	trie = squat_trie_init(trie_path, time(NULL),
 			       FILE_LOCK_METHOD_FCNTL, FALSE, 0600, (gid_t)-1);
 
--- a/src/plugins/fts-squat/squat-trie.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/fts-squat/squat-trie.c	Tue Sep 08 19:07:02 2015 +0300
@@ -60,8 +60,7 @@
 
 void squat_trie_delete(struct squat_trie *trie)
 {
-	if (unlink(trie->path) < 0 && errno != ENOENT)
-		i_error("unlink(%s) failed: %m", trie->path);
+	i_unlink_if_exists(trie->path);
 	squat_uidlist_delete(trie->uidlist);
 }
 
@@ -1704,8 +1703,7 @@
 	}
 
 	if (ret < 0) {
-		if (unlink(path) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", path);
+		i_unlink_if_exists(path);
 		if (file_lock != NULL)
 			file_lock_free(&file_lock);
 	} else {
--- a/src/plugins/fts-squat/squat-uidlist.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/fts-squat/squat-uidlist.c	Tue Sep 08 19:07:02 2015 +0300
@@ -92,8 +92,7 @@
 
 void squat_uidlist_delete(struct squat_uidlist *uidlist)
 {
-	if (unlink(uidlist->path) < 0 && errno != ENOENT)
-		i_error("unlink(%s) failed: %m", uidlist->path);
+	i_unlink_if_exists(uidlist->path);
 }
 
 static void squat_uidlist_set_corrupted(struct squat_uidlist *uidlist,
@@ -1084,10 +1083,8 @@
 	if (close(ctx->fd) < 0)
 		i_error("close(%s) failed: %m", temp_path);
 
-	if (ret <= 0) {
-		if (unlink(temp_path) < 0)
-			i_error("unlink(%s) failed: %m", temp_path);
-	}
+	if (ret <= 0)
+		i_unlink(temp_path);
 	array_free(&ctx->new_block_offsets);
 	array_free(&ctx->new_block_end_indexes);
 	i_free(ctx);
--- a/src/plugins/fts/fts-expunge-log.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/fts/fts-expunge-log.c	Tue Sep 08 19:07:02 2015 +0300
@@ -442,9 +442,8 @@
 	(void)i_stream_read_data(ctx->input, &data, &size, IO_BLOCK_SIZE);
 	if (size == 0 && ctx->input->stream_errno == 0) {
 		/* expected EOF - mark the file as read by unlinking it */
-		if (ctx->unlink &&
-		    unlink(ctx->log->path) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", ctx->log->path);
+		if (ctx->unlink)
+			i_unlink_if_exists(ctx->log->path);
 
 		/* try reading again, in case something new was written */
 		i_stream_sync(ctx->input);
@@ -510,9 +509,8 @@
 	*_ctx = NULL;
 
 	if (ctx->corrupted) {
-		if (ctx->unlink &&
-		    unlink(ctx->log->path) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", ctx->log->path);
+		if (ctx->unlink)
+			i_unlink_if_exists(ctx->log->path);
 	}
 
 	if (ctx->input != NULL)
--- a/src/plugins/mail-filter/mail-filter-plugin.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/mail-filter/mail-filter-plugin.c	Tue Sep 08 19:07:02 2015 +0300
@@ -74,9 +74,8 @@
 	}
 
 	/* we just want the fd, unlink it */
-	if (unlink(str_c(path)) < 0) {
+	if (i_unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
-		i_error("unlink(%s) failed: %m", str_c(path));
 		i_close_fd(&fd);
 		return -1;
 	}
--- a/src/plugins/quota/quota-maildir.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/plugins/quota/quota-maildir.c	Tue Sep 08 19:07:02 2015 +0300
@@ -304,16 +304,14 @@
 	if (write_full(fd, str_data(str), str_len(str)) < 0) {
 		i_error("write_full(%s) failed: %m", str_c(temp_path));
 		i_close_fd(&fd);
-		if (unlink(str_c(temp_path)) < 0)
-			i_error("unlink(%s) failed: %m", str_c(temp_path));
+		i_unlink(str_c(temp_path));
 		return -1;
 	}
 	i_close_fd(&fd);
 
 	if (rename(str_c(temp_path), path) < 0) {
 		i_error("rename(%s, %s) failed: %m", str_c(temp_path), path);
-		if (unlink(str_c(temp_path)) < 0 && errno != ENOENT)
-			i_error("unlink(%s) failed: %m", str_c(temp_path));
+		i_unlink_if_exists(str_c(temp_path));
 		return -1;
 	}
 	return 0;
--- a/src/ssl-params/ssl-params.c	Tue Sep 08 18:49:00 2015 +0300
+++ b/src/ssl-params/ssl-params.c	Tue Sep 08 19:07:02 2015 +0300
@@ -211,7 +211,7 @@
 	if (st.st_size == 0 || st.st_size > MAX_PARAM_FILE_SIZE) {
 		i_error("Corrupted file: %s", param->path);
 		i_close_fd(&fd);
-		(void)unlink(param->path);
+		i_unlink(param->path);
 		return -1;
 	}