Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 04f4e10

Browse files
committed
Use symbolic names not octal constants for file permission flags.
Purely cosmetic patch to make our coding standards more consistent --- we were doing symbolic some places and octal other places. This patch fixes all C-coded uses of mkdir, chmod, and umask. There might be some other calls I missed. Inconsistency noted while researching tablespace directory permissions issue.
1 parent 244407a commit 04f4e10

File tree

10 files changed

+24
-23
lines changed

10 files changed

+24
-23
lines changed

src/backend/access/transam/xlog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,7 @@ ValidateXLOGDirectoryStructure(void)
34513451
{
34523452
ereport(LOG,
34533453
(errmsg("creating missing WAL directory \"%s\"", path)));
3454-
if (mkdir(path, 0700) < 0)
3454+
if (mkdir(path, S_IRWXU) < 0)
34553455
ereport(FATAL,
34563456
(errmsg("could not create missing directory \"%s\": %m",
34573457
path)));

src/backend/commands/copy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ DoCopyTo(CopyState cstate)
12691269
(errcode(ERRCODE_INVALID_NAME),
12701270
errmsg("relative path not allowed for COPY to file")));
12711271

1272-
oumask = umask((mode_t) 022);
1272+
oumask = umask(S_IWGRP | S_IWOTH);
12731273
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
12741274
umask(oumask);
12751275

src/backend/commands/tablespace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
552552
* Attempt to coerce target directory to safe permissions. If this fails,
553553
* it doesn't exist or has the wrong owner.
554554
*/
555-
if (chmod(location, 0700) != 0)
555+
if (chmod(location, S_IRWXU) != 0)
556556
{
557557
if (errno == ENOENT)
558558
ereport(ERROR,

src/backend/libpq/be-fsstubs.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ lo_import_internal(text *filename, Oid lobjOid)
399399
* open the file to be read in
400400
*/
401401
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
402-
fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, 0666);
402+
fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, S_IRWXU);
403403
if (fd < 0)
404404
ereport(ERROR,
405405
(errcode_for_file_access(),
@@ -474,8 +474,9 @@ lo_export(PG_FUNCTION_ARGS)
474474
* world-writable export files doesn't seem wise.
475475
*/
476476
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
477-
oumask = umask((mode_t) 0022);
478-
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666);
477+
oumask = umask(S_IWGRP | S_IWOTH);
478+
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
479+
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
479480
umask(oumask);
480481
if (fd < 0)
481482
ereport(ERROR,

src/backend/postmaster/postmaster.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ PostmasterMain(int argc, char *argv[])
494494
/*
495495
* for security, no dir or file created can be group or other accessible
496496
*/
497-
umask((mode_t) 0077);
497+
umask(S_IRWXG | S_IRWXO);
498498

499499
/*
500500
* Fire up essential subsystems: memory management
@@ -1274,7 +1274,7 @@ pmdaemonize(void)
12741274
progname, DEVNULL, strerror(errno));
12751275
ExitPostmaster(1);
12761276
}
1277-
pmlog = open(pmlogname, O_CREAT | O_WRONLY | O_APPEND, 0600);
1277+
pmlog = open(pmlogname, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR);
12781278
if (pmlog < 0)
12791279
{
12801280
write_stderr("%s: could not open log file \"%s/%s\": %s\n",

src/backend/postmaster/syslogger.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int Log_RotationSize = 10 * 1024;
7373
char *Log_directory = NULL;
7474
char *Log_filename = NULL;
7575
bool Log_truncate_on_rotation = false;
76-
int Log_file_mode = 0600;
76+
int Log_file_mode = S_IRUSR | S_IWUSR;
7777

7878
/*
7979
* Globally visible state (used by elog.c)
@@ -511,7 +511,7 @@ SysLogger_Start(void)
511511
/*
512512
* Create log directory if not present; ignore errors
513513
*/
514-
mkdir(Log_directory, 0700);
514+
mkdir(Log_directory, S_IRWXU);
515515

516516
/*
517517
* The initial logfile is created right in the postmaster, to verify that
@@ -1020,7 +1020,7 @@ logfile_open(const char *filename, const char *mode, bool allow_errors)
10201020
* Note we do not let Log_file_mode disable IWUSR, since we certainly
10211021
* want to be able to write the files ourselves.
10221022
*/
1023-
oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & 0777));
1023+
oumask = umask((mode_t) ((~(Log_file_mode | S_IWUSR)) & (S_IRWXU | S_IRWXG | S_IRWXO)));
10241024
fh = fopen(filename, mode);
10251025
umask(oumask);
10261026

src/backend/storage/file/copydir.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ copydir(char *fromdir, char *todir, bool recurse)
5656
char fromfile[MAXPGPATH];
5757
char tofile[MAXPGPATH];
5858

59-
if (mkdir(todir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
59+
if (mkdir(todir, S_IRWXU) != 0)
6060
ereport(ERROR,
6161
(errcode_for_file_access(),
6262
errmsg("could not create directory \"%s\": %m", todir)));

src/backend/storage/ipc/ipc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ proc_exit(int code)
126126
else
127127
snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());
128128

129-
mkdir("gprof", 0777);
130-
mkdir(gprofDirName, 0777);
129+
mkdir("gprof", S_IRWXU | S_IRWXG | S_IRWXO);
130+
mkdir(gprofDirName, S_IRWXU | S_IRWXG | S_IRWXO);
131131
chdir(gprofDirName);
132132
}
133133
#endif

src/bin/initdb/initdb.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ mkdatadir(const char *subdir)
870870
else
871871
strcpy(path, pg_data);
872872

873-
if (mkdir_p(path, 0700) == 0)
873+
if (mkdir_p(path, S_IRWXU) == 0)
874874
return true;
875875

876876
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
@@ -1166,7 +1166,7 @@ setup_config(void)
11661166
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
11671167

11681168
writefile(path, conflines);
1169-
chmod(path, 0600);
1169+
chmod(path, S_IRUSR | S_IWUSR);
11701170

11711171
free(conflines);
11721172

@@ -1237,7 +1237,7 @@ setup_config(void)
12371237
snprintf(path, sizeof(path), "%s/pg_hba.conf", pg_data);
12381238

12391239
writefile(path, conflines);
1240-
chmod(path, 0600);
1240+
chmod(path, S_IRUSR | S_IWUSR);
12411241

12421242
free(conflines);
12431243

@@ -1248,7 +1248,7 @@ setup_config(void)
12481248
snprintf(path, sizeof(path), "%s/pg_ident.conf", pg_data);
12491249

12501250
writefile(path, conflines);
1251-
chmod(path, 0600);
1251+
chmod(path, S_IRUSR | S_IWUSR);
12521252

12531253
free(conflines);
12541254

@@ -2904,7 +2904,7 @@ main(int argc, char *argv[])
29042904

29052905
printf("\n");
29062906

2907-
umask(077);
2907+
umask(S_IRWXG | S_IRWXO);
29082908

29092909
/*
29102910
* now we are starting to do real work, trap signals so we can clean up
@@ -2951,7 +2951,7 @@ main(int argc, char *argv[])
29512951
pg_data);
29522952
fflush(stdout);
29532953

2954-
if (chmod(pg_data, 0700) != 0)
2954+
if (chmod(pg_data, S_IRWXU) != 0)
29552955
{
29562956
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
29572957
progname, pg_data, strerror(errno));
@@ -3004,7 +3004,7 @@ main(int argc, char *argv[])
30043004
xlog_dir);
30053005
fflush(stdout);
30063006

3007-
if (mkdir_p(xlog_dir, 0700) != 0)
3007+
if (mkdir_p(xlog_dir, S_IRWXU) != 0)
30083008
{
30093009
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
30103010
progname, xlog_dir, strerror(errno));
@@ -3021,7 +3021,7 @@ main(int argc, char *argv[])
30213021
xlog_dir);
30223022
fflush(stdout);
30233023

3024-
if (chmod(xlog_dir, 0700) != 0)
3024+
if (chmod(xlog_dir, S_IRWXU) != 0)
30253025
{
30263026
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
30273027
progname, xlog_dir, strerror(errno));

src/bin/pg_ctl/pg_ctl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ main(int argc, char **argv)
17691769
*/
17701770
argv0 = argv[0];
17711771

1772-
umask(077);
1772+
umask(S_IRWXG | S_IRWXO);
17731773

17741774
/* support --help and --version even if invoked as root */
17751775
if (argc > 1)

0 commit comments

Comments
 (0)