8000 [PBCKP-236] draft, solution without macros cleanup · postgrespro/pg_probackup@0604cce · GitHub
[go: up one dir, main page]

Skip to content

Commit 0604cce

Browse files
author
Ivan Lazarev
committed
[PBCKP-236] draft, solution without macros cleanup
1 parent eefd887 commit 0604cce

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

src/utils/file.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fio_get_agent_version(int* protocol, char* payload_buf, size_t payload_buf_size)
281281
IO_CHECK(fio_read_all(fio_stdin, &hdr, sizeof(hdr)), sizeof(hdr));
282282
if (hdr.size > payload_buf_size)
283283
{
284-
//TODO REVIEW XXX %zu is C99 but not ANSI S standard, should we cast to unsigned long?
284+
//TODO REVIEW XXX %zu is C99 but not ANSI S compatible, should we use ints, %zu is also applied at data.c:501 data.c:1638??
285285
elog(ERROR, "Corrupted remote compatibility protocol: insufficient payload_buf_size=%zu", payload_buf_size);
286286
}
287287

@@ -3330,8 +3330,6 @@ fio_communicate(int in, int out)
33303330

33313331
IO_CHECK(fio_write_all(out, &hdr, sizeof(hdr)), sizeof(hdr));
33323332
IO_CHECK(fio_write_all(out, buf, payload_size), payload_size);
3333-
//TODO REVIEW XXX make INFO to LOG or VERBOSE
3334-
elog(INFO, "TODO REVIEW XXX sent agent compatibility\n %s", buf);
33353333
break;
33363334
}
33373335
case FIO_STAT: /* Get information about file with specified path */

src/utils/remote.c

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -277,49 +277,28 @@ static char* compatibility_params[] = {
277277
*/
278278
size_t prepare_compatibility_str(char* compatibility_buf, size_t compatibility_buf_size)
279279
{
280-
char tmp_buf[1024];
281-
int size_inc = 0;
282-
size_t result_size = 1;
280+
size_t result_size = 0;
283281
size_t compatibility_params_array_size = sizeof compatibility_params / sizeof compatibility_params[0];;
284282

285283
*compatibility_buf = '\0';
286284
Assert(compatibility_params_array_size % 2 == 0);
287285

288-
//TODO !!!!
289286
for (int i = 0; i < compatibility_params_array_size; i+=2)
290287
{
291-
size_inc = snprintf(compatibility_buf + size_inc, compatibility_buf_size,
292-
"%s" COMPATIBILITY_VAL_SEPARATOR "%s" COMPATIBILITY_LINE_SEPARATOR,
293-
compatibility_params[i], compatibility_params[i+1]);
294-
295-
// size_inc = snprintf(tmp_buf, sizeof tmp_buf,
296-
// "%s" COMPATIBILITY_VAL_SEPARATOR "%s" COMPATIBILITY_LINE_SEPARATOR,
297-
// compatibility_params[i], compatibility_params[i+1]);
298-
if (size_inc >= sizeof tmp_buf)
299-
{
300-
//TODO make Assert
301-
elog(ERROR, "Compatibility params from agent doesn't fit to %zu chars, %s=%s",
302-
sizeof tmp_buf - 1, compatibility_params[i], compatibility_params[i+1] );
303-
}
304-
305-
result_size += size_inc;
306-
if (result_size > compatibility_buf_size)
307-
{
308-
//TODO make Assert
309-
elog(ERROR, "Can't fit compatibility string size %zu to buffer size %zu:\n%s\n%s",
310-
result_size, compatibility_buf_size, compatibility_buf, tmp_buf);
311-
}
312-
strcat(compatibility_buf, tmp_buf);
288+
result_size += snprintf(compatibility_buf + result_size, compatibility_buf_size - result_size,
289+
"%s" COMPATIBILITY_VAL_SEPARATOR "%s" COMPATIBILITY_LINE_SEPARATOR,
290+
compatibility_params[i], compatibility_params[i+1]);
291+
Assert(result_size < compatibility_buf_size);
313292
}
314-
return result_size;
293+
return result_size + 1;
315294
}
316295

317296
/*
318297
* Check incoming remote agent's compatibility params for equality to local ones.
319298
*/
320299
void check_remote_agent_compatibility(int agent_version, char *compatibility_str, size_t compatibility_str_max_size)
321300
{
322-
elog(LOG, "Agent version=%d", agent_version);
301+
elog(LOG, "Agent version=%d\n", agent_version);
323302

324303
if (agent_version != AGENT_PROTOCOL_VERSION)
325304
{
@@ -331,25 +310,24 @@ void check_remote_agent_compatibility(int agent_version, char *compatibility_str
331310

332311
elog(ERROR, "Remote agent protocol version %s does not match local program protocol version %s, "
333312
"consider to upgrade pg_probackup binary",
334-
agent_version_str, AGENT_PROTOCOL_VERSION_STR);
313+
agent_version_str, AGENT_PROTOCOL_VERSION_STR);
335314
}
336315

316+
/* checking compatibility params */
337317
if (strnlen(compatibility_str, compatibility_str_max_size) == compatibility_str_max_size)
338318
{
339319
elog(ERROR, "Corrupted remote compatibility protocol: compatibility string has no terminating \\0");
340320
}
341321

342-
elog(LOG, "Agent compatibility params: '%s'", compatibility_str);
322+
elog(LOG, "Agent compatibility params:\n%s", compatibility_str);
343323

344-
/* checking compatibility params */
345324
{
346-
char *buf[compatibility_str_max_size];
325+
char buf[compatibility_str_max_size];
347326

348327
prepare_compatibility_str(buf, sizeof buf);
349-
if(!strcmp(compatibility_str, buf))
328+
if(strcmp(compatibility_str, buf))
350329
{
351-
elog(ERROR, "Incompatible agent params, expected %s", buf);
330+
elog(ERROR, "Incompatible remote agent params, expected:\n%s", buf);
352331
}
353332
}
354-
355333
}

0 commit comments

Comments
 (0)
0