summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2019-07-06 21:18:46 +0000
committerPeter Eisentraut2019-07-07 13:28:49 +0000
commit7e9a4c5c3dca0d9637812d8991e96fc8f46800d9 (patch)
treeea48b3d7e575d88a8e4afeb9040dab178f9a2dab
parentd1a040543b49e0aad273e7766cd7e2fcf2b781fa (diff)
Use consistent style for checking return from system calls
Use if (something() != 0) error ... instead of just if (something) error ... The latter is not incorrect, but it's a bit confusing and not the common style. Discussion: https://www.postgresql.org/message-id/flat/5de61b6b-8be9-7771-0048-860328efe027%402ndquadrant.com
-rw-r--r--contrib/pg_stat_statements/pg_stat_statements.c2
-rw-r--r--src/backend/access/heap/rewriteheap.c4
-rw-r--r--src/backend/access/transam/slru.c12
-rw-r--r--src/backend/access/transam/timeline.c6
-rw-r--r--src/backend/access/transam/twophase.c2
-rw-r--r--src/backend/access/transam/xlog.c14
-rw-r--r--src/backend/libpq/be-fsstubs.c4
-rw-r--r--src/backend/postmaster/postmaster.c2
-rw-r--r--src/backend/replication/logical/origin.c4
-rw-r--r--src/backend/replication/logical/reorderbuffer.c2
-rw-r--r--src/backend/replication/logical/snapbuild.c4
-rw-r--r--src/backend/replication/slot.c4
-rw-r--r--src/backend/replication/walsender.c2
-rw-r--r--src/backend/storage/file/copydir.c4
-rw-r--r--src/backend/storage/file/fd.c10
-rw-r--r--src/backend/storage/ipc/dsm_impl.c2
-rw-r--r--src/backend/utils/cache/relmapper.c4
-rw-r--r--src/common/controldata_utils.c6
-rw-r--r--src/interfaces/libpq/fe-lobj.c2
19 files changed, 45 insertions, 45 deletions
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 490ade9e5fe..00cae04eea9 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1992,7 +1992,7 @@ qtext_load_file(Size *buffer_size)
return NULL;
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(LOG,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", PGSS_TEXT_FILE)));
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 369694fa2e9..72a448ad316 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -1202,7 +1202,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
errmsg("could not fsync file \"%s\": %m", path)));
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
@@ -1304,7 +1304,7 @@ CheckPointLogicalRewriteHeap(void)
errmsg("could not fsync file \"%s\": %m", path)));
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 2dbc65b125b..13aa8e1b95a 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -621,7 +621,7 @@ SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno)
result = endpos >= (off_t) (offset + BLCKSZ);
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
slru_errcause = SLRU_CLOSE_FAILED;
slru_errno = errno;
@@ -697,7 +697,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
}
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
slru_errcause = SLRU_CLOSE_FAILED;
slru_errno = errno;
@@ -869,7 +869,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
if (!fdata)
{
pgstat_report_wait_start(WAIT_EVENT_SLRU_SYNC);
- if (ctl->do_fsync && pg_fsync(fd))
+ if (ctl->do_fsync && pg_fsync(fd) != 0)
{
pgstat_report_wait_end();
slru_errcause = SLRU_FSYNC_FAILED;
@@ -879,7 +879,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
}
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
slru_errcause = SLRU_CLOSE_FAILED;
slru_errno = errno;
@@ -1146,7 +1146,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
for (i = 0; i < fdata.num_files; i++)
{
pgstat_report_wait_start(WAIT_EVENT_SLRU_FLUSH_SYNC);
- if (ctl->do_fsync && pg_fsync(fdata.fd[i]))
+ if (ctl->do_fsync && pg_fsync(fdata.fd[i]) != 0)
{
slru_errcause = SLRU_FSYNC_FAILED;
slru_errno = errno;
@@ -1155,7 +1155,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
}
pgstat_report_wait_end();
- if (CloseTransientFile(fdata.fd[i]))
+ if (CloseTransientFile(fdata.fd[i]) != 0)
{
slru_errcause = SLRU_CLOSE_FAILED;
slru_errno = errno;
diff --git a/src/backend/access/transam/timeline.c b/src/backend/access/transam/timeline.c
index cbd9b2cee19..c2ba480c703 100644
--- a/src/backend/access/transam/timeline.c
+++ b/src/backend/access/transam/timeline.c
@@ -371,7 +371,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
pgstat_report_wait_end();
}
- if (CloseTransientFile(srcfd))
+ if (CloseTransientFile(srcfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
@@ -415,7 +415,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
errmsg("could not fsync file \"%s\": %m", tmppath)));
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tmppath)));
@@ -493,7 +493,7 @@ writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
errmsg("could not fsync file \"%s\": %m", tmppath)));
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tmppath)));
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 5196d6181dd..477709bbc23 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -1299,7 +1299,7 @@ ReadTwoPhaseFile(TransactionId xid, bool missing_ok)
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 13e0d2366f5..b6c9353cbd2 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -3321,7 +3321,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
}
pgstat_report_wait_end();
- if (close(fd))
+ if (close(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tmppath)));
@@ -3489,12 +3489,12 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
errmsg("could not fsync file \"%s\": %m", tmppath)));
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tmppath)));
- if (CloseTransientFile(srcfd))
+ if (CloseTransientFile(srcfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
@@ -3791,7 +3791,7 @@ XLogFileClose(void)
(void) posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED);
#endif
- if (close(openLogFile))
+ if (close(openLogFile) != 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
@@ -4566,7 +4566,7 @@ WriteControlFile(void)
XLOG_CONTROL_FILE)));
pgstat_report_wait_end();
- if (close(fd))
+ if (close(fd) != 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
@@ -5225,7 +5225,7 @@ BootStrapXLOG(void)
errmsg("could not fsync bootstrap write-ahead log file: %m")));
pgstat_report_wait_end();
- if (close(openLogFile))
+ if (close(openLogFile) != 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close bootstrap write-ahead log file: %m")));
@@ -5527,7 +5527,7 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
fd = XLogFileInit(startLogSegNo, &use_existent, true);
- if (close(fd))
+ if (close(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index 97add3f257d..a750f921fa1 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -456,7 +456,7 @@ lo_import_internal(text *filename, Oid lobjOid)
inv_close(lobj);
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
@@ -529,7 +529,7 @@ be_lo_export(PG_FUNCTION_ARGS)
fnamebuf)));
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 688ad439edb..3339804be91 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2520,7 +2520,7 @@ ClosePostmasterPorts(bool am_syslogger)
* do this as early as possible, so that if postmaster dies, others won't
* think that it's still running because we're holding the pipe open.
*/
- if (close(postmaster_alive_fds[POSTMASTER_FD_OWN]))
+ if (close(postmaster_alive_fds[POSTMASTER_FD_OWN]) != 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 681132c922b..7477ceae283 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -650,7 +650,7 @@ CheckPointReplicationOrigin(void)
tmppath)));
}
- if (CloseTransientFile(tmpfd))
+ if (CloseTransientFile(tmpfd) != 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
@@ -789,7 +789,7 @@ StartupReplicationOrigin(void)
errmsg("replication slot checkpoint has wrong checksum %u, expected %u",
crc, file_crc)));
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index e7c32f2a132..591377d2cd7 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -3360,7 +3360,7 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
}
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 3e9d4cd79f9..dc64b1e0c2f 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -1652,7 +1652,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
}
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tmppath)));
@@ -1850,7 +1850,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
}
COMP_CRC32C(checksum, ondisk.builder.committed.xip, sz);
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 3861b8f583c..62342a69cbf 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -1315,7 +1315,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
}
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
ereport(elevel,
(errcode_for_file_access(),
@@ -1472,7 +1472,7 @@ RestoreSlotFromDisk(const char *name)
path, readBytes, (Size) cp.length)));
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(PANIC,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 92fa86fc9d5..e7a59b0a921 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -522,7 +522,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
bytesleft -= nread;
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", path)));
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index 30f6200a86f..ca1c9cd7655 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -212,12 +212,12 @@ copy_file(char *fromfile, char *tofile)
if (offset > flush_offset)
pg_flush_data(dstfd, flush_offset, offset - flush_offset);
- if (CloseTransientFile(dstfd))
+ if (CloseTransientFile(dstfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", tofile)));
- if (CloseTransientFile(srcfd))
+ if (CloseTransientFile(srcfd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", fromfile)));
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 6bfd4fa13ef..7b49802b4e1 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -647,7 +647,7 @@ durable_rename(const char *oldfile, const char *newfile, int elevel)
return -1;
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
ereport(elevel,
(errcode_for_file_access(),
@@ -1047,7 +1047,7 @@ LruDelete(File file)
* Close the file. We aren't expecting this to fail; if it does, better
* to leak the FD than to mess up our internal state.
*/
- if (close(vfdP->fd))
+ if (close(vfdP->fd) != 0)
elog(vfdP->fdstate & FD_TEMP_FILE_LIMIT ? LOG : data_sync_elevel(LOG),
"could not close file \"%s\": %m", vfdP->fileName);
vfdP->fd = VFD_CLOSED;
@@ -1724,7 +1724,7 @@ FileClose(File file)
if (!FileIsNotOpen(file))
{
/* close the file */
- if (close(vfdP->fd))
+ if (close(vfdP->fd) != 0)
{
/*
* We may need to panic on failure to close non-temporary files;
@@ -3302,7 +3302,7 @@ pre_sync_fname(const char *fname, bool isdir, int elevel)
*/
pg_flush_data(fd, 0, 0);
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(elevel,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m", fname)));
@@ -3404,7 +3404,7 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
return -1;
}
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
ereport(elevel,
(errcode_for_file_access(),
diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c
index d32996b6fc4..2879b84bf61 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -917,7 +917,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
*mapped_address = address;
*mapped_size = request_size;
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
{
ereport(elevel,
(errcode_for_file_access(),
diff --git a/src/backend/utils/cache/relmapper.c b/src/backend/utils/cache/relmapper.c
index 3b4f21bc548..42b0c48c2be 100644
--- a/src/backend/utils/cache/relmapper.c
+++ b/src/backend/utils/cache/relmapper.c
@@ -747,7 +747,7 @@ load_relmap_file(bool shared)
}
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
@@ -886,7 +886,7 @@ write_relmap_file(bool shared, RelMapFile *newmap,
mapfilename)));
pgstat_report_wait_end();
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 2c28e51e111..39c27c92292 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -106,13 +106,13 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
}
#ifndef FRONTEND
- if (CloseTransientFile(fd))
+ if (CloseTransientFile(fd) != 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not close file \"%s\": %m",
ControlFilePath)));
#else
- if (close(fd))
+ if (close(fd) != 0)
{
pg_log_fatal("could not close file \"%s\": %m", ControlFilePath);
exit(EXIT_FAILURE);
@@ -248,7 +248,7 @@ update_controlfile(const char *DataDir,
#endif
}
- if (close(fd) < 0)
+ if (close(fd) != 0)
{
#ifndef FRONTEND
ereport(PANIC,
diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c
index 6866d645380..e755f69ab8a 100644
--- a/src/interfaces/libpq/fe-lobj.c
+++ b/src/interfaces/libpq/fe-lobj.c
@@ -853,7 +853,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
}
/* if we already failed, don't overwrite that msg with a close error */
- if (close(fd) && result >= 0)
+ if (close(fd) != 0 && result >= 0)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not write to file \"%s\": %s\n"),