diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2024-02-11 09:08:35 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2024-02-11 09:27:48 +0100 |
commit | e70abd67c3e6155fe8e853c4e29255578d9cf48d (patch) | |
tree | 9811c1dbcf4e8e5a9967dbdacf738adf95e3ec4f /src/test/isolation/isolation_main.c | |
parent | 469745468668917434dbef48eddad4f961880b3d (diff) | |
download | postgresql-e70abd67c3e6155fe8e853c4e29255578d9cf48d.tar.gz postgresql-e70abd67c3e6155fe8e853c4e29255578d9cf48d.zip |
Use extensible buffers to assemble command lines
This makes use of StringInfo to assemble command lines, instead of
using fixed-size buffers and the (remote) possibility of "command too
long" errors. Also makes the code a bit simpler.
This covers the test driver programs pg_regress and
pg_isolation_regress.
Similar to the changes done for pg_rewind in a33e17f210.
Discussion: https://www.postgresql.org/message-id/2be4fee5-738f-4749-b9f8-b452032c7ade%40eisentraut.org
Diffstat (limited to 'src/test/isolation/isolation_main.c')
-rw-r--r-- | src/test/isolation/isolation_main.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/test/isolation/isolation_main.c b/src/test/isolation/isolation_main.c index 05e81035c1f..2a3e41d2101 100644 --- a/src/test/isolation/isolation_main.c +++ b/src/test/isolation/isolation_main.c @@ -12,6 +12,7 @@ #include "postgres_fe.h" +#include "lib/stringinfo.h" #include "pg_regress.h" char saved_argv0[MAXPGPATH]; @@ -34,8 +35,7 @@ isolation_start_test(const char *testname, char infile[MAXPGPATH]; char outfile[MAXPGPATH]; char expectfile[MAXPGPATH]; - char psql_cmd[MAXPGPATH * 3]; - size_t offset = 0; + StringInfoData psql_cmd; char *appnameenv; /* need to do the path lookup here, check isolation_init() for details */ @@ -75,34 +75,23 @@ isolation_start_test(const char *testname, add_stringlist_item(resultfiles, outfile); add_stringlist_item(expectfiles, expectfile); + initStringInfo(&psql_cmd); + if (launcher) - { - offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset, - "%s ", launcher); - if (offset >= sizeof(psql_cmd)) - { - fprintf(stderr, _("command too long\n")); - exit(2); - } - } + appendStringInfo(&psql_cmd, "%s ", launcher); - offset += snprintf(psql_cmd + offset, sizeof(psql_cmd) - offset, - "\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1", - isolation_exec, - dblist->str, - infile, - outfile); - if (offset >= sizeof(psql_cmd)) - { - fprintf(stderr, _("command too long\n")); - exit(2); - } + appendStringInfo(&psql_cmd, + "\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1", + isolation_exec, + dblist->str, + infile, + outfile); appnameenv = psprintf("isolation/%s", testname); setenv("PGAPPNAME", appnameenv, 1); free(appnameenv); - pid = spawn_process(psql_cmd); + pid = spawn_process(psql_cmd.data); if (pid == INVALID_PID) { @@ -113,6 +102,8 @@ isolation_start_test(const char *testname, unsetenv("PGAPPNAME"); + pfree(psql_cmd.data); + return pid; } |