Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit29ce500

Browse files
committed
Fix error message on short read of pg_control
Instead of saying "error: success", indicate that we got a working readbut it was too short.
1 parentee68541 commit29ce500

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4475,6 +4475,7 @@ ReadControlFile(void)
44754475
{
44764476
pg_crc32ccrc;
44774477
intfd;
4478+
intr;
44784479

44794480
/*
44804481
* Read data...
@@ -4489,10 +4490,17 @@ ReadControlFile(void)
44894490
XLOG_CONTROL_FILE)));
44904491

44914492
pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_READ);
4492-
if (read(fd,ControlFile,sizeof(ControlFileData))!=sizeof(ControlFileData))
4493-
ereport(PANIC,
4494-
(errcode_for_file_access(),
4495-
errmsg("could not read from control file: %m")));
4493+
r=read(fd,ControlFile,sizeof(ControlFileData));
4494+
if (r!=sizeof(ControlFileData))
4495+
{
4496+
if (r<0)
4497+
ereport(PANIC,
4498+
(errcode_for_file_access(),
4499+
errmsg("could not read from control file: %m")));
4500+
else
4501+
ereport(PANIC,
4502+
(errmsg("could not read from control file: read %d bytes, expected %d",r, (int)sizeof(ControlFileData))));
4503+
}
44964504
pgstat_report_wait_end();
44974505

44984506
close(fd);

‎src/common/controldata_utils.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
4444
intfd;
4545
charControlFilePath[MAXPGPATH];
4646
pg_crc32ccrc;
47+
intr;
4748

4849
AssertArg(crc_ok_p);
4950

@@ -64,18 +65,34 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
6465
}
6566
#endif
6667

67-
if (read(fd,ControlFile,sizeof(ControlFileData))!=sizeof(ControlFileData))
68+
r=read(fd,ControlFile,sizeof(ControlFileData));
69+
if (r!=sizeof(ControlFileData))
70+
{
71+
if (r<0)
6872
#ifndefFRONTEND
69-
ereport(ERROR,
70-
(errcode_for_file_access(),
71-
errmsg("could not read file \"%s\": %m",ControlFilePath)));
73+
ereport(ERROR,
74+
(errcode_for_file_access(),
75+
errmsg("could not read file \"%s\": %m",ControlFilePath)));
7276
#else
73-
{
74-
fprintf(stderr,_("%s: could not read file \"%s\": %s\n"),
75-
progname,ControlFilePath,strerror(errno));
76-
exit(EXIT_FAILURE);
77-
}
77+
{
78+
fprintf(stderr,_("%s: could not read file \"%s\": %s\n"),
79+
progname,ControlFilePath,strerror(errno));
80+
exit(EXIT_FAILURE);
81+
}
7882
#endif
83+
else
84+
#ifndefFRONTEND
85+
ereport(ERROR,
86+
(errmsg("could not read file \"%s\": read %d bytes, expected %d",
87+
ControlFilePath,r, (int)sizeof(ControlFileData))));
88+
#else
89+
{
90+
fprintf(stderr,_("%s: could not read file \"%s\": read %d bytes, expected %d\n"),
91+
progname,ControlFilePath,r, (int)sizeof(ControlFileData));
92+
exit(EXIT_FAILURE);
93+
}
94+
#endif
95+
}
7996

8097
close(fd);
8198

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp