* Write the configuration file in the directory specified in target_dir, * with the contents already collected in memory appended. Then write * the signal file into the target_dir. If the server does not support * recovery parameters as GUCs, the signal file is not necessary, and * configuration is written to recovery.conf. */
| 117 | * configuration is written to recovery.conf. |
| 118 | */ |
| 119 | void |
| 120 | WriteRecoveryConfig(PGconn *pgconn, char *target_dir, PQExpBuffer contents) |
| 121 | { |
| 122 | char filename[MAXPGPATH]; |
| 123 | FILE *cf; |
| 124 | bool use_recovery_conf; |
| 125 | |
| 126 | Assert(pgconn != NULL); |
| 127 | |
| 128 | use_recovery_conf = |
| 129 | PQserverVersion(pgconn) < MINIMUM_VERSION_FOR_RECOVERY_GUC; |
| 130 | |
| 131 | snprintf(filename, MAXPGPATH, "%s/%s", target_dir, |
| 132 | use_recovery_conf ? "recovery.conf" : "postgresql.auto.conf"); |
| 133 | |
| 134 | cf = fopen(filename, use_recovery_conf ? "w" : "a"); |
| 135 | if (cf == NULL) |
| 136 | { |
| 137 | pg_log_error("could not open file \"%s\": %m", filename); |
| 138 | exit(1); |
| 139 | } |
| 140 | |
| 141 | if (fwrite(contents->data, contents->len, 1, cf) != 1) |
| 142 | { |
| 143 | pg_log_error("could not write to file \"%s\": %m", filename); |
| 144 | exit(1); |
| 145 | } |
| 146 | |
| 147 | fclose(cf); |
| 148 | |
| 149 | if (!use_recovery_conf) |
| 150 | { |
| 151 | snprintf(filename, MAXPGPATH, "%s/%s", target_dir, "standby.signal"); |
| 152 | cf = fopen(filename, "w"); |
| 153 | if (cf == NULL) |
| 154 | { |
| 155 | pg_log_error("could not create file \"%s\": %m", filename); |
| 156 | exit(1); |
| 157 | } |
| 158 | |
| 159 | fclose(cf); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Escape a string so that it can be used as a value in a key-value pair |
no test coverage detected