pg_upgrade: adjust umask() calls
Since pg_upgrade -j on Windows uses threads, calling umask() before/after opening a file via fopen_priv() is no longer possible, so set umask() as we enter the thread-creating loop, and reset it on exit. Also adjust internal fopen_priv() calls to just use fopen(). Backpatch to 9.3beta.
This commit is contained in:
parent
9bd0feeba8
commit
76a7650c40
@ -17,6 +17,7 @@ void
|
|||||||
generate_old_dump(void)
|
generate_old_dump(void)
|
||||||
{
|
{
|
||||||
int dbnum;
|
int dbnum;
|
||||||
|
mode_t old_umask;
|
||||||
|
|
||||||
prep_status("Creating dump of global objects");
|
prep_status("Creating dump of global objects");
|
||||||
|
|
||||||
@ -31,6 +32,13 @@ generate_old_dump(void)
|
|||||||
|
|
||||||
prep_status("Creating dump of database schemas\n");
|
prep_status("Creating dump of database schemas\n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set umask for this function, all functions it calls, and all
|
||||||
|
* subprocesses/threads it creates. We can't use fopen_priv()
|
||||||
|
* as Windows uses threads and umask is process-global.
|
||||||
|
*/
|
||||||
|
old_umask = umask(S_IRWXG | S_IRWXO);
|
||||||
|
|
||||||
/* create per-db dump files */
|
/* create per-db dump files */
|
||||||
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
|
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
|
||||||
{
|
{
|
||||||
@ -54,6 +62,8 @@ generate_old_dump(void)
|
|||||||
while (reap_child(true) == true)
|
while (reap_child(true) == true)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
umask(old_umask);
|
||||||
|
|
||||||
end_progress_output();
|
end_progress_output();
|
||||||
check_ok();
|
check_ok();
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,9 @@ exec_prog(const char *log_file, const char *opt_log_file,
|
|||||||
|
|
||||||
#define MAXCMDLEN (2 * MAXPGPATH)
|
#define MAXCMDLEN (2 * MAXPGPATH)
|
||||||
char cmd[MAXCMDLEN];
|
char cmd[MAXCMDLEN];
|
||||||
mode_t old_umask = 0;
|
|
||||||
FILE *log;
|
FILE *log;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
old_umask = umask(S_IRWXG | S_IRWXO);
|
|
||||||
|
|
||||||
written = strlcpy(cmd, SYSTEMQUOTE, sizeof(cmd));
|
written = strlcpy(cmd, SYSTEMQUOTE, sizeof(cmd));
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
written += vsnprintf(cmd + written, MAXCMDLEN - written, fmt, ap);
|
written += vsnprintf(cmd + written, MAXCMDLEN - written, fmt, ap);
|
||||||
@ -64,7 +61,7 @@ exec_prog(const char *log_file, const char *opt_log_file,
|
|||||||
if (written >= MAXCMDLEN)
|
if (written >= MAXCMDLEN)
|
||||||
pg_log(PG_FATAL, "command too long\n");
|
pg_log(PG_FATAL, "command too long\n");
|
||||||
|
|
||||||
log = fopen_priv(log_file, "a");
|
log = fopen(log_file, "a");
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
{
|
{
|
||||||
@ -80,7 +77,7 @@ exec_prog(const char *log_file, const char *opt_log_file,
|
|||||||
for (iter = 0; iter < 4 && log == NULL; iter++)
|
for (iter = 0; iter < 4 && log == NULL; iter++)
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
log = fopen_priv(log_file, "a");
|
log = fopen(log_file, "a");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -101,8 +98,6 @@ exec_prog(const char *log_file, const char *opt_log_file,
|
|||||||
|
|
||||||
result = system(cmd);
|
result = system(cmd);
|
||||||
|
|
||||||
umask(old_umask);
|
|
||||||
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
/* we might be in on a progress status line, so go to the next line */
|
/* we might be in on a progress status line, so go to the next line */
|
||||||
@ -131,7 +126,7 @@ exec_prog(const char *log_file, const char *opt_log_file,
|
|||||||
* never reused while the server is running, so it works fine. We could
|
* never reused while the server is running, so it works fine. We could
|
||||||
* log these commands to a third file, but that just adds complexity.
|
* log these commands to a third file, but that just adds complexity.
|
||||||
*/
|
*/
|
||||||
if ((log = fopen_priv(log_file, "a")) == NULL)
|
if ((log = fopen(log_file, "a")) == NULL)
|
||||||
pg_log(PG_FATAL, "cannot write to log file %s\n", log_file);
|
pg_log(PG_FATAL, "cannot write to log file %s\n", log_file);
|
||||||
fprintf(log, "\n\n");
|
fprintf(log, "\n\n");
|
||||||
fclose(log);
|
fclose(log);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user