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

Commitcfb758b

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 parenta194106 commitcfb758b

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
@@ -4486,6 +4486,7 @@ ReadControlFile(void)
44864486
pg_crc32ccrc;
44874487
intfd;
44884488
staticcharwal_segsz_str[20];
4489+
intr;
44894490

44904491
/*
44914492
* Read data...
@@ -4499,10 +4500,17 @@ ReadControlFile(void)
44994500
XLOG_CONTROL_FILE)));
45004501

45014502
pgstat_report_wait_start(WAIT_EVENT_CONTROL_FILE_READ);
4502-
if (read(fd,ControlFile,sizeof(ControlFileData))!=sizeof(ControlFileData))
4503-
ereport(PANIC,
4504-
(errcode_for_file_access(),
4505-
errmsg("could not read from control file: %m")));
4503+
r=read(fd,ControlFile,sizeof(ControlFileData));
4504+
if (r!=sizeof(ControlFileData))
4505+
{
4506+
if (r<0)
4507+
ereport(PANIC,
4508+
(errcode_for_file_access(),
4509+
errmsg("could not read from control file: %m")));
4510+
else
4511+
ereport(PANIC,
4512+
(errmsg("could not read from control file: read %d bytes, expected %d",r, (int)sizeof(ControlFileData))));
4513+
}
45064514
pgstat_report_wait_end();
45074515

45084516
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