Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

+1-1
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

+2-2
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

+6-6
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

+3-3
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

+1-1
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

+7-7
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

+2-2
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

+1-1
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

+2-2
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

+1-1
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)));

src/backend/replication/logical/snapbuild.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
16521652
}
16531653
pgstat_report_wait_end();
16541654

1655-
if (CloseTransientFile(fd))
1655+
if (CloseTransientFile(fd) != 0)
16561656
ereport(ERROR,
16571657
(errcode_for_file_access(),
16581658
errmsg("could not close file \"%s\": %m", tmppath)));
@@ -1850,7 +1850,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18501850
}
18511851
COMP_CRC32C(checksum, ondisk.builder.committed.xip, sz);
18521852

1853-
if (CloseTransientFile(fd))
1853+
if (CloseTransientFile(fd) != 0)
18541854
ereport(ERROR,
18551855
(errcode_for_file_access(),
18561856
errmsg("could not close file \"%s\": %m", path)));

src/backend/replication/slot.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
13151315
}
13161316
pgstat_report_wait_end();
13171317

1318-
if (CloseTransientFile(fd))
1318+
if (CloseTransientFile(fd) != 0)
13191319
{
13201320
ereport(elevel,
13211321
(errcode_for_file_access(),
@@ -1472,7 +1472,7 @@ RestoreSlotFromDisk(const char *name)
14721472
path, readBytes, (Size) cp.length)));
14731473
}
14741474

1475-
if (CloseTransientFile(fd))
1475+
if (CloseTransientFile(fd) != 0)
14761476
ereport(PANIC,
14771477
(errcode_for_file_access(),
14781478
errmsg("could not close file \"%s\": %m", path)));

src/backend/replication/walsender.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
522522
bytesleft -= nread;
523523
}
524524

525-
if (CloseTransientFile(fd))
525+
if (CloseTransientFile(fd) != 0)
526526
ereport(ERROR,
527527
(errcode_for_file_access(),
528528
errmsg("could not close file \"%s\": %m", path)));

src/backend/storage/file/copydir.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ copy_file(char *fromfile, char *tofile)
212212
if (offset > flush_offset)
213213
pg_flush_data(dstfd, flush_offset, offset - flush_offset);
214214

215-
if (CloseTransientFile(dstfd))
215+
if (CloseTransientFile(dstfd) != 0)
216216
ereport(ERROR,
217217
(errcode_for_file_access(),
218218
errmsg("could not close file \"%s\": %m", tofile)));
219219

220-
if (CloseTransientFile(srcfd))
220+
if (CloseTransientFile(srcfd) != 0)
221221
ereport(ERROR,
222222
(errcode_for_file_access(),
223223
errmsg("could not close file \"%s\": %m", fromfile)));

src/backend/storage/file/fd.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ durable_rename(const char *oldfile, const char *newfile, int elevel)
647647
return -1;
648648
}
649649

650-
if (CloseTransientFile(fd))
650+
if (CloseTransientFile(fd) != 0)
651651
{
652652
ereport(elevel,
653653
(errcode_for_file_access(),
@@ -1047,7 +1047,7 @@ LruDelete(File file)
10471047
* Close the file. We aren't expecting this to fail; if it does, better
10481048
* to leak the FD than to mess up our internal state.
10491049
*/
1050-
if (close(vfdP->fd))
1050+
if (close(vfdP->fd) != 0)
10511051
elog(vfdP->fdstate & FD_TEMP_FILE_LIMIT ? LOG : data_sync_elevel(LOG),
10521052
"could not close file \"%s\": %m", vfdP->fileName);
10531053
vfdP->fd = VFD_CLOSED;
@@ -1724,7 +1724,7 @@ FileClose(File file)
17241724
if (!FileIsNotOpen(file))
17251725
{
17261726
/* close the file */
1727-
if (close(vfdP->fd))
1727+
if (close(vfdP->fd) != 0)
17281728
{
17291729
/*
17301730
* 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)
33023302
*/
33033303
pg_flush_data(fd, 0, 0);
33043304

3305-
if (CloseTransientFile(fd))
3305+
if (CloseTransientFile(fd) != 0)
33063306
ereport(elevel,
33073307
(errcode_for_file_access(),
33083308
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)
34043404
return -1;
34053405
}
34063406

3407-
if (CloseTransientFile(fd))
3407+
if (CloseTransientFile(fd) != 0)
34083408
{
34093409
ereport(elevel,
34103410
(errcode_for_file_access(),

src/backend/storage/ipc/dsm_impl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
917917
*mapped_address = address;
918918
*mapped_size = request_size;
919919

920-
if (CloseTransientFile(fd))
920+
if (CloseTransientFile(fd) != 0)
921921
{
922922
ereport(elevel,
923923
(errcode_for_file_access(),

src/backend/utils/cache/relmapper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ load_relmap_file(bool shared)
747747
}
748748
pgstat_report_wait_end();
749749

750-
if (CloseTransientFile(fd))
750+
if (CloseTransientFile(fd) != 0)
751751
ereport(FATAL,
752752
(errcode_for_file_access(),
753753
errmsg("could not close file \"%s\": %m",
@@ -886,7 +886,7 @@ write_relmap_file(bool shared, RelMapFile *newmap,
886886
mapfilename)));
887887
pgstat_report_wait_end();
888888

889-
if (CloseTransientFile(fd))
889+
if (CloseTransientFile(fd) != 0)
890890
ereport(ERROR,
891891
(errcode_for_file_access(),
892892
errmsg("could not close file \"%s\": %m",

src/common/controldata_utils.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ get_controlfile(const char *DataDir, bool *crc_ok_p)
106106
}
107107

108108
#ifndef FRONTEND
109-
if (CloseTransientFile(fd))
109+
if (CloseTransientFile(fd) != 0)
110110
ereport(ERROR,
111111
(errcode_for_file_access(),
112112
errmsg("could not close file \"%s\": %m",
113113
ControlFilePath)));
114114
#else
115-
if (close(fd))
115+
if (close(fd) != 0)
116116
{
117117
pg_log_fatal("could not close file \"%s\": %m", ControlFilePath);
118118
exit(EXIT_FAILURE);
@@ -248,7 +248,7 @@ update_controlfile(const char *DataDir,
248248
#endif
249249
}
250250

251-
if (close(fd) < 0)
251+
if (close(fd) != 0)
252252
{
253253
#ifndef FRONTEND
254254
ereport(PANIC,

src/interfaces/libpq/fe-lobj.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
853853
}
854854

855855
/* if we already failed, don't overwrite that msg with a close error */
856-
if (close(fd) && result >= 0)
856+
if (close(fd) != 0 && result >= 0)
857857
{
858858
printfPQExpBuffer(&conn->errorMessage,
859859
libpq_gettext("could not write to file \"%s\": %s\n"),

0 commit comments

Comments
 (0)