@@ -292,12 +292,8 @@ static char* extract_pg_edition_str()
292
292
#endif
293
293
}
294
294
295
- #define COMPATIBILITY_VAL_STR (macro ) #macro, macro
296
- #define COMPATIBILITY_VAL_INT_HELPER (macro , helper_buf , buf_size ) (snprintf(helper_buf, buf_size, "%d", macro), helper_buf)
297
- #define COMPATIBILITY_VAL_INT (macro , helper_buf , buf_size ) #macro, COMPATIBILITY_VAL_INT_HELPER(macro, helper_buf, buf_size)
298
-
299
- #define COMPATIBILITY_VAL_SEPARATOR "="
300
- #define COMPATIBILITY_LINE_SEPARATOR "\n"
295
+ #define COMPATIBILITY_VAL_STR (macro ) { #macro, macro, 0 }
296
+ #define COMPATIBILITY_VAL_INT (macro ) { #macro, NULL, macro }
301
297
302
298
/*
303
299
* Compose compatibility string to be sent by pg_probackup agent
@@ -307,13 +303,10 @@ static char* extract_pg_edition_str()
307
303
*/
308
304
size_t prepare_compatibility_str (char * compatibility_buf , size_t compatibility_buf_size )
309
305
{
310
- char compatibility_val_int_macro_helper_buf [32 ];
311
- char * compatibility_params [] = {
306
+ struct { const char * name ; const char * strval ; int intval ; } compatibility_params [] = {
312
307
COMPATIBILITY_VAL_STR (PG_MAJORVERSION ),
313
- "edition" , extract_pg_edition_str (),
314
- /* 32/64 bits compatibility */
315
- COMPATIBILITY_VAL_INT (SIZEOF_VOID_P ,
316
- compatibility_val_int_macro_helper_buf , sizeof compatibility_val_int_macro_helper_buf ),
308
+ { "edition" , extract_pg_edition_str (), 0 },
309
+ COMPATIBILITY_VAL_INT (SIZEOF_VOID_P ),
317
310
};
318
311
319
312
size_t result_size = 0 ;
@@ -324,9 +317,16 @@ size_t prepare_compatibility_str(char* compatibility_buf, size_t compatibility_b
324
317
325
318
for (int i = 0 ; i < compatibility_params_array_size ; i += 2 )
326
319
{
327
- result_size += snprintf (compatibility_buf + result_size , compatibility_buf_size - result_size ,
328
- "%s" COMPATIBILITY_VAL_SEPARATOR "%s" COMPATIBILITY_LINE_SEPARATOR ,
329
- compatibility_params [i ], compatibility_params [i + 1 ]);
320
+ if (compatibility_params [i ].strval != NULL )
321
+ result_size += snprintf (compatibility_buf + result_size , compatibility_buf_size - result_size ,
322
+ "%s=%s/n" ,
323
+ compatibility_params [i ].name ,
324
+ compatibility_params [i ].strval );
325
+ else
326
+ result_size += snprintf (compatibility_buf + result_size , compatibility_buf_size - result_size ,
327
+ "%s=%d/n" ,
328
+ compatibility_params [i ].name ,
329
+ compatibility_params [i ].intval );
330
330
Assert (result_size < compatibility_buf_size );
331
331
}
332
332
return result_size + 1 ;
@@ -349,7 +349,7 @@ void check_remote_agent_compatibility(int agent_version, char *compatibility_str
349
349
350
350
elog (ERROR , "Remote agent protocol version %s does not match local program protocol version %s, "
351
351
"consider to upgrade pg_probackup binary" ,
352
- agent_version_str , AGENT_PROTOCOL_VERSION_STR );
352
+ agent_version_str , AGENT_PROTOCOL_VERSION_STR );
353
353
}
354
354
355
355
/* checking compatibility params */
0 commit comments