Skip to content

Commit

Permalink
[Issue #342] check error when writing to pg_probackup.conf and sync i…
Browse files Browse the repository at this point in the history
…t to disk before rename
  • Loading branch information
gsmolk committed Mar 5, 2021
1 parent 2974c03 commit e0dfc9c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ do_set_config(bool missing_ok)

for (i = 0; instance_options[i].type; i++)
{
int rc = 0;
ConfigOption *opt = &instance_options[i];
char *value;

Expand All @@ -319,13 +320,25 @@ do_set_config(bool missing_ok)
}

if (strchr(value, ' '))
fprintf(fp, "%s = '%s'\n", opt->lname, value);
rc = fprintf(fp, "%s = '%s'\n", opt->lname, value);
else
fprintf(fp, "%s = %s\n", opt->lname, value);
rc = fprintf(fp, "%s = %s\n", opt->lname, value);

if (rc < 0)
elog(ERROR, "Cannot write to configuration file: \"%s\"", path_temp);

pfree(value);
}

fclose(fp);
if (ferror(fp) || fflush(fp))
elog(ERROR, "Cannot write to configuration file: \"%s\"", path_temp);

if (fclose(fp))
elog(ERROR, "Cannot close configuration file: \"%s\"", path_temp);

if (fio_sync(path_temp, FIO_LOCAL_HOST) != 0)
elog(ERROR, "Failed to sync temp configuration file \"%s\": %s",
path_temp, strerror(errno));

if (rename(path_temp, path) < 0)
{
Expand Down

0 comments on commit e0dfc9c

Please sign in to comment.