repmgr: truncate version string if necessary

Some distributions may add extra information to PG_VERSION after
the actual version number (e.g. "10.4 (Debian 10.4-2.pgdg90+1)"), so
copy the version number string up until the first space is found.

GitHub #490.
This commit is contained in:
Ian Barwick
2018-08-14 09:48:46 +09:00
parent f8667c1aac
commit 34c4f4c3f8
2 changed files with 23 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
4.1.1 2018-??-??
repmgr: truncate version string, if necessary; GitHub #490 (Ian)
repmgrd: ensure that sending SIGHUP always results in the log file
being reopened; GitHub #485 (Ian)
repmgrd: report version number *after* logger initialisation; GitHub #487 (Ian)

View File

@@ -1095,7 +1095,28 @@ get_server_version(PGconn *conn, char *server_version)
}
if (server_version != NULL)
strncpy(server_version, PQgetvalue(res, 0, 1), MAXVERSIONSTR);
{
char server_version_buf[MAXVERSIONSTR];
int i;
memset(server_version_buf, 0, MAXVERSIONSTR);
/*
* Some distributions may add extra info after the actual version number,
* e.g. "10.4 (Debian 10.4-2.pgdg90+1)", so copy everything up until the
* first space.
*/
strncpy(server_version_buf, PQgetvalue(res, 0, 1), MAXVERSIONSTR);
for (i = 0; i < MAXVERSIONSTR; i++)
{
if (server_version_buf[i] == ' ')
break;
*server_version++ = server_version_buf[i];
}
}
server_version_num = atoi(PQgetvalue(res, 0, 0));