Consolidate various backported functions

This commit is contained in:
Ian Barwick
2016-12-22 12:11:54 +09:00
parent 666e71a589
commit 9da0914976
7 changed files with 44 additions and 42 deletions

View File

@@ -10,6 +10,7 @@
with cascaded downstream node records (Ian)
repmgr: add option `--no-conninfo-password` (Abhijit, Ian)
repmgr: add initial support for PostgreSQL 10.0 (Ian)
repmgr: escape values in primary_conninfo if needed (Ian)
3.2.1 2016-10-24
repmgr: require a valid repmgr cluster name unless -F/--force

View File

@@ -5,7 +5,7 @@
HEADERS = $(wildcard *.h)
repmgrd_OBJS = dbutils.o config.o repmgrd.o log.o strutil.o
repmgr_OBJS = dbutils.o check_dir.o config.o repmgr.o log.o strutil.o dirmod.o escape.o
repmgr_OBJS = dbutils.o check_dir.o config.o repmgr.o log.o strutil.o dirmod.o compat.o
DATA = repmgr.sql uninstall_repmgr.sql

View File

@@ -1,7 +1,8 @@
/*
*
* escape.c
* parameter escaping functions
* compat.c
* Provide backports of various functions not publicly
* exposed before PostgreSQL 9.6
*
* Copyright (C) 2ndQuadrant, 2010-2016
*
@@ -26,7 +27,7 @@
#if (PG_VERSION_NUM < 90600)
#include "repmgr.h"
#include "escape.h"
#include "compat.h"
/*
* Append the given string to the buffer, with suitable quoting for passing
@@ -76,4 +77,35 @@ appendConnStrVal(PQExpBuffer buf, const char *str)
appendPQExpBufferStr(buf, str);
}
/*
* Adapted from: src/fe_utils/string_utils.c
*
* Function not publicly available before PostgreSQL 9.6.
*/
void
appendShellString(PQExpBuffer buf, const char *str)
{
const char *p;
appendPQExpBufferChar(buf, '\'');
for (p = str; *p; p++)
{
if (*p == '\n' || *p == '\r')
{
fprintf(stderr,
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
str);
exit(ERR_BAD_CONFIG);
}
if (*p == '\'')
appendPQExpBufferStr(buf, "'\"'\"'");
else
appendPQExpBufferChar(buf, *p);
}
appendPQExpBufferChar(buf, '\'');
}
#endif

View File

@@ -1,5 +1,5 @@
/*
* escape.h
* compat.h
* Copyright (c) 2ndQuadrant, 2010-2016
*
* This program is free software: you can redistribute it and/or modify
@@ -17,10 +17,13 @@
*
*/
#ifndef _ESCAPE_H_
#define _ESCAPE_H_
#ifndef _COMPAT_H_
#define _COMPAT_H_
extern void
appendConnStrVal(PQExpBuffer buf, const char *str);
extern void
appendShellString(PQExpBuffer buf, const char *str);
#endif

View File

@@ -64,7 +64,7 @@
#include "version.h"
#if (PG_VERSION_NUM < 90600)
#include "escape.h"
#include "compat.h"
#else
#include "fe_utils/string_utils.h"
#include "postgres_fe.h"

View File

@@ -89,37 +89,6 @@ maxlen_snprintf(char *str, const char *format,...)
}
/*
* Adapted from: src/fe_utils/string_utils.c
*
* Function not publicly available before PostgreSQL 9.6.
*/
void
appendShellString(PQExpBuffer buf, const char *str)
{
const char *p;
appendPQExpBufferChar(buf, '\'');
for (p = str; *p; p++)
{
if (*p == '\n' || *p == '\r')
{
fprintf(stderr,
_("shell command argument contains a newline or carriage return: \"%s\"\n"),
str);
exit(ERR_BAD_CONFIG);
}
if (*p == '\'')
appendPQExpBufferStr(buf, "'\"'\"'");
else
appendPQExpBufferChar(buf, *p);
}
appendPQExpBufferChar(buf, '\'');
}
/*
* Escape a string for use as a parameter in recovery.conf
* Caller must free returned value

View File

@@ -49,9 +49,6 @@ extern int
maxlen_snprintf(char *str, const char *format,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
extern void
appendShellString(PQExpBuffer buf, const char *str);
extern char *
escape_recovery_conf_value(const char *src);
#endif /* _STRUTIL_H_ */