Skip to content

Commit 76a7650

Browse files
committed
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.
1 parent 9bd0fee commit 76a7650

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

contrib/pg_upgrade/dump.c

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void
1717
generate_old_dump(void)
1818
{
1919
int dbnum;
20+
mode_t old_umask;
2021

2122
prep_status("Creating dump of global objects");
2223

@@ -31,6 +32,13 @@ generate_old_dump(void)
3132

3233
prep_status("Creating dump of database schemas\n");
3334

35+
/*
36+
* Set umask for this function, all functions it calls, and all
37+
* subprocesses/threads it creates. We can't use fopen_priv()
38+
* as Windows uses threads and umask is process-global.
39+
*/
40+
old_umask = umask(S_IRWXG | S_IRWXO);
41+
3442
/* create per-db dump files */
3543
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
3644
{
@@ -54,6 +62,8 @@ generate_old_dump(void)
5462
while (reap_child(true) == true)
5563
;
5664

65+
umask(old_umask);
66+
5767
end_progress_output();
5868
check_ok();
5969
}

contrib/pg_upgrade/exec.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ exec_prog(const char *log_file, const char *opt_log_file,
4747

4848
#define MAXCMDLEN (2 * MAXPGPATH)
4949
char cmd[MAXCMDLEN];
50-
mode_t old_umask = 0;
5150
FILE *log;
5251
va_list ap;
5352

54-
old_umask = umask(S_IRWXG | S_IRWXO);
55-
5653
written = strlcpy(cmd, SYSTEMQUOTE, sizeof(cmd));
5754
va_start(ap, fmt);
5855
written += vsnprintf(cmd + written, MAXCMDLEN - written, fmt, ap);
@@ -64,7 +61,7 @@ exec_prog(const char *log_file, const char *opt_log_file,
6461
if (written >= MAXCMDLEN)
6562
pg_log(PG_FATAL, "command too long\n");
6663

67-
log = fopen_priv(log_file, "a");
64+
log = fopen(log_file, "a");
6865

6966
#ifdef WIN32
7067
{
@@ -80,7 +77,7 @@ exec_prog(const char *log_file, const char *opt_log_file,
8077
for (iter = 0; iter < 4 && log == NULL; iter++)
8178
{
8279
sleep(1);
83-
log = fopen_priv(log_file, "a");
80+
log = fopen(log_file, "a");
8481
}
8582
}
8683
#endif
@@ -101,8 +98,6 @@ exec_prog(const char *log_file, const char *opt_log_file,
10198

10299
result = system(cmd);
103100

104-
umask(old_umask);
105-
106101
if (result != 0)
107102
{
108103
/* 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,
131126
* never reused while the server is running, so it works fine. We could
132127
* log these commands to a third file, but that just adds complexity.
133128
*/
134-
if ((log = fopen_priv(log_file, "a")) == NULL)
129+
if ((log = fopen(log_file, "a")) == NULL)
135130
pg_log(PG_FATAL, "cannot write to log file %s\n", log_file);
136131
fprintf(log, "\n\n");
137132
fclose(log);

0 commit comments

Comments
 (0)