@@ -41,6 +41,7 @@ get_controlfile(char *DataDir, const char *progname)
41
41
int fd ;
42
42
char ControlFilePath [MAXPGPATH ];
43
43
pg_crc32c crc ;
44
+ int r ;
44
45
45
46
ControlFile = palloc (sizeof (ControlFileData ));
46
47
snprintf (ControlFilePath , MAXPGPATH , "%s/global/pg_control" , DataDir );
@@ -59,18 +60,34 @@ get_controlfile(char *DataDir, const char *progname)
59
60
}
60
61
#endif
61
62
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 )
63
67
#ifndef FRONTEND
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 )));
67
71
#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
+ }
73
77
#endif
78
+ else
79
+ #ifndef FRONTEND
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
+ }
74
91
75
92
close (fd );
76
93
0 commit comments