static char *info_schema_file;
static char *features_file;
static char *system_views_file;
+static bool success = false;
static bool made_new_pgdata = false;
static bool found_existing_pgdata = false;
static bool made_new_xlogdir = false;
static char **readfile(const char *path);
static void writefile(char *path, char **lines);
static FILE *popen_check(const char *command, const char *mode);
-static void exit_nicely(void) pg_attribute_noreturn();
static char *get_id(void);
static int get_encoding_id(const char *encoding_name);
static void set_input(char **dest, const char *filename);
do { \
cmdfd = popen_check(cmd, "w"); \
if (cmdfd == NULL) \
- exit_nicely(); /* message already printed by popen_check */ \
+ exit(1); /* message already printed by popen_check */ \
} while (0)
#define PG_CMD_CLOSE \
do { \
if (pclose_check(cmdfd)) \
- exit_nicely(); /* message already printed by pclose_check */ \
+ exit(1); /* message already printed by pclose_check */ \
} while (0)
#define PG_CMD_PUTS(line) \
{
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
/* pass over the file twice - the first time to size the result */
{
fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
for (line = lines; *line != NULL; line++)
{
{
fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(*line);
}
{
fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
}
* if we created the data directory remove it too
*/
static void
-exit_nicely(void)
+cleanup_directories_atexit(void)
{
+ if (success)
+ return;
+
if (!noclean)
{
if (made_new_pgdata)
_("%s: WAL directory \"%s\" not removed at user's request\n"),
progname, xlog_dir);
}
-
- exit(1);
}
/*
{
fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
fclose(version_file))
{
fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(path);
}
{
fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
if (fclose(conf_file))
{
fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(path);
}
{
fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
/*
{
fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(conflines);
{
fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(conflines);
{
fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(conflines);
"Check your installation or specify the correct path "
"using the option -L.\n"),
progname, bki_file, PG_VERSION);
- exit_nicely();
+ exit(1);
}
/* Substitute for various symbols used in the BKI file */
if (strcmp(pwd1, pwd2) != 0)
{
fprintf(stderr, _("Passwords didn't match.\n"));
- exit_nicely();
+ exit(1);
}
}
else
{
fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
progname, pwfilename, strerror(errno));
- exit_nicely();
+ exit(1);
}
if (!fgets(pwd1, sizeof(pwd1), pwf))
{
else
fprintf(stderr, _("%s: password file \"%s\" is empty\n"),
progname, pwfilename);
- exit_nicely();
+ exit(1);
}
fclose(pwf);
* if you are handling SIGFPE.
*
* I avoided doing the forbidden things by setting a flag instead of calling
- * exit_nicely() directly.
+ * exit() directly.
*
* Also note the behaviour of Windows with SIGINT, which says this:
* Note SIGINT is not supported for any Win32 application, including
}
/*
- * call exit_nicely() if we got a signal, or else output "ok".
+ * call exit() if we got a signal, or else output "ok".
*/
static void
check_ok(void)
{
printf(_("caught signal\n"));
fflush(stdout);
- exit_nicely();
+ exit(1);
}
else if (output_failed)
{
printf(_("could not write to child process: %s\n"),
strerror(output_errno));
fflush(stdout);
- exit_nicely();
+ exit(1);
}
else
{
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
- exit_nicely();
+ exit(1);
}
else
check_ok();
{
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
- exit_nicely();
+ exit(1);
}
else
check_ok();
/* Trouble accessing directory */
fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
- exit_nicely();
+ exit(1);
}
}
if (!is_absolute_path(xlog_dir))
{
fprintf(stderr, _("%s: WAL directory location must be an absolute path\n"), progname);
- exit_nicely();
+ exit(1);
}
/* check if the specified xlog directory exists/is empty */
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, xlog_dir, strerror(errno));
- exit_nicely();
+ exit(1);
}
else
check_ok();
{
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
progname, xlog_dir, strerror(errno));
- exit_nicely();
+ exit(1);
}
else
check_ok();
_("If you want to store the WAL there, either remove or empty the directory\n"
"\"%s\".\n"),
xlog_dir);
- exit_nicely();
+ exit(1);
default:
/* Trouble accessing directory */
fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
progname, xlog_dir, strerror(errno));
- exit_nicely();
+ exit(1);
}
#ifdef HAVE_SYMLINK
{
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
progname, subdirloc, strerror(errno));
- exit_nicely();
+ exit(1);
}
#else
fprintf(stderr, _("%s: symlinks are not supported on this platform\n"), progname);
- exit_nicely();
+ exit(1);
#endif
}
else
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, subdirloc, strerror(errno));
- exit_nicely();
+ exit(1);
}
}
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, path, strerror(errno));
- exit_nicely();
+ exit(1);
}
free(path);
exit(1);
}
+ atexit(cleanup_directories_atexit);
+
/* If we only need to fsync, just do it and exit */
if (sync_only)
{
{
fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
- exit_nicely();
+ exit(1);
}
fputs(_("syncing data to disk ... "), stdout);
destroyPQExpBuffer(start_db_cmd);
+ success = true;
return 0;
}