@@ -32,7 +32,6 @@ static intnconns = 0;
3232/* In dry run only output permutations to be run by the tester. */
3333static int dry_run = false;
3434
35- static void exit_nicely (void )pg_attribute_noreturn ();
3635static void run_testspec (TestSpec * testspec );
3736static void run_all_permutations (TestSpec * testspec );
3837static void run_all_permutations_recurse (TestSpec * testspec ,int nsteps ,
@@ -51,15 +50,14 @@ static void printResultSet(PGresult *res);
5150static void isotesterNoticeProcessor (void * arg ,const char * message );
5251static void blackholeNoticeProcessor (void * arg ,const char * message );
5352
54- /* close all connections and exit */
5553static void
56- exit_nicely (void )
54+ disconnect_atexit (void )
5755{
5856int i ;
5957
6058for (i = 0 ;i < nconns ;i ++ )
61- PQfinish (conns [i ]);
62- exit ( 1 );
59+ if (conns [i ])
60+ PQfinish ( conns [ i ] );
6361}
6462
6563int
@@ -140,7 +138,7 @@ main(int argc, char **argv)
140138{
141139fprintf (stderr ,"duplicate step name: %s\n" ,
142140testspec -> allsteps [i ]-> name );
143- exit_nicely ( );
141+ exit ( 1 );
144142}
145143}
146144
@@ -162,6 +160,7 @@ main(int argc, char **argv)
162160 */
163161nconns = 1 + testspec -> nsessions ;
164162conns = calloc (nconns ,sizeof (PGconn * ));
163+ atexit (disconnect_atexit );
165164backend_pids = calloc (nconns ,sizeof (* backend_pids ));
166165for (i = 0 ;i < nconns ;i ++ )
167166{
@@ -170,7 +169,7 @@ main(int argc, char **argv)
170169{
171170fprintf (stderr ,"Connection %d to database failed: %s" ,
172171i ,PQerrorMessage (conns [i ]));
173- exit_nicely ( );
172+ exit ( 1 );
174173}
175174
176175/*
@@ -196,7 +195,7 @@ main(int argc, char **argv)
196195if (PQresultStatus (res )!= PGRES_COMMAND_OK )
197196{
198197fprintf (stderr ,"message level setup failed: %s" ,PQerrorMessage (conns [i ]));
199- exit_nicely ( );
198+ exit ( 1 );
200199}
201200PQclear (res );
202201
@@ -210,14 +209,14 @@ main(int argc, char **argv)
210209{
211210fprintf (stderr ,"backend pid query returned %d rows and %d columns, expected 1 row and 1 column" ,
212211PQntuples (res ),PQnfields (res ));
213- exit_nicely ( );
212+ exit ( 1 );
214213}
215214}
216215else
217216{
218217fprintf (stderr ,"backend pid query failed: %s" ,
219218PQerrorMessage (conns [i ]));
220- exit_nicely ( );
219+ exit ( 1 );
221220}
222221PQclear (res );
223222}
@@ -254,7 +253,7 @@ main(int argc, char **argv)
254253{
255254fprintf (stderr ,"prepare of lock wait query failed: %s" ,
256255PQerrorMessage (conns [0 ]));
257- exit_nicely ( );
256+ exit ( 1 );
258257}
259258PQclear (res );
260259termPQExpBuffer (& wait_query );
@@ -265,9 +264,6 @@ main(int argc, char **argv)
265264 */
266265run_testspec (testspec );
267266
268- /* Clean up and exit */
269- for (i = 0 ;i < nconns ;i ++ )
270- PQfinish (conns [i ]);
271267return 0 ;
272268}
273269
@@ -375,7 +371,7 @@ run_named_permutations(TestSpec *testspec)
375371{
376372fprintf (stderr ,"undefined step \"%s\" specified in permutation\n" ,
377373p -> stepnames [j ]);
378- exit_nicely ( );
374+ exit ( 1 );
379375}
380376steps [j ]= * this ;
381377}
@@ -510,7 +506,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
510506else if (PQresultStatus (res )!= PGRES_COMMAND_OK )
511507{
512508fprintf (stderr ,"setup failed: %s" ,PQerrorMessage (conns [0 ]));
513- exit_nicely ( );
509+ exit ( 1 );
514510}
515511PQclear (res );
516512}
@@ -530,7 +526,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
530526fprintf (stderr ,"setup of session %s failed: %s" ,
531527testspec -> sessions [i ]-> name ,
532528PQerrorMessage (conns [i + 1 ]));
533- exit_nicely ( );
529+ exit ( 1 );
534530}
535531PQclear (res );
536532}
@@ -612,7 +608,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
612608{
613609fprintf (stdout ,"failed to send query for step %s: %s\n" ,
614610step -> 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)
723719if (sock < 0 )
724720{
725721fprintf (stderr ,"invalid socket: %s" ,PQerrorMessage (conn ));
726- exit_nicely ( );
722+ exit ( 1 );
727723}
728724
729725gettimeofday (& start_time ,NULL );
@@ -741,7 +737,7 @@ try_complete_step(Step *step, int flags)
741737if (errno == EINTR )
742738continue ;
743739fprintf (stderr ,"select failed: %s\n" ,strerror (errno ));
744- exit_nicely ( );
740+ exit ( 1 );
745741}
746742else if (ret == 0 )/* select() timeout: check for lock wait */
747743{
@@ -761,7 +757,7 @@ try_complete_step(Step *step, int flags)
761757{
762758fprintf (stderr ,"lock wait query failed: %s" ,
763759PQerrorMessage (conns [0 ]));
764- exit_nicely ( );
760+ exit ( 1 );
765761}
766762waiting = ((PQgetvalue (res ,0 ,0 ))[0 ]== 't' );
767763PQclear (res );
@@ -818,14 +814,14 @@ try_complete_step(Step *step, int flags)
818814{
819815fprintf (stderr ,"step %s timed out after 200 seconds\n" ,
820816step -> name );
821- exit_nicely ( );
817+ exit ( 1 );
822818}
823819}
824820else if (!PQconsumeInput (conn ))/* select(): data available */
825821{
826822fprintf (stderr ,"PQconsumeInput failed: %s\n" ,
827823PQerrorMessage (conn ));
828- exit_nicely ( );
824+ exit ( 1 );
829825}
830826}
831827