@@ -44,6 +44,7 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
4444 int fd ;
4545 char ControlFilePath [MAXPGPATH ];
4646 pg_crc32c crc ;
47+ int r ;
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#ifndef FRONTEND
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+ #ifndef FRONTEND
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