Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite70abd6

Browse files
committed
Use extensible buffers to assemble command lines
This makes use of StringInfo to assemble command lines, instead ofusing fixed-size buffers and the (remote) possibility of "command toolong" errors. Also makes the code a bit simpler.This covers the test driver programs pg_regress andpg_isolation_regress.Similar to the changes done for pg_rewind ina33e17f.Discussion:https://www.postgresql.org/message-id/2be4fee5-738f-4749-b9f8-b452032c7ade%40eisentraut.org
1 parent4697454 commite70abd6

File tree

2 files changed

+30
-48
lines changed

2 files changed

+30
-48
lines changed

‎src/test/isolation/isolation_main.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include"postgres_fe.h"
1414

15+
#include"lib/stringinfo.h"
1516
#include"pg_regress.h"
1617

1718
charsaved_argv0[MAXPGPATH];
@@ -34,8 +35,7 @@ isolation_start_test(const char *testname,
3435
charinfile[MAXPGPATH];
3536
charoutfile[MAXPGPATH];
3637
charexpectfile[MAXPGPATH];
37-
charpsql_cmd[MAXPGPATH*3];
38-
size_toffset=0;
38+
StringInfoDatapsql_cmd;
3939
char*appnameenv;
4040

4141
/* need to do the path lookup here, check isolation_init() for details */
@@ -75,34 +75,23 @@ isolation_start_test(const char *testname,
7575
add_stringlist_item(resultfiles,outfile);
7676
add_stringlist_item(expectfiles,expectfile);
7777

78+
initStringInfo(&psql_cmd);
79+
7880
if (launcher)
79-
{
80-
offset+=snprintf(psql_cmd+offset,sizeof(psql_cmd)-offset,
81-
"%s ",launcher);
82-
if (offset >=sizeof(psql_cmd))
83-
{
84-
fprintf(stderr,_("command too long\n"));
85-
exit(2);
86-
}
87-
}
81+
appendStringInfo(&psql_cmd,"%s ",launcher);
8882

89-
offset+=snprintf(psql_cmd+offset,sizeof(psql_cmd)-offset,
90-
"\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1",
91-
isolation_exec,
92-
dblist->str,
93-
infile,
94-
outfile);
95-
if (offset >=sizeof(psql_cmd))
96-
{
97-
fprintf(stderr,_("command too long\n"));
98-
exit(2);
99-
}
83+
appendStringInfo(&psql_cmd,
84+
"\"%s\" \"dbname=%s\" < \"%s\" > \"%s\" 2>&1",
85+
isolation_exec,
86+
dblist->str,
87+
infile,
88+
outfile);
10089

10190
appnameenv=psprintf("isolation/%s",testname);
10291
setenv("PGAPPNAME",appnameenv,1);
10392
free(appnameenv);
10493

105-
pid=spawn_process(psql_cmd);
94+
pid=spawn_process(psql_cmd.data);
10695

10796
if (pid==INVALID_PID)
10897
{
@@ -113,6 +102,8 @@ isolation_start_test(const char *testname,
113102

114103
unsetenv("PGAPPNAME");
115104

105+
pfree(psql_cmd.data);
106+
116107
returnpid;
117108
}
118109

‎src/test/regress/pg_regress_main.c

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include"postgres_fe.h"
2020

21+
#include"lib/stringinfo.h"
2122
#include"pg_regress.h"
2223

2324
/*
@@ -34,8 +35,7 @@ psql_start_test(const char *testname,
3435
charinfile[MAXPGPATH];
3536
charoutfile[MAXPGPATH];
3637
charexpectfile[MAXPGPATH];
37-
charpsql_cmd[MAXPGPATH*3];
38-
size_toffset=0;
38+
StringInfoDatapsql_cmd;
3939
char*appnameenv;
4040

4141
/*
@@ -62,40 +62,29 @@ psql_start_test(const char *testname,
6262
add_stringlist_item(resultfiles,outfile);
6363
add_stringlist_item(expectfiles,expectfile);
6464

65+
initStringInfo(&psql_cmd);
66+
6567
if (launcher)
66-
{
67-
offset+=snprintf(psql_cmd+offset,sizeof(psql_cmd)-offset,
68-
"%s ",launcher);
69-
if (offset >=sizeof(psql_cmd))
70-
{
71-
fprintf(stderr,_("command too long\n"));
72-
exit(2);
73-
}
74-
}
68+
appendStringInfo(&psql_cmd,"%s ",launcher);
7569

7670
/*
7771
* Use HIDE_TABLEAM to hide different AMs to allow to use regression tests
7872
* against different AMs without unnecessary differences.
7973
*/
80-
offset+=snprintf(psql_cmd+offset,sizeof(psql_cmd)-offset,
81-
"\"%s%spsql\" -X -a -q -d \"%s\" %s < \"%s\" > \"%s\" 2>&1",
82-
bindir ?bindir :"",
83-
bindir ?"/" :"",
84-
dblist->str,
85-
"-v HIDE_TABLEAM=on -v HIDE_TOAST_COMPRESSION=on",
86-
infile,
87-
outfile);
88-
if (offset >=sizeof(psql_cmd))
89-
{
90-
fprintf(stderr,_("command too long\n"));
91-
exit(2);
92-
}
74+
appendStringInfo(&psql_cmd,
75+
"\"%s%spsql\" -X -a -q -d \"%s\" %s < \"%s\" > \"%s\" 2>&1",
76+
bindir ?bindir :"",
77+
bindir ?"/" :"",
78+
dblist->str,
79+
"-v HIDE_TABLEAM=on -v HIDE_TOAST_COMPRESSION=on",
80+
infile,
81+
outfile);
9382

9483
appnameenv=psprintf("pg_regress/%s",testname);
9584
setenv("PGAPPNAME",appnameenv,1);
9685
free(appnameenv);
9786

98-
pid=spawn_process(psql_cmd);
87+
pid=spawn_process(psql_cmd.data);
9988

10089
if (pid==INVALID_PID)
10190
{
@@ -106,6 +95,8 @@ psql_start_test(const char *testname,
10695

10796
unsetenv("PGAPPNAME");
10897

98+
pfree(psql_cmd.data);
99+
109100
returnpid;
110101
}
111102

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp