@@ -159,6 +159,7 @@ static char *dictionary_file;
159159static char * info_schema_file ;
160160static char * features_file ;
161161static char * system_views_file ;
162+ static bool success = false;
162163static bool made_new_pgdata = false;
163164static bool found_existing_pgdata = false;
164165static bool made_new_xlogdir = false;
@@ -237,7 +238,6 @@ static char **filter_lines_with_token(char **lines, const char *token);
237238static char * * readfile (const char * path );
238239static void writefile (char * path ,char * * lines );
239240static FILE * popen_check (const char * command ,const char * mode );
240- static void exit_nicely (void )pg_attribute_noreturn ();
241241static char * get_id (void );
242242static int get_encoding_id (const char * encoding_name );
243243static void set_input (char * * dest ,const char * filename );
@@ -291,13 +291,13 @@ voidinitialize_data_directory(void);
291291do { \
292292cmdfd = popen_check(cmd, "w"); \
293293if (cmdfd == NULL) \
294- exit_nicely( );/* message already printed by popen_check */ \
294+ exit(1 );/* message already printed by popen_check */ \
295295}while (0 )
296296
297297#define PG_CMD_CLOSE \
298298do { \
299299if (pclose_check(cmdfd)) \
300- exit_nicely( );/* message already printed by pclose_check */ \
300+ exit(1 );/* message already printed by pclose_check */ \
301301}while (0 )
302302
303303#define PG_CMD_PUTS (line ) \
@@ -493,7 +493,7 @@ readfile(const char *path)
493493{
494494fprintf (stderr ,_ ("%s: could not open file \"%s\" for reading: %s\n" ),
495495progname ,path ,strerror (errno ));
496- exit_nicely ( );
496+ exit ( 1 );
497497}
498498
499499/* pass over the file twice - the first time to size the result */
@@ -549,23 +549,23 @@ writefile(char *path, char **lines)
549549{
550550fprintf (stderr ,_ ("%s: could not open file \"%s\" for writing: %s\n" ),
551551progname ,path ,strerror (errno ));
552- exit_nicely ( );
552+ exit ( 1 );
553553}
554554for (line = lines ;* line != NULL ;line ++ )
555555{
556556if (fputs (* line ,out_file )< 0 )
557557{
558558fprintf (stderr ,_ ("%s: could not write file \"%s\": %s\n" ),
559559progname ,path ,strerror (errno ));
560- exit_nicely ( );
560+ exit ( 1 );
561561}
562562free (* line );
563563}
564564if (fclose (out_file ))
565565{
566566fprintf (stderr ,_ ("%s: could not write file \"%s\": %s\n" ),
567567progname ,path ,strerror (errno ));
568- exit_nicely ( );
568+ exit ( 1 );
569569}
570570}
571571
@@ -592,8 +592,11 @@ popen_check(const char *command, const char *mode)
592592 * if we created the data directory remove it too
593593 */
594594static void
595- exit_nicely (void )
595+ cleanup_directories_atexit (void )
596596{
597+ if (success )
598+ return ;
599+
597600if (!noclean )
598601{
599602if (made_new_pgdata )
@@ -645,8 +648,6 @@ exit_nicely(void)
645648_ ("%s: WAL directory \"%s\" not removed at user's request\n" ),
646649progname ,xlog_dir );
647650}
648-
649- exit (1 );
650651}
651652
652653/*
@@ -877,14 +878,14 @@ write_version_file(const char *extrapath)
877878{
878879fprintf (stderr ,_ ("%s: could not open file \"%s\" for writing: %s\n" ),
879880progname ,path ,strerror (errno ));
880- exit_nicely ( );
881+ exit ( 1 );
881882}
882883if (fprintf (version_file ,"%s\n" ,PG_MAJORVERSION )< 0 ||
883884fclose (version_file ))
884885{
885886fprintf (stderr ,_ ("%s: could not write file \"%s\": %s\n" ),
886887progname ,path ,strerror (errno ));
887- exit_nicely ( );
888+ exit ( 1 );
888889}
889890free (path );
890891}
@@ -905,13 +906,13 @@ set_null_conf(void)
905906{
906907fprintf (stderr ,_ ("%s: could not open file \"%s\" for writing: %s\n" ),
907908progname ,path ,strerror (errno ));
908- exit_nicely ( );
909+ exit ( 1 );
909910}
910911if (fclose (conf_file ))
911912{
912913fprintf (stderr ,_ ("%s: could not write file \"%s\": %s\n" ),
913914progname ,path ,strerror (errno ));
914- exit_nicely ( );
915+ exit ( 1 );
915916}
916917free (path );
917918}
@@ -1262,7 +1263,7 @@ setup_config(void)
12621263{
12631264fprintf (stderr ,_ ("%s: could not change permissions of \"%s\": %s\n" ),
12641265progname ,path ,strerror (errno ));
1265- exit_nicely ( );
1266+ exit ( 1 );
12661267}
12671268
12681269/*
@@ -1282,7 +1283,7 @@ setup_config(void)
12821283{
12831284fprintf (stderr ,_ ("%s: could not change permissions of \"%s\": %s\n" ),
12841285progname ,path ,strerror (errno ));
1285- exit_nicely ( );
1286+ exit ( 1 );
12861287}
12871288
12881289free (conflines );
@@ -1369,7 +1370,7 @@ setup_config(void)
13691370{
13701371fprintf (stderr ,_ ("%s: could not change permissions of \"%s\": %s\n" ),
13711372progname ,path ,strerror (errno ));
1372- exit_nicely ( );
1373+ exit ( 1 );
13731374}
13741375
13751376free (conflines );
@@ -1385,7 +1386,7 @@ setup_config(void)
13851386{
13861387fprintf (stderr ,_ ("%s: could not change permissions of \"%s\": %s\n" ),
13871388progname ,path ,strerror (errno ));
1388- exit_nicely ( );
1389+ exit ( 1 );
13891390}
13901391
13911392free (conflines );
@@ -1423,7 +1424,7 @@ bootstrap_template1(void)
14231424"Check your installation or specify the correct path "
14241425"using the option -L.\n" ),
14251426progname ,bki_file ,PG_VERSION );
1426- exit_nicely ( );
1427+ exit ( 1 );
14271428}
14281429
14291430/* Substitute for various symbols used in the BKI file */
@@ -1541,7 +1542,7 @@ get_su_pwd(void)
15411542if (strcmp (pwd1 ,pwd2 )!= 0 )
15421543{
15431544fprintf (stderr ,_ ("Passwords didn't match.\n" ));
1544- exit_nicely ( );
1545+ exit ( 1 );
15451546}
15461547}
15471548else
@@ -1561,7 +1562,7 @@ get_su_pwd(void)
15611562{
15621563fprintf (stderr ,_ ("%s: could not open file \"%s\" for reading: %s\n" ),
15631564progname ,pwfilename ,strerror (errno ));
1564- exit_nicely ( );
1565+ exit ( 1 );
15651566}
15661567if (!fgets (pwd1 ,sizeof (pwd1 ),pwf ))
15671568{
@@ -1571,7 +1572,7 @@ get_su_pwd(void)
15711572else
15721573fprintf (stderr ,_ ("%s: password file \"%s\" is empty\n" ),
15731574progname ,pwfilename );
1574- exit_nicely ( );
1575+ exit ( 1 );
15751576}
15761577fclose (pwf );
15771578
@@ -2104,7 +2105,7 @@ make_postgres(FILE *cmdfd)
21042105 * if you are handling SIGFPE.
21052106 *
21062107 * I avoided doing the forbidden things by setting a flag instead of calling
2107- *exit_nicely () directly.
2108+ *exit () directly.
21082109 *
21092110 * Also note the behaviour of Windows with SIGINT, which says this:
21102111 * NoteSIGINT is not supported for any Win32 application, including
@@ -2125,7 +2126,7 @@ trapsig(int signum)
21252126}
21262127
21272128/*
2128- * callexit_nicely () if we got a signal, or else output "ok".
2129+ * callexit () if we got a signal, or else output "ok".
21292130 */
21302131static void
21312132check_ok (void )
@@ -2134,14 +2135,14 @@ check_ok(void)
21342135{
21352136printf (_ ("caught signal\n" ));
21362137fflush (stdout );
2137- exit_nicely ( );
2138+ exit ( 1 );
21382139}
21392140else if (output_failed )
21402141{
21412142printf (_ ("could not write to child process: %s\n" ),
21422143strerror (output_errno ));
21432144fflush (stdout );
2144- exit_nicely ( );
2145+ exit ( 1 );
21452146}
21462147else
21472148{
@@ -2775,7 +2776,7 @@ create_data_directory(void)
27752776{
27762777fprintf (stderr ,_ ("%s: could not create directory \"%s\": %s\n" ),
27772778progname ,pg_data ,strerror (errno ));
2778- exit_nicely ( );
2779+ exit ( 1 );
27792780}
27802781else
27812782check_ok ();
@@ -2793,7 +2794,7 @@ create_data_directory(void)
27932794{
27942795fprintf (stderr ,_ ("%s: could not change permissions of directory \"%s\": %s\n" ),
27952796progname ,pg_data ,strerror (errno ));
2796- exit_nicely ( );
2797+ exit ( 1 );
27972798}
27982799else
27992800check_ok ();
@@ -2822,7 +2823,7 @@ create_data_directory(void)
28222823/* Trouble accessing directory */
28232824fprintf (stderr ,_ ("%s: could not access directory \"%s\": %s\n" ),
28242825progname ,pg_data ,strerror (errno ));
2825- exit_nicely ( );
2826+ exit ( 1 );
28262827}
28272828}
28282829
@@ -2845,7 +2846,7 @@ create_xlog_or_symlink(void)
28452846if (!is_absolute_path (xlog_dir ))
28462847{
28472848fprintf (stderr ,_ ("%s: WAL directory location must be an absolute path\n" ),progname );
2848- exit_nicely ( );
2849+ exit ( 1 );
28492850}
28502851
28512852/* check if the specified xlog directory exists/is empty */
@@ -2861,7 +2862,7 @@ create_xlog_or_symlink(void)
28612862{
28622863fprintf (stderr ,_ ("%s: could not create directory \"%s\": %s\n" ),
28632864progname ,xlog_dir ,strerror (errno ));
2864- exit_nicely ( );
2865+ exit ( 1 );
28652866}
28662867else
28672868check_ok ();
@@ -2879,7 +2880,7 @@ create_xlog_or_symlink(void)
28792880{
28802881fprintf (stderr ,_ ("%s: could not change permissions of directory \"%s\": %s\n" ),
28812882progname ,xlog_dir ,strerror (errno ));
2882- exit_nicely ( );
2883+ exit ( 1 );
28832884}
28842885else
28852886check_ok ();
@@ -2901,25 +2902,25 @@ create_xlog_or_symlink(void)
29012902_ ("If you want to store the WAL there, either remove or empty the directory\n"
29022903"\"%s\".\n" ),
29032904xlog_dir );
2904- exit_nicely ( );
2905+ exit ( 1 );
29052906
29062907default :
29072908/* Trouble accessing directory */
29082909fprintf (stderr ,_ ("%s: could not access directory \"%s\": %s\n" ),
29092910progname ,xlog_dir ,strerror (errno ));
2910- exit_nicely ( );
2911+ exit ( 1 );
29112912}
29122913
29132914#ifdef HAVE_SYMLINK
29142915if (symlink (xlog_dir ,subdirloc )!= 0 )
29152916{
29162917fprintf (stderr ,_ ("%s: could not create symbolic link \"%s\": %s\n" ),
29172918progname ,subdirloc ,strerror (errno ));
2918- exit_nicely ( );
2919+ exit ( 1 );
29192920}
29202921#else
29212922fprintf (stderr ,_ ("%s: symlinks are not supported on this platform\n" ),progname );
2922- exit_nicely ( );
2923+ exit ( 1 );
29232924#endif
29242925}
29252926else
@@ -2929,7 +2930,7 @@ create_xlog_or_symlink(void)
29292930{
29302931fprintf (stderr ,_ ("%s: could not create directory \"%s\": %s\n" ),
29312932progname ,subdirloc ,strerror (errno ));
2932- exit_nicely ( );
2933+ exit ( 1 );
29332934}
29342935}
29352936
@@ -2991,7 +2992,7 @@ initialize_data_directory(void)
29912992{
29922993fprintf (stderr ,_ ("%s: could not create directory \"%s\": %s\n" ),
29932994progname ,path ,strerror (errno ));
2994- exit_nicely ( );
2995+ exit ( 1 );
29952996}
29962997
29972998free (path );
@@ -3266,6 +3267,8 @@ main(int argc, char *argv[])
32663267exit (1 );
32673268}
32683269
3270+ atexit (cleanup_directories_atexit );
3271+
32693272/* If we only need to fsync, just do it and exit */
32703273if (sync_only )
32713274{
@@ -3276,7 +3279,7 @@ main(int argc, char *argv[])
32763279{
32773280fprintf (stderr ,_ ("%s: could not access directory \"%s\": %s\n" ),
32783281progname ,pg_data ,strerror (errno ));
3279- exit_nicely ( );
3282+ exit ( 1 );
32803283}
32813284
32823285fputs (_ ("syncing data to disk ... " ),stdout );
@@ -3412,5 +3415,6 @@ main(int argc, char *argv[])
34123415
34133416destroyPQExpBuffer (start_db_cmd );
34143417
3418+ success = true;
34153419return 0 ;
34163420}