@@ -277,49 +277,28 @@ static char* compatibility_params[] = {
277277 */
278278size_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 */
320299void 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