@@ -159,6 +159,7 @@ static char *dictionary_file;
159
159
static char * info_schema_file ;
160
160
static char * features_file ;
161
161
static char * system_views_file ;
162
+ static bool success = false;
162
163
static bool made_new_pgdata = false;
163
164
static bool found_existing_pgdata = false;
164
165
static bool made_new_xlogdir = false;
@@ -237,7 +238,6 @@ static char **filter_lines_with_token(char **lines, const char *token);
237
238
static char * * readfile (const char * path );
238
239
static void writefile (char * path , char * * lines );
239
240
static FILE * popen_check (const char * command , const char * mode );
240
- static void exit_nicely (void ) pg_attribute_noreturn ();
241
241
static char * get_id (void );
242
242
static int get_encoding_id (const char * encoding_name );
243
243
static void set_input (char * * dest , const char * filename );
@@ -291,13 +291,13 @@ void initialize_data_directory(void);
291
291
do { \
292
292
cmdfd = popen_check(cmd, "w"); \
293
293
if (cmdfd == NULL) \
294
- exit_nicely( ); /* message already printed by popen_check */ \
294
+ exit(1 ); /* message already printed by popen_check */ \
295
295
} while (0 )
296
296
297
297
#define PG_CMD_CLOSE \
298
298
do { \
299
299
if (pclose_check(cmdfd)) \
300
- exit_nicely( ); /* message already printed by pclose_check */ \
300
+ exit(1 ); /* message already printed by pclose_check */ \
301
301
} while (0 )
302
302
303
303
#define PG_CMD_PUTS (line ) \
@@ -493,7 +493,7 @@ readfile(const char *path)
493
493
{
494
494
fprintf (stderr , _ ("%s: could not open file \"%s\" for reading: %s\n" ),
495
495
progname , path , strerror (errno ));
496
- exit_nicely ( );
496
+ exit ( 1 );
497
497
}
498
498
499
499
/* pass over the file twice - the first time to size the result */
@@ -549,23 +549,23 @@ writefile(char *path, char **lines)
549
549
{
550
550
fprintf (stderr , _ ("%s: could not open file \"%s\" for writing: %s\n" ),
551
551
progname , path , strerror (errno ));
552
- exit_nicely ( );
552
+ exit ( 1 );
553
553
}
554
554
for (line = lines ; * line != NULL ; line ++ )
555
555
{
556
556
if (fputs (* line , out_file ) < 0 )
557
557
{
558
558
fprintf (stderr , _ ("%s: could not write file \"%s\": %s\n" ),
559
559
progname , path , strerror (errno ));
560
- exit_nicely ( );
560
+ exit ( 1 );
561
561
}
562
562
free (* line );
563
563
}
564
564
if (fclose (out_file ))
565
565
{
566
566
fprintf (stderr , _ ("%s: could not write file \"%s\": %s\n" ),
567
567
progname , path , strerror (errno ));
568
- exit_nicely ( );
568
+ exit ( 1 );
569
569
}
570
570
}
571
571
@@ -592,8 +592,11 @@ popen_check(const char *command, const char *mode)
592
592
* if we created the data directory remove it too
593
593
*/
594
594
static void
595
- exit_nicely (void )
595
+ cleanup_directories_atexit (void )
596
596
{
597
+ if (success )
598
+ return ;
599
+
597
600
if (!noclean )
598
601
{
599
602
if (made_new_pgdata )
@@ -645,8 +648,6 @@ exit_nicely(void)
645
648
_ ("%s: WAL directory \"%s\" not removed at user's request\n" ),
646
649
progname , xlog_dir );
647
650
}
648
-
649
- exit (1 );
650
651
}
651
652
652
653
/*
@@ -877,14 +878,14 @@ write_version_file(const char *extrapath)
877
878
{
878
879
fprintf (stderr , _ ("%s: could not open file \"%s\" for writing: %s\n" ),
879
880
progname , path , strerror (errno ));
880
- exit_nicely ( );
881
+ exit ( 1 );
881
882
}
882
883
if (fprintf (version_file , "%s\n" , PG_MAJORVERSION ) < 0 ||
883
884
fclose (version_file ))
884
885
{
885
886
fprintf (stderr , _ ("%s: could not write file \"%s\": %s\n" ),
886
887
progname , path , strerror (errno ));
887
- exit_nicely ( );
888
+ exit ( 1 );
888
889
}
889
890
free (path );
890
891
}
@@ -905,13 +906,13 @@ set_null_conf(void)
905
906
{
906
907
fprintf (stderr , _ ("%s: could not open file \"%s\" for writing: %s\n" ),
907
908
progname , path , strerror (errno ));
908
- exit_nicely ( );
909
+ exit ( 1 );
909
910
}
910
911
if (fclose (conf_file ))
911
912
{
912
913
fprintf (stderr , _ ("%s: could not write file \"%s\": %s\n" ),
913
914
progname , path , strerror (errno ));
914
- exit_nicely ( );
915
+ exit ( 1 );
915
916
}
916
917
free (path );
917
918
}
@@ -1262,7 +1263,7 @@ setup_config(void)
1262
1263
{
1263
1264
fprintf (stderr , _ ("%s: could not change permissions of \"%s\": %s\n" ),
1264
1265
progname , path , strerror (errno ));
1265
- exit_nicely ( );
1266
+ exit ( 1 );
1266
1267
}
1267
1268
1268
1269
/*
@@ -1282,7 +1283,7 @@ setup_config(void)
1282
1283
{
1283
1284
fprintf (stderr , _ ("%s: could not change permissions of \"%s\": %s\n" ),
1284
1285
progname , path , strerror (errno ));
1285
- exit_nicely ( );
1286
+ exit ( 1 );
1286
1287
}
1287
1288
1288
1289
free (conflines );
@@ -1369,7 +1370,7 @@ setup_config(void)
1369
1370
{
1370
1371
fprintf (stderr , _ ("%s: could not change permissions of \"%s\": %s\n" ),
1371
1372
progname , path , strerror (errno ));
1372
- exit_nicely ( );
1373
+ exit ( 1 );
1373
1374
}
1374
1375
1375
1376
free (conflines );
@@ -1385,7 +1386,7 @@ setup_config(void)
1385
1386
{
1386
1387
fprintf (stderr , _ ("%s: could not change permissions of \"%s\": %s\n" ),
1387
1388
progname , path , strerror (errno ));
1388
- exit_nicely ( );
1389
+ exit ( 1 );
1389
1390
}
1390
1391
1391
1392
free (conflines );
@@ -1423,7 +1424,7 @@ bootstrap_template1(void)
1423
1424
"Check your installation or specify the correct path "
1424
1425
"using the option -L.\n" ),
1425
1426
progname , bki_file , PG_VERSION );
1426
- exit_nicely ( );
1427
+ exit ( 1 );
1427
1428
}
1428
1429
1429
1430
/* Substitute for various symbols used in the BKI file */
@@ -1541,7 +1542,7 @@ get_su_pwd(void)
1541
1542
if (strcmp (pwd1 , pwd2 ) != 0 )
1542
1543
{
1543
1544
fprintf (stderr , _ ("Passwords didn't match.\n" ));
1544
- exit_nicely ( );
1545
+ exit ( 1 );
1545
1546
}
1546
1547
}
1547
1548
else
@@ -1561,7 +1562,7 @@ get_su_pwd(void)
1561
1562
{
1562
1563
fprintf (stderr , _ ("%s: could not open file \"%s\" for reading: %s\n" ),
1563
1564
progname , pwfilename , strerror (errno ));
1564
- exit_nicely ( );
1565
+ exit ( 1 );
1565
1566
}
1566
1567
if (!fgets (pwd1 , sizeof (pwd1 ), pwf ))
1567
1568
{
@@ -1571,7 +1572,7 @@ get_su_pwd(void)
1571
1572
else
1572
1573
fprintf (stderr , _ ("%s: password file \"%s\" is empty\n" ),
1573
1574
progname , pwfilename );
1574
- exit_nicely ( );
1575
+ exit ( 1 );
1575
1576
}
1576
1577
fclose (pwf );
1577
1578
@@ -2104,7 +2105,7 @@ make_postgres(FILE *cmdfd)
2104
2105
* if you are handling SIGFPE.
2105
2106
*
2106
2107
* I avoided doing the forbidden things by setting a flag instead of calling
2107
- * exit_nicely () directly.
2108
+ * exit () directly.
2108
2109
*
2109
2110
* Also note the behaviour of Windows with SIGINT, which says this:
2110
2111
* Note SIGINT is not supported for any Win32 application, including
@@ -2125,7 +2126,7 @@ trapsig(int signum)
2125
2126
}
2126
2127
2127
2128
/*
2128
- * call exit_nicely () if we got a signal, or else output "ok".
2129
+ * call exit () if we got a signal, or else output "ok".
2129
2130
*/
2130
2131
static void
2131
2132
check_ok (void )
@@ -2134,14 +2135,14 @@ check_ok(void)
2134
2135
{
2135
2136
printf (_ ("caught signal\n" ));
2136
2137
fflush (stdout );
2137
- exit_nicely ( );
2138
+ exit ( 1 );
2138
2139
}
2139
2140
else if (output_failed )
2140
2141
{
2141
2142
printf (_ ("could not write to child process: %s\n" ),
2142
2143
strerror (output_errno ));
2143
2144
fflush (stdout );
2144
- exit_nicely ( );
2145
+ exit ( 1 );
2145
2146
}
2146
2147
else
2147
2148
{
@@ -2775,7 +2776,7 @@ create_data_directory(void)
2775
2776
{
2776
2777
fprintf (stderr , _ ("%s: could not create directory \"%s\": %s\n" ),
2777
2778
progname , pg_data , strerror (errno ));
2778
- exit_nicely ( );
2779
+ exit ( 1 );
2779
2780
}
2780
2781
else
2781
2782
check_ok ();
@@ -2793,7 +2794,7 @@ create_data_directory(void)
2793
2794
{
2794
2795
fprintf (stderr , _ ("%s: could not change permissions of directory \"%s\": %s\n" ),
2795
2796
progname , pg_data , strerror (errno ));
2796
- exit_nicely ( );
2797
+ exit ( 1 );
2797
2798
}
2798
2799
else
2799
2800
check_ok ();
@@ -2822,7 +2823,7 @@ create_data_directory(void)
2822
2823
/* Trouble accessing directory */
2823
2824
fprintf (stderr , _ ("%s: could not access directory \"%s\": %s\n" ),
2824
2825
progname , pg_data , strerror (errno ));
2825
- exit_nicely ( );
2826
+ exit ( 1 );
2826
2827
}
2827
2828
}
2828
2829
@@ -2845,7 +2846,7 @@ create_xlog_or_symlink(void)
2845
2846
if (!is_absolute_path (xlog_dir ))
2846
2847
{
2847
2848
fprintf (stderr , _ ("%s: WAL directory location must be an absolute path\n" ), progname );
2848
- exit_nicely ( );
2849
+ exit ( 1 );
2849
2850
}
2850
2851
2851
2852
/* check if the specified xlog directory exists/is empty */
@@ -2861,7 +2862,7 @@ create_xlog_or_symlink(void)
2861
2862
{
2862
2863
fprintf (stderr , _ ("%s: could not create directory \"%s\": %s\n" ),
2863
2864
progname , xlog_dir , strerror (errno ));
2864
- exit_nicely ( );
2865
+ exit ( 1 );
2865
2866
}
2866
2867
else
2867
2868
check_ok ();
@@ -2879,7 +2880,7 @@ create_xlog_or_symlink(void)
2879
2880
{
2880
2881
fprintf (stderr , _ ("%s: could not change permissions of directory \"%s\": %s\n" ),
2881
2882
progname , xlog_dir , strerror (errno ));
2882
- exit_nicely ( );
2883
+ exit ( 1 );
2883
2884
}
2884
2885
else
2885
2886
check_ok ();
@@ -2901,25 +2902,25 @@ create_xlog_or_symlink(void)
2901
2902
_ ("If you want to store the WAL there, either remove or empty the directory\n"
2902
2903
"\"%s\".\n" ),
2903
2904
xlog_dir );
2904
- exit_nicely ( );
2905
+ exit ( 1 );
2905
2906
2906
2907
default :
2907
2908
/* Trouble accessing directory */
2908
2909
fprintf (stderr , _ ("%s: could not access directory \"%s\": %s\n" ),
2909
2910
progname , xlog_dir , strerror (errno ));
2910
- exit_nicely ( );
2911
+ exit ( 1 );
2911
2912
}
2912
2913
2913
2914
#ifdef HAVE_SYMLINK
2914
2915
if (symlink (xlog_dir , subdirloc ) != 0 )
2915
2916
{
2916
2917
fprintf (stderr , _ ("%s: could not create symbolic link \"%s\": %s\n" ),
2917
2918
progname , subdirloc , strerror (errno ));
2918
- exit_nicely ( );
2919
+ exit ( 1 );
2919
2920
}
2920
2921
#else
2921
2922
fprintf (stderr , _ ("%s: symlinks are not supported on this platform\n" ), progname );
2922
- exit_nicely ( );
2923
+ exit ( 1 );
2923
2924
#endif
2924
2925
}
2925
2926
else
@@ -2929,7 +2930,7 @@ create_xlog_or_symlink(void)
2929
2930
{
2930
2931
fprintf (stderr , _ ("%s: could not create directory \"%s\": %s\n" ),
2931
2932
progname , subdirloc , strerror (errno ));
2932
- exit_nicely ( );
2933
+ exit ( 1 );
2933
2934
}
2934
2935
}
2935
2936
@@ -2991,7 +2992,7 @@ initialize_data_directory(void)
2991
2992
{
2992
2993
fprintf (stderr , _ ("%s: could not create directory \"%s\": %s\n" ),
2993
2994
progname , path , strerror (errno ));
2994
- exit_nicely ( );
2995
+ exit ( 1 );
2995
2996
}
2996
2997
2997
2998
free (path );
@@ -3266,6 +3267,8 @@ main(int argc, char *argv[])
3266
3267
exit (1 );
3267
3268
}
3268
3269
3270
+ atexit (cleanup_directories_atexit );
3271
+
3269
3272
/* If we only need to fsync, just do it and exit */
3270
3273
if (sync_only )
3271
3274
{
@@ -3276,7 +3279,7 @@ main(int argc, char *argv[])
3276
3279
{
3277
3280
fprintf (stderr , _ ("%s: could not access directory \"%s\": %s\n" ),
3278
3281
progname , pg_data , strerror (errno ));
3279
- exit_nicely ( );
3282
+ exit ( 1 );
3280
3283
}
3281
3284
3282
3285
fputs (_ ("syncing data to disk ... " ), stdout );
@@ -3412,5 +3415,6 @@ main(int argc, char *argv[])
3412
3415
3413
3416
destroyPQExpBuffer (start_db_cmd );
3414
3417
3418
+ success = true;
3415
3419
return 0 ;
3416
3420
}
0 commit comments