@@ -32,7 +32,6 @@ static int nconns = 0;
32
32
/* In dry run only output permutations to be run by the tester. */
33
33
static int dry_run = false;
34
34
35
- static void exit_nicely (void ) pg_attribute_noreturn ();
36
35
static void run_testspec (TestSpec * testspec );
37
36
static void run_all_permutations (TestSpec * testspec );
38
37
static void run_all_permutations_recurse (TestSpec * testspec , int nsteps ,
@@ -51,15 +50,14 @@ static void printResultSet(PGresult *res);
51
50
static void isotesterNoticeProcessor (void * arg , const char * message );
52
51
static void blackholeNoticeProcessor (void * arg , const char * message );
53
52
54
- /* close all connections and exit */
55
53
static void
56
- exit_nicely (void )
54
+ disconnect_atexit (void )
57
55
{
58
56
int i ;
59
57
60
58
for (i = 0 ; i < nconns ; i ++ )
61
- PQfinish (conns [i ]);
62
- exit ( 1 );
59
+ if (conns [i ])
60
+ PQfinish ( conns [ i ] );
63
61
}
64
62
65
63
int
@@ -140,7 +138,7 @@ main(int argc, char **argv)
140
138
{
141
139
fprintf (stderr , "duplicate step name: %s\n" ,
142
140
testspec -> allsteps [i ]-> name );
143
- exit_nicely ( );
141
+ exit ( 1 );
144
142
}
145
143
}
146
144
@@ -162,6 +160,7 @@ main(int argc, char **argv)
162
160
*/
163
161
nconns = 1 + testspec -> nsessions ;
164
162
conns = calloc (nconns , sizeof (PGconn * ));
163
+ atexit (disconnect_atexit );
165
164
backend_pids = calloc (nconns , sizeof (* backend_pids ));
166
165
for (i = 0 ; i < nconns ; i ++ )
167
166
{
@@ -170,7 +169,7 @@ main(int argc, char **argv)
170
169
{
171
170
fprintf (stderr , "Connection %d to database failed: %s" ,
172
171
i , PQerrorMessage (conns [i ]));
173
- exit_nicely ( );
172
+ exit ( 1 );
174
173
}
175
174
176
175
/*
@@ -196,7 +195,7 @@ main(int argc, char **argv)
196
195
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
197
196
{
198
197
fprintf (stderr , "message level setup failed: %s" , PQerrorMessage (conns [i ]));
199
- exit_nicely ( );
198
+ exit ( 1 );
200
199
}
201
200
PQclear (res );
202
201
@@ -210,14 +209,14 @@ main(int argc, char **argv)
210
209
{
211
210
fprintf (stderr , "backend pid query returned %d rows and %d columns, expected 1 row and 1 column" ,
212
211
PQntuples (res ), PQnfields (res ));
213
- exit_nicely ( );
212
+ exit ( 1 );
214
213
}
215
214
}
216
215
else
217
216
{
218
217
fprintf (stderr , "backend pid query failed: %s" ,
219
218
PQerrorMessage (conns [i ]));
220
- exit_nicely ( );
219
+ exit ( 1 );
221
220
}
222
221
PQclear (res );
223
222
}
@@ -254,7 +253,7 @@ main(int argc, char **argv)
254
253
{
255
254
fprintf (stderr , "prepare of lock wait query failed: %s" ,
256
255
PQerrorMessage (conns [0 ]));
257
- exit_nicely ( );
256
+ exit ( 1 );
258
257
}
259
258
PQclear (res );
260
259
termPQExpBuffer (& wait_query );
@@ -265,9 +264,6 @@ main(int argc, char **argv)
265
264
*/
266
265
run_testspec (testspec );
267
266
268
- /* Clean up and exit */
269
- for (i = 0 ; i < nconns ; i ++ )
270
- PQfinish (conns [i ]);
271
267
return 0 ;
272
268
}
273
269
@@ -375,7 +371,7 @@ run_named_permutations(TestSpec *testspec)
375
371
{
376
372
fprintf (stderr , "undefined step \"%s\" specified in permutation\n" ,
377
373
p -> stepnames [j ]);
378
- exit_nicely ( );
374
+ exit ( 1 );
379
375
}
380
376
steps [j ] = * this ;
381
377
}
@@ -510,7 +506,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
510
506
else if (PQresultStatus (res ) != PGRES_COMMAND_OK )
511
507
{
512
508
fprintf (stderr , "setup failed: %s" , PQerrorMessage (conns [0 ]));
513
- exit_nicely ( );
509
+ exit ( 1 );
514
510
}
515
511
PQclear (res );
516
512
}
@@ -530,7 +526,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
530
526
fprintf (stderr , "setup of session %s failed: %s" ,
531
527
testspec -> sessions [i ]-> name ,
532
528
PQerrorMessage (conns [i + 1 ]));
533
- exit_nicely ( );
529
+ exit ( 1 );
534
530
}
535
531
PQclear (res );
536
532
}
@@ -612,7 +608,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
612
608
{
613
609
fprintf (stdout , "failed to send query for step %s: %s\n" ,
614
610
step -> name , PQerrorMessage (conn ));
615
- exit_nicely ( );
611
+ exit ( 1 );
616
612
}
617
613
618
614
/* Try to complete this step without blocking. */
@@ -723,7 +719,7 @@ try_complete_step(Step *step, int flags)
723
719
if (sock < 0 )
724
720
{
725
721
fprintf (stderr , "invalid socket: %s" , PQerrorMessage (conn ));
726
- exit_nicely ( );
722
+ exit ( 1 );
727
723
}
728
724
729
725
gettimeofday (& start_time , NULL );
@@ -741,7 +737,7 @@ try_complete_step(Step *step, int flags)
741
737
if (errno == EINTR )
742
738
continue ;
743
739
fprintf (stderr , "select failed: %s\n" , strerror (errno ));
744
- exit_nicely ( );
740
+ exit ( 1 );
745
741
}
746
742
else if (ret == 0 ) /* select() timeout: check for lock wait */
747
743
{
@@ -761,7 +757,7 @@ try_complete_step(Step *step, int flags)
761
757
{
762
758
fprintf (stderr , "lock wait query failed: %s" ,
763
759
PQerrorMessage (conns [0 ]));
764
- exit_nicely ( );
760
+ exit ( 1 );
765
761
}
766
762
waiting = ((PQgetvalue (res , 0 , 0 ))[0 ] == 't' );
767
763
PQclear (res );
@@ -818,14 +814,14 @@ try_complete_step(Step *step, int flags)
818
814
{
819
815
fprintf (stderr , "step %s timed out after 200 seconds\n" ,
820
816
step -> name );
821
- exit_nicely ( );
817
+ exit ( 1 );
822
818
}
823
819
}
824
820
else if (!PQconsumeInput (conn )) /* select(): data available */
825
821
{
826
822
fprintf (stderr , "PQconsumeInput failed: %s\n" ,
827
823
PQerrorMessage (conn ));
828
- exit_nicely ( );
824
+ exit ( 1 );
829
825
}
830
826
}
831
827
0 commit comments