Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e9a4c5

Browse files
committed
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
1 parent d1a0405 commit 7e9a4c5

File tree

19 files changed

+45
-45
lines changed

19 files changed

+45
-45
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ qtext_load_file(Size *buffer_size)
19921992
return NULL;
19931993
}
19941994

1995-
if (CloseTransientFile(fd))
1995+
if (CloseTransientFile(fd) != 0)
19961996
ereport(LOG,
19971997
(errcode_for_file_access(),
19981998
errmsg("could not close file \"%s\": %m", PGSS_TEXT_FILE)));

src/backend/access/heap/rewriteheap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
12021202
errmsg("could not fsync file \"%s\": %m", path)));
12031203
pgstat_report_wait_end();
12041204

1205-
if (CloseTransientFile(fd))
1205+
if (CloseTransientFile(fd) != 0)
12061206
ereport(ERROR,
12071207
(errcode_for_file_access(),
12081208
errmsg("could not close file \"%s\": %m", path)));
@@ -1304,7 +1304,7 @@ CheckPointLogicalRewriteHeap(void)
13041304
errmsg("could not fsync file \"%s\": %m", path)));
13051305
pgstat_report_wait_end();
13061306

1307-
if (CloseTransientFile(fd))
1307+
if (CloseTransientFile(fd) != 0)
13081308
ereport(ERROR,
13091309
(errcode_for_file_access(),
13101310
errmsg("could not close file \"%s\": %m", path)));

src/backend/access/transam/slru.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno)
621621

622622
result = endpos >= (off_t) (offset + BLCKSZ);
623623

624-
if (CloseTransientFile(fd))
624+
if (CloseTransientFile(fd) != 0)
625625
{
626626
slru_errcause = SLRU_CLOSE_FAILED;
627627
slru_errno = errno;
@@ -697,7 +697,7 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
697697
}
698698
pgstat_report_wait_end();
699699

700-
if (CloseTransientFile(fd))
700+
if (CloseTransientFile(fd) != 0)
701701
{
702702
slru_errcause = SLRU_CLOSE_FAILED;
703703
slru_errno = errno;
@@ -869,7 +869,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
869869
if (!fdata)
870870
{
871871
pgstat_report_wait_start(WAIT_EVENT_SLRU_SYNC);
872-
if (ctl->do_fsync && pg_fsync(fd))
872+
if (ctl->do_fsync && pg_fsync(fd) != 0)
873873
{
874874
pgstat_report_wait_end();
875875
slru_errcause = SLRU_FSYNC_FAILED;
@@ -879,7 +879,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
879879
}
880880
pgstat_report_wait_end();
881881

882-
if (CloseTransientFile(fd))
882+
if (CloseTransientFile(fd) != 0)
883883
{
884884
slru_errcause = SLRU_CLOSE_FAILED;
885885
slru_errno = errno;
@@ -1146,7 +1146,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
11461146
for (i = 0; i < fdata.num_files; i++)
11471147
{
11481148
pgstat_report_wait_start(WAIT_EVENT_SLRU_FLUSH_SYNC);
1149-
if (ctl->do_fsync && pg_fsync(fdata.fd[i]))
1149+
if (ctl->do_fsync && pg_fsync(fdata.fd[i]) != 0)
11501150
{
11511151
slru_errcause = SLRU_FSYNC_FAILED;
11521152
slru_errno = errno;
@@ -1155,7 +1155,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
11551155
}
11561156
pgstat_report_wait_end();
11571157

1158-
if (CloseTransientFile(fdata.fd[i]))
1158+
if (CloseTransientFile(fdata.fd[i]) != 0)
11591159
{
11601160
slru_errcause = SLRU_CLOSE_FAILED;
11611161
slru_errno = errno;

src/backend/access/transam/timeline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
371371
pgstat_report_wait_end();
372372
}
373373

374-
if (CloseTransientFile(srcfd))
374+
if (CloseTransientFile(srcfd) != 0)
375375
ereport(ERROR,
376376
(errcode_for_file_access(),
377377
errmsg("could not close file \"%s\": %m", path)));
@@ -415,7 +415,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
415415
errmsg("could not fsync file \"%s\": %m", tmppath)));
416416
pgstat_report_wait_end();
417417

418-
if (CloseTransientFile(fd))
418+
if (CloseTransientFile(fd) != 0)
419419
ereport(ERROR,
420420
(errcode_for_file_access(),
421421
errmsg("could not close file \"%s\": %m", tmppath)));
@@ -493,7 +493,7 @@ writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
493493
errmsg("could not fsync file \"%s\": %m", tmppath)));
494494
pgstat_report_wait_end();
495495

496-
if (CloseTransientFile(fd))
496+
if (CloseTransientFile(fd) != 0)
497497
ereport(ERROR,
498498
(errcode_for_file_access(),
499499
errmsg("could not close file \"%s\": %m", tmppath)));

src/backend/access/transam/twophase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ ReadTwoPhaseFile(TransactionId xid, bool missing_ok)
12991299

13001300
pgstat_report_wait_end();
13011301

1302-
if (CloseTransientFile(fd))
1302+
if (CloseTransientFile(fd) != 0)
13031303
ereport(ERROR,
13041304
(errcode_for_file_access(),
13051305
errmsg("could not close file \"%s\": %m", path)));

src/backend/access/transam/xlog.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
33213321
}
33223322
pgstat_report_wait_end();
33233323

3324-
if (close(fd))
3324+
if (close(fd) != 0)
33253325
ereport(ERROR,
33263326
(errcode_for_file_access(),
33273327
errmsg("could not close file \"%s\": %m", tmppath)));
@@ -3489,12 +3489,12 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
34893489
errmsg("could not fsync file \"%s\": %m", tmppath)));
34903490
pgstat_report_wait_end();
34913491

3492-
if (CloseTransientFile(fd))
3492+
if (CloseTransientFile(fd) != 0)
34933493
ereport(ERROR,
34943494
(errcode_for_file_access(),
34953495
errmsg("could not close file \"%s\": %m", tmppath)));
34963496

3497-
if (CloseTransientFile(srcfd))
3497+
if (CloseTransientFile(srcfd) != 0)
34983498
ereport(ERROR,
34993499
(errcode_for_file_access(),
35003500
errmsg("could not close file \"%s\": %m", path)));
@@ -3791,7 +3791,7 @@ XLogFileClose(void)
37913791
(void) posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED);
37923792
#endif
37933793

3794-
if (close(openLogFile))
3794+
if (close(openLogFile) != 0)
37953795
ereport(PANIC,
37963796
(errcode_for_file_access(),
37973797
errmsg("could not close file \"%s\": %m",
@@ -4566,7 +4566,7 @@ WriteControlFile(void)
45664566
XLOG_CONTROL_FILE)));
45674567
pgstat_report_wait_end();
45684568

4569-
if (close(fd))
4569+
if (close(fd) != 0)
45704570
ereport(PANIC,
45714571
(errcode_for_file_access(),
45724572
errmsg("could not close file \"%s\": %m",
@@ -5225,7 +5225,7 @@ BootStrapXLOG(void)
52255225
errmsg("could not fsync bootstrap write-ahead log file: %m")));
52265226
pgstat_report_wait_end();
52275227

5228-
if (close(openLogFile))
5228+
if (close(openLogFile) != 0)
52295229
ereport(PANIC,
52305230
(errcode_for_file_access(),
52315231
errmsg("could not close bootstrap write-ahead log file: %m")));
@@ -5527,7 +5527,7 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
55275527

55285528
fd = XLogFileInit(startLogSegNo, &use_existent, true);
55295529

5530-
if (close(fd))
5530+
if (close(fd) != 0)
55315531
ereport(ERROR,
55325532
(errcode_for_file_access(),
55335533
errmsg("could not close file \"%s\": %m",

src/backend/libpq/be-fsstubs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ lo_import_internal(text *filename, Oid lobjOid)
456456

457457
inv_close(lobj);
458458

459-
if (CloseTransientFile(fd))
459+
if (CloseTransientFile(fd) != 0)
460460
ereport(ERROR,
461461
(errcode_for_file_access(),
462462
errmsg("could not close file \"%s\": %m",
@@ -529,7 +529,7 @@ be_lo_export(PG_FUNCTION_ARGS)
529529
fnamebuf)));
530530
}
531531

532-
if (CloseTransientFile(fd))
532+
if (CloseTransientFile(fd) != 0)
533533
ereport(ERROR,
534534
(errcode_for_file_access(),
535535
errmsg("could not close file \"%s\": %m",

src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,7 @@ ClosePostmasterPorts(bool am_syslogger)
25202520
* do this as early as possible, so that if postmaster dies, others won't
25212521
* think that it's still running because we're holding the pipe open.
25222522
*/
2523-
if (close(postmaster_alive_fds[POSTMASTER_FD_OWN]))
2523+
if (close(postmaster_alive_fds[POSTMASTER_FD_OWN]) != 0)
25242524
ereport(FATAL,
25252525
(errcode_for_file_access(),
25262526
errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));

src/backend/replication/logical/origin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ CheckPointReplicationOrigin(void)
650650
tmppath)));
651651
}
652652

653-
if (CloseTransientFile(tmpfd))
653+
if (CloseTransientFile(tmpfd) != 0)
654654
ereport(PANIC,
655655
(errcode_for_file_access(),
656656
errmsg("could not close file \"%s\": %m",
@@ -789,7 +789,7 @@ StartupReplicationOrigin(void)
789789
errmsg("replication slot checkpoint has wrong checksum %u, expected %u",
790790
crc, file_crc)));
791791

792-
if (CloseTransientFile(fd))
792+
if (CloseTransientFile(fd) != 0)
793793
ereport(PANIC,
794794
(errcode_for_file_access(),
795795
errmsg("could not close file \"%s\": %m",

src/backend/replication/logical/reorderbuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3360,7 +3360,7 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
33603360
}
33613361
}
33623362

3363-
if (CloseTransientFile(fd))
3363+
if (CloseTransientFile(fd) != 0)
33643364
ereport(ERROR,
33653365
(errcode_for_file_access(),
33663366
errmsg("could not close file \"%s\": %m", path)));

0 commit comments

Comments
 (0)