From fa77fb314ddac3d047ec34809479f506a172c56c Mon Sep 17 00:00:00 2001 From: David Christensen Date: Sun, 28 Mar 2010 23:54:09 -0500 Subject: [PATCH] Add -C option to initdb to allow invocation-time GUC appending to postgresql.conf This is a simple mechanism to allow you to provide explicit overrides to any GUC at initdb time. As a basic example, consider the case where you are programmatically generating multiple db clusters in order to test various configurations: $ for cluster in 1 2 3 4 5 6; > do initdb -D data$cluster -C "port = 1234$cluster" -C 'max_connections = 10' -C shared_buffers=1M; > done A possible future improvement would be to provide some basic formatting corrections to allow specificications such as -C 'port 1234', -C port=1234, and -C 'port = 1234' to all be ultimately output as 'port = 1234' in the final output. This would be consistent with postmaster's parsing. The -C flag was chosen to be a mnemonic for "config". --- src/bin/initdb/initdb.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 108 insertions(+), 1 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index f40ad87..4855f99 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -111,6 +111,7 @@ static char infoversion[100]; static bool caught_signal = false; static bool output_failed = false; static int output_errno = 0; +static char **append_config_buffer; /* defaults */ static int n_connections = 10; @@ -271,6 +272,27 @@ xstrdup(const char *s) return result; } +/* like xstrdup, but appends a newline to the duplicated string*/ +static char * +xstrdupln(const char *s) +{ + char *result; + int len = strlen(s); + + result = (char*)malloc(len+2); + if (!result) + { + fprintf(stderr, _("%s: out of memory\n"), progname); + exit(1); + } + memcpy(result,s,len); + + result[len] = '\n'; + result[len+1] = 0; + + return result; +} + /* * make a copy of the array of lines, with token replaced by replacement * the first time it occurs on each line. @@ -417,6 +439,79 @@ readfile(const char *path) } /* + * return a char** created by appending the source** with the dest** + * + * adds newlines to the end of any line which are missing one. + */ +static char ** +append_lines(char **src, char **lines) +{ + char **buf; + int i; + int src_lines = 0; + int app_lines = 0; + + for (i=0; src[i]; i++) + src_lines++; + for (i=0; lines[i]; i++) + app_lines++; + + buf = (char**) pg_malloc((src_lines + app_lines + 1) * (sizeof(char *))); + + memcpy(buf,src,(sizeof(char *))*src_lines); + + for (i=0; i