Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit be2e329

Browse files
committed
isolationtester: Use atexit()
Replace exit_nicely() calls with standard exit() and register the cleanup actions using atexit(). Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/ec4135ba-84e9-28bf-b584-0e78d47448d5@2ndquadrant.com/
1 parent 3913a40 commit be2e329

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/test/isolation/isolationtester.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ static int nconns = 0;
3232
/* In dry run only output permutations to be run by the tester. */
3333
static int dry_run = false;
3434

35-
static void exit_nicely(void) pg_attribute_noreturn();
3635
static void run_testspec(TestSpec *testspec);
3736
static void run_all_permutations(TestSpec *testspec);
3837
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
@@ -51,15 +50,14 @@ static void printResultSet(PGresult *res);
5150
static void isotesterNoticeProcessor(void *arg, const char *message);
5251
static void blackholeNoticeProcessor(void *arg, const char *message);
5352

54-
/* close all connections and exit */
5553
static void
56-
exit_nicely(void)
54+
disconnect_atexit(void)
5755
{
5856
int i;
5957

6058
for (i = 0; i < nconns; i++)
61-
PQfinish(conns[i]);
62-
exit(1);
59+
if (conns[i])
60+
PQfinish(conns[i]);
6361
}
6462

6563
int
@@ -140,7 +138,7 @@ main(int argc, char **argv)
140138
{
141139
fprintf(stderr, "duplicate step name: %s\n",
142140
testspec->allsteps[i]->name);
143-
exit_nicely();
141+
exit(1);
144142
}
145143
}
146144

@@ -162,6 +160,7 @@ main(int argc, char **argv)
162160
*/
163161
nconns = 1 + testspec->nsessions;
164162
conns = calloc(nconns, sizeof(PGconn *));
163+
atexit(disconnect_atexit);
165164
backend_pids = calloc(nconns, sizeof(*backend_pids));
166165
for (i = 0; i < nconns; i++)
167166
{
@@ -170,7 +169,7 @@ main(int argc, char **argv)
170169
{
171170
fprintf(stderr, "Connection %d to database failed: %s",
172171
i, PQerrorMessage(conns[i]));
173-
exit_nicely();
172+
exit(1);
174173
}
175174

176175
/*
@@ -196,7 +195,7 @@ main(int argc, char **argv)
196195
if (PQresultStatus(res) != PGRES_COMMAND_OK)
197196
{
198197
fprintf(stderr, "message level setup failed: %s", PQerrorMessage(conns[i]));
199-
exit_nicely();
198+
exit(1);
200199
}
201200
PQclear(res);
202201

@@ -210,14 +209,14 @@ main(int argc, char **argv)
210209
{
211210
fprintf(stderr, "backend pid query returned %d rows and %d columns, expected 1 row and 1 column",
212211
PQntuples(res), PQnfields(res));
213-
exit_nicely();
212+
exit(1);
214213
}
215214
}
216215
else
217216
{
218217
fprintf(stderr, "backend pid query failed: %s",
219218
PQerrorMessage(conns[i]));
220-
exit_nicely();
219+
exit(1);
221220
}
222221
PQclear(res);
223222
}
@@ -254,7 +253,7 @@ main(int argc, char **argv)
254253
{
255254
fprintf(stderr, "prepare of lock wait query failed: %s",
256255
PQerrorMessage(conns[0]));
257-
exit_nicely();
256+
exit(1);
258257
}
259258
PQclear(res);
260259
termPQExpBuffer(&wait_query);
@@ -265,9 +264,6 @@ main(int argc, char **argv)
265264
*/
266265
run_testspec(testspec);
267266

268-
/* Clean up and exit */
269-
for (i = 0; i < nconns; i++)
270-
PQfinish(conns[i]);
271267
return 0;
272268
}
273269

@@ -375,7 +371,7 @@ run_named_permutations(TestSpec *testspec)
375371
{
376372
fprintf(stderr, "undefined step \"%s\" specified in permutation\n",
377373
p->stepnames[j]);
378-
exit_nicely();
374+
exit(1);
379375
}
380376
steps[j] = *this;
381377
}
@@ -510,7 +506,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
510506
else if (PQresultStatus(res) != PGRES_COMMAND_OK)
511507
{
512508
fprintf(stderr, "setup failed: %s", PQerrorMessage(conns[0]));
513-
exit_nicely();
509+
exit(1);
514510
}
515511
PQclear(res);
516512
}
@@ -530,7 +526,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
530526
fprintf(stderr, "setup of session %s failed: %s",
531527
testspec->sessions[i]->name,
532528
PQerrorMessage(conns[i + 1]));
533-
exit_nicely();
529+
exit(1);
534530
}
535531
PQclear(res);
536532
}
@@ -612,7 +608,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
612608
{
613609
fprintf(stdout, "failed to send query for step %s: %s\n",
614610
step->name, PQerrorMessage(conn));
615-
exit_nicely();
611+
exit(1);
616612
}
617613

618614
/* Try to complete this step without blocking. */
@@ -723,7 +719,7 @@ try_complete_step(Step *step, int flags)
723719
if (sock < 0)
724720
{
725721
fprintf(stderr, "invalid socket: %s", PQerrorMessage(conn));
726-
exit_nicely();
722+
exit(1);
727723
}
728724

729725
gettimeofday(&start_time, NULL);
@@ -741,7 +737,7 @@ try_complete_step(Step *step, int flags)
741737
if (errno == EINTR)
742738
continue;
743739
fprintf(stderr, "select failed: %s\n", strerror(errno));
744-
exit_nicely();
740+
exit(1);
745741
}
746742
else if (ret == 0) /* select() timeout: check for lock wait */
747743
{
@@ -761,7 +757,7 @@ try_complete_step(Step *step, int flags)
761757
{
762758
fprintf(stderr, "lock wait query failed: %s",
763759
PQerrorMessage(conns[0]));
764-
exit_nicely();
760+
exit(1);
765761
}
766762
waiting = ((PQgetvalue(res, 0, 0))[0] == 't');
767763
PQclear(res);
@@ -818,14 +814,14 @@ try_complete_step(Step *step, int flags)
818814
{
819815
fprintf(stderr, "step %s timed out after 200 seconds\n",
820816
step->name);
821-
exit_nicely();
817+
exit(1);
822818
}
823819
}
824820
else if (!PQconsumeInput(conn)) /* select(): data available */
825821
{
826822
fprintf(stderr, "PQconsumeInput failed: %s\n",
827823
PQerrorMessage(conn));
828-
exit_nicely();
824+
exit(1);
829825
}
830826
}
831827

0 commit comments

Comments
 (0)