@@ -277,49 +277,28 @@ static char* compatibility_params[] = {
277
277
*/
278
278
size_t prepare_compatibility_str (char * compatibility_buf , size_t compatibility_buf_size )
279
279
{
280
- char tmp_buf [1024 ];
281
- int size_inc = 0 ;
282
- size_t result_size = 1 ;
280
+ size_t result_size = 0 ;
283
281
size_t compatibility_params_array_size = sizeof compatibility_params / sizeof compatibility_params [0 ];;
284
282
285
283
* compatibility_buf = '\0' ;
286
284
Assert (compatibility_params_array_size % 2 == 0 );
287
285
288
- //TODO !!!!
289
286
for (int i = 0 ; i < compatibility_params_array_size ; i += 2 )
290
287
{
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 );
313
292
}
314
- return result_size ;
293
+ return result_size + 1 ;
315
294
}
316
295
317
296
/*
318
297
* Check incoming remote agent's compatibility params for equality to local ones.
319
298
*/
320
299
void check_remote_agent_compatibility (int agent_version , char * compatibility_str , size_t compatibility_str_max_size )
321
300
{
322
- elog (LOG , "Agent version=%d" , agent_version );
301
+ elog (LOG , "Agent version=%d\n " , agent_version );
323
302
324
303
if (agent_version != AGENT_PROTOCOL_VERSION )
325
304
{
@@ -331,25 +310,24 @@ void check_remote_agent_compatibility(int agent_version, char *compatibility_str
331
310
332
311
elog (ERROR , "Remote agent protocol version %s does not match local program protocol version %s, "
333
312
"consider to upgrade pg_probackup binary" ,
334
- agent_version_str , AGENT_PROTOCOL_VERSION_STR );
313
+ agent_version_str , AGENT_PROTOCOL_VERSION_STR );
335
314
}
336
315
316
+ /* checking compatibility params */
337
317
if (strnlen (compatibility_str , compatibility_str_max_size ) == compatibility_str_max_size )
338
318
{
339
319
elog (ERROR , "Corrupted remote compatibility protocol: compatibility string has no terminating \\0" );
340
320
}
341
321
342
- elog (LOG , "Agent compatibility params: '%s' " , compatibility_str );
322
+ elog (LOG , "Agent compatibility params:\n%s " , compatibility_str );
343
323
344
- /* checking compatibility params */
345
324
{
346
- char * buf [compatibility_str_max_size ];
325
+ char buf [compatibility_str_max_size ];
347
326
348
327
prepare_compatibility_str (buf , sizeof buf );
349
- if (! strcmp (compatibility_str , buf ))
328
+ if (strcmp (compatibility_str , buf ))
350
329
{
351
- elog (ERROR , "Incompatible agent params, expected %s" , buf );
330
+ elog (ERROR , "Incompatible remote agent params, expected:\n %s" , buf );
352
331
}
353
332
}
354
-
355
333
}
0 commit comments