@@ -1102,6 +1102,7 @@ pg_stop_backup(pgBackup *backup)
11021102 char backup_label [MAXPGPATH ];
11031103 FILE * fp ;
11041104 pgFile * file ;
1105+ size_t len ;
11051106
11061107 Assert (PQnfields (res ) >= 5 );
11071108
@@ -1114,9 +1115,13 @@ pg_stop_backup(pgBackup *backup)
11141115 elog (ERROR , "can't open backup label file \"%s\": %s" ,
11151116 backup_label , strerror (errno ));
11161117
1117- fwrite (PQgetvalue (res , 0 , 1 ), 1 , strlen (PQgetvalue (res , 0 , 1 )), fp );
1118- fsync (fileno (fp ));
1119- fclose (fp );
1118+ len = strlen (PQgetvalue (res , 0 , 1 ));
1119+ if (fwrite (PQgetvalue (res , 0 , 1 ), 1 , len , fp ) != len ||
1120+ fflush (fp ) != 0 ||
1121+ fsync (fileno (fp )) != 0 ||
1122+ fclose (fp ))
1123+ elog (ERROR , "can't write backup label file \"%s\": %s" ,
1124+ backup_label , strerror (errno ));
11201125
11211126 /*
11221127 * It's vital to check if backup_files_list is initialized,
@@ -1142,9 +1147,13 @@ pg_stop_backup(pgBackup *backup)
11421147 elog (ERROR , "can't open tablespace map file \"%s\": %s" ,
11431148 tablespace_map , strerror (errno ));
11441149
1145- fwrite (PQgetvalue (res , 0 , 2 ), 1 , strlen (PQgetvalue (res , 0 , 2 )), fp );
1146- fsync (fileno (fp ));
1147- fclose (fp );
1150+ len = strlen (PQgetvalue (res , 0 , 2 ));
1151+ if (fwrite (PQgetvalue (res , 0 , 2 ), 1 , len , fp ) != len ||
1152+ fflush (fp ) != 0 ||
1153+ fsync (fileno (fp )) != 0 ||
1154+ fclose (fp ))
1155+ elog (ERROR , "can't write tablespace map file \"%s\": %s" ,
1156+ tablespace_map , strerror (errno ));
11481157
11491158 file = pgFileNew (tablespace_map , true);
11501159 calc_file_checksum (file );
@@ -1667,8 +1676,10 @@ write_backup_file_list(parray *files, const char *root)
16671676
16681677 print_file_list (fp , files , root );
16691678
1670- fsync (fileno (fp ));
1671- fclose (fp );
1679+ if (fflush (fp ) != 0 ||
1680+ fsync (fileno (fp )) != 0 ||
1681+ fclose (fp ))
1682+ elog (ERROR , "cannot write file list \"%s\": %s" , path , strerror (errno ));
16721683}
16731684
16741685/*
0 commit comments