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

Commit830e8e3

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 parent4a9b44d commit830e8e3

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
@@ -4311,6 +4311,7 @@ ReadControlFile(void)
43114311
{
43124312
pg_crc32ccrc;
43134313
intfd;
4314+
intr;
43144315

43154316
/*
43164317
* Read data...
@@ -4324,10 +4325,17 @@ ReadControlFile(void)
43244325
errmsg("could not open control file \"%s\": %m",
43254326
XLOG_CONTROL_FILE)));
43264327

4327-
if (read(fd,ControlFile,sizeof(ControlFileData))!=sizeof(ControlFileData))
4328-
ereport(PANIC,
4329-
(errcode_for_file_access(),
4330-
errmsg("could not read from control file: %m")));
4328+
r=read(fd,ControlFile,sizeof(ControlFileData));
4329+
if (r!=sizeof(ControlFileData))
4330+
{
4331+
if (r<0)
4332+
ereport(PANIC,
4333+
(errcode_for_file_access(),
4334+
errmsg("could not read from control file: %m")));
4335+
else
4336+
ereport(PANIC,
4337+
(errmsg("could not read from control file: read %d bytes, expected %d",r, (int)sizeof(ControlFileData))));
4338+
}
43314339

43324340
close(fd);
43334341

‎src/common/controldata_utils.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ get_controlfile(char *DataDir, const char *progname)
4141
intfd;
4242
charControlFilePath[MAXPGPATH];
4343
pg_crc32ccrc;
44+
intr;
4445

4546
ControlFile=palloc(sizeof(ControlFileData));
4647
snprintf(ControlFilePath,MAXPGPATH,"%s/global/pg_control",DataDir);
@@ -59,18 +60,34 @@ get_controlfile(char *DataDir, const char *progname)
5960
}
6061
#endif
6162

62-
if (read(fd,ControlFile,sizeof(ControlFileData))!=sizeof(ControlFileData))
63+
r=read(fd,ControlFile,sizeof(ControlFileData));
64+
if (r!=sizeof(ControlFileData))
65+
{
66+
if (r<0)
6367
#ifndefFRONTEND
64-
ereport(ERROR,
65-
(errcode_for_file_access(),
66-
errmsg("could not read file \"%s\": %m",ControlFilePath)));
68+
ereport(ERROR,
69+
(errcode_for_file_access(),
70+
errmsg("could not read file \"%s\": %m",ControlFilePath)));
6771
#else
68-
{
69-
fprintf(stderr,_("%s: could not read file \"%s\": %s\n"),
70-
progname,ControlFilePath,strerror(errno));
71-
exit(EXIT_FAILURE);
72-
}
72+
{
73+
fprintf(stderr,_("%s: could not read file \"%s\": %s\n"),
74+
progname,ControlFilePath,strerror(errno));
75+
exit(EXIT_FAILURE);
76+
}
7377
#endif
78+
else
79+
#ifndefFRONTEND
80+
ereport(ERROR,
81+
(errmsg("could not read file \"%s\": read %d bytes, expected %d",
82+
ControlFilePath,r, (int)sizeof(ControlFileData))));
83+
#else
84+
{
85+
fprintf(stderr,_("%s: could not read file \"%s\": read %d bytes, expected %d\n"),
86+
progname,ControlFilePath,r, (int)sizeof(ControlFileData));
87+
exit(EXIT_FAILURE);
88+
}
89+
#endif
90+
}
7491

7592
close(fd);
7693

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp